forked from linux4sam/at91bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
443 lines (356 loc) · 11.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#
# Default config file is in $(TOPDIR)/board/$(BOARD_NAME)/*_defconfig
# First, run xxx_defconfig
# Then, `make menuconfig' if needed
#
# Do not:
# o use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour);
# o print "Entering directory ...";
MAKEFLAGS += -rR --no-print-directory
TOPDIR=$(shell pwd)
CONFIG_CONFIG_IN=Config.in
CONFIG_DEFCONFIG=.defconfig
CONFIG=config
CONFIG_SHELL=$(shell which bash)
ifeq ($(CONFIG_SHELL),)
$(error GNU Bash is needed to build Bootstrap!)
endif
BINDIR:=$(TOPDIR)/binaries
DATE := $(shell date)
VERSION := 3.8.8
REVISION :=
SCMINFO := $(shell ($(TOPDIR)/host-utilities/setlocalversion $(TOPDIR)))
ifeq ($(SCMINFO),)
-include $(TOPDIR)/scminfo.mk
SCMINFO=$(RECORD_SCMINFO)
endif
TARBALL_NAME=AT91Bootstrap-$(VERSION)$(REV)$(SCMINFO).tar.gz
TARBALL_DIR=../tarball_dir
TARBALL_PREFIX=at91bootstrap-$(VERSION)$(REV)/
# Use 'make V=1' for the verbose mode
ifneq ("$(origin V)", "command line")
Q=@
export Q
endif
noconfig_targets:= menuconfig defconfig $(CONFIG) oldconfig savedefconfig
# Check first if we want to configure at91bootstrap
#
ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
-include .config
endif
include host-utilities/host.mk
ifeq ($(HAVE_DOT_CONFIG),)
all: menuconfig
# configuration
# ---------------------------------------------------------------------------
HOSTCFLAGS=$(CFLAGS_FOR_BUILD)
export HOSTCFLAGS
$(CONFIG)/conf:
@mkdir -p $(CONFIG)/at91bootstrap-config
@$(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf
-@if [ ! -f .config ]; then \
cp $(CONFIG_DEFCONFIG) .config; \
fi
$(CONFIG)/mconf:
@mkdir -p $(CONFIG)/at91bootstrap-config
@$(MAKE) CC="$(HOSTCC)" -C $(CONFIG) conf mconf
-@if [ ! -f .config ]; then \
cp $(CONFIG_DEFCONFIG) .config; \
fi
menuconfig: $(CONFIG)/mconf
@mkdir -p $(CONFIG)/at91bootstrap-config
@if ! KCONFIG_AUTOCONFIG=$(CONFIG)/at91bootstrap-config/auto.conf \
KCONFIG_AUTOHEADER=$(CONFIG)/at91bootstrap-config/autoconf.h \
$(CONFIG)/mconf $(CONFIG_CONFIG_IN); then \
test -f .config.cmd || rm -f .config; \
fi
$(CONFIG): $(CONFIG)/conf
@mkdir -p $(CONFIG)/at91bootstrap-config
@KCONFIG_AUTOCONFIG=$(CONFIG)/at91bootstrap-config/auto.conf \
KCONFIG_AUTOHEADER=$(CONFIG)/at91bootstrap-config/autoconf.h \
$(CONFIG)/conf $(CONFIG_CONFIG_IN)
oldconfig: $(CONFIG)/conf
@mkdir -p $(CONFIG)/at91bootstrap-config
@KCONFIG_AUTOCONFIG=$(CONFIG)/at91bootstrap-config/auto.conf \
KCONFIG_AUTOHEADER=$(CONFIG)/at91bootstrap-config/autoconf.h \
$(CONFIG)/conf --oldconfig $(CONFIG_CONFIG_IN)
defconfig: $(CONFIG)/conf
@mkdir -p $(CONFIG)/at91bootstrap-config
@KCONFIG_AUTOCONFIG=$(CONFIG)/at91bootstrap-config/auto.conf \
KCONFIG_AUTOHEADER=$(CONFIG)/at91bootstrap-config/autoconf.h \
$(CONFIG)/conf --defconfig=.config $(CONFIG_CONFIG_IN)
savedefconfig: $(CONFIG)/conf
@mkdir -p $(CONFIG)/at91bootstrap-config
@KCONFIG_AUTOCONFIG=$(CONFIG)/at91bootstrap-config/auto.conf \
KCONFIG_AUTOHEADER=$(CONFIG)/at91bootstrap-config/autoconf.h \
$(CONFIG)/conf --savedefconfig=defconfig $(CONFIG_CONFIG_IN)
else # Have DOT Config
HOSTARCH := $(shell uname -m | sed -e s/arm.*/arm/)
AS=$(CROSS_COMPILE)gcc
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
NM= $(CROSS_COMPILE)nm
SIZE=$(CROSS_COMPILE)size
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump
PROJECT := $(strip $(subst ",,$(CONFIG_PROJECT)))
IMG_ADDRESS := $(strip $(subst ",,$(CONFIG_IMG_ADDRESS)))
IMG_SIZE := $(strip $(subst ",,$(CONFIG_IMG_SIZE)))
JUMP_ADDR := $(strip $(subst ",,$(CONFIG_JUMP_ADDR)))
OF_OFFSET := $(strip $(subst ",,$(CONFIG_OF_OFFSET)))
OF_ADDRESS := $(strip $(subst ",,$(CONFIG_OF_ADDRESS)))
BOOTSTRAP_MAXSIZE := $(strip $(subst ",,$(CONFIG_BOOTSTRAP_MAXSIZE)))
MEMORY := $(strip $(subst ",,$(CONFIG_MEMORY)))
IMAGE_NAME:= $(strip $(subst ",,$(CONFIG_IMAGE_NAME)))
CARD_SUFFIX := $(strip $(subst ",,$(CONFIG_CARD_SUFFIX)))
MEM_BANK := $(strip $(subst ",,$(CONFIG_MEM_BANK)))
MEM_SIZE := $(strip $(subst ",,$(CONFIG_MEM_SIZE)))
LINUX_KERNEL_ARG_STRING := $(strip $(subst ",,$(CONFIG_LINUX_KERNEL_ARG_STRING)))
# Board definitions
BOARDNAME:=$(strip $(subst ",,$(CONFIG_BOARDNAME)))
MACH_TYPE:=$(strip $(subst ",,$(CONFIG_MACH_TYPE)))
LINK_ADDR:=$(strip $(subst ",,$(CONFIG_LINK_ADDR)))
DATA_SECTION_ADDR:=$(strip $(subst ",,$(CONFIG_DATA_SECTION_ADDR)))
TOP_OF_MEMORY:=$(strip $(subst ",,$(CONFIG_TOP_OF_MEMORY)))
# CRYSTAL is UNUSED
CRYSTAL:=$(strip $(subst ",,$(CONFIG_CRYSTAL)))
# driver definitions
SPI_CLK:=$(strip $(subst ",,$(CONFIG_SPI_CLK)))
SPI_BOOT:=$(strip $(subst ",,$(CONFIG_SPI_BOOT)))
ifeq ($(REVISION),)
REV:=
else
REV:=-$(strip $(subst ",,$(REVISION)))
endif
ifeq ($(CONFIG_OF_LIBFDT), y)
BLOB:=-dt
else
BLOB:=
endif
ifeq ($(CONFIG_LOAD_LINUX), y)
TARGET_NAME:=linux-$(subst I,i,$(IMAGE_NAME))
endif
ifeq ($(CONFIG_LOAD_ANDROID), y)
TARGET_NAME:=android-$(subst I,i,$(IMAGE_NAME))
endif
ifeq ($(CONFIG_LOAD_UBOOT), y)
TARGET_NAME:=$(subst -,,$(basename $(IMAGE_NAME)))
endif
ifeq ($(CONFIG_LOAD_64KB), y)
TARGET_NAME:=$(basename $(IMAGE_NAME))
endif
ifeq ($(CONFIG_LOAD_1MB), y)
TARGET_NAME:=$(basename $(IMAGE_NAME))
endif
ifeq ($(CONFIG_LOAD_4MB), y)
TARGET_NAME:=$(basename $(IMAGE_NAME))
endif
BOOT_NAME=$(BOARDNAME)-$(PROJECT)$(CARD_SUFFIX)boot-$(TARGET_NAME)$(BLOB)-$(VERSION)$(REV)
AT91BOOTSTRAP:=$(BINDIR)/$(BOOT_NAME).bin
ifeq ($(IMAGE),)
IMAGE=$(BOOT_NAME).bin
endif
ifeq ($(SYMLINK),)
SYMLINK=at91bootstrap.bin
endif
ifeq ($(SYMLINK_BOOT),)
SYMLINK_BOOT=boot.bin
endif
COBJS-y:= $(TOPDIR)/main.o
SOBJS-y:= $(TOPDIR)/crt0_gnu.o
BOARD_LOCATE=$(shell find $(TOPDIR)/board/ -name $(BOARDNAME) -type d)
ifeq ("$(realpath $(BOARD_LOCATE))", "")
BOARD_LOCATE=$(shell find $(TOPDIR)/contrib/board/ -name $(BOARDNAME) -type d)
ifeq ("$(realpath $(BOARD_LOCATE))", "")
$(error ERROR: *** file: $(BOARD_LOCATE) does not found!)
endif
endif
COBJS-y += $(BOARD_LOCATE)/$(BOARDNAME).o
INCL = $(BOARD_LOCATE)
include lib/lib.mk
include driver/driver.mk
include contrib/driver/driver.mk
include fs/src/fat.mk
GC_SECTIONS=--gc-sections
NOSTDINC_FLAGS=-nostdinc -isystem $(shell $(CC) -print-file-name=include)
CPPFLAGS=$(NOSTDINC_FLAGS) -ffunction-sections -g -Os -Wall \
-mno-unaligned-access \
-fno-stack-protector -fno-common \
-I$(INCL) -Icontrib/include -Iinclude -Ifs/include \
-I$(TOPDIR)/config/at91bootstrap-config \
-DAT91BOOTSTRAP_VERSION=\"$(VERSION)$(REV)$(SCMINFO)\" -DCOMPILE_TIME="\"$(DATE)\""
ASFLAGS=-g -Os -Wall -I$(INCL) -Iinclude -Icontrib/include
include toplevel_cpp.mk
include board/board_cpp.mk
ifneq ("$(wildcard $(BOARD_LOCATE)/board.mk)", "")
include $(BOARD_LOCATE)/board.mk
else
$(warning WARNING: *** file: $(BOARD_LOCATE)/board.mk are not found!)
endif
include driver/driver_cpp.mk
OBJS:= $(SOBJS-y) $(COBJS-y)
ifeq ($(CONFIG_ENTER_NWD), y)
link_script:=elf32-littlearm-tz.lds
else
link_script:=elf32-littlearm.lds
endif
# Linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
# -lc : tells the linker to tie in newlib
# -lgcc : tells the linker to tie in newlib
LDFLAGS=-nostartfiles -Map=$(BINDIR)/$(BOOT_NAME).map --cref -static
LDFLAGS+=-T $(link_script) $(GC_SECTIONS) -Ttext $(LINK_ADDR)
ifneq ($(DATA_SECTION_ADDR),)
LDFLAGS+=-Tdata $(DATA_SECTION_ADDR)
endif
gccversion := $(shell expr `$(CC) -dumpversion`)
ifdef YYY # For other utils
ifeq ($(CC),gcc)
TARGETS=no-cross-compiler
else
TARGETS=$(AT91BOOTSTRAP) host-utilities .config filesize
endif
endif
TARGETS=$(AT91BOOTSTRAP)
PHONY:=all
all: CheckCrossCompile PrintFlags $(AT91BOOTSTRAP) ChkFileSize ${AT91BOOTSTRAP}.pmecc
CheckCrossCompile:
@( if [ "$(HOSTARCH)" != "arm" ]; then \
if [ "x$(CROSS_COMPILE)" = "x" ]; then \
echo "error: Environment variable "CROSS_COMPILE" must be defined!"; \
exit 2; \
fi \
fi )
PrintFlags:
@echo CC
@echo ========
@echo $(CC) $(gccversion)&& echo
@echo as FLAGS
@echo ========
@echo $(ASFLAGS) && echo
@echo gcc FLAGS
@echo =========
@echo $(CPPFLAGS) && echo
@echo ld FLAGS
@echo ========
@echo $(LDFLAGS) && echo
$(AT91BOOTSTRAP): $(OBJS)
$(if $(wildcard $(BINDIR)),,mkdir -p $(BINDIR))
@echo " LD "$(BOOT_NAME).elf
$(Q)$(LD) $(LDFLAGS) -n -o $(BINDIR)/$(BOOT_NAME).elf $(OBJS)
# @$(OBJCOPY) --strip-debug --strip-unneeded $(BINDIR)/$(BOOT_NAME).elf -O binary $(BINDIR)/$(BOOT_NAME).bin
@$(OBJCOPY) --strip-all $(BINDIR)/$(BOOT_NAME).elf -O binary $@
@ln -sf $(BOOT_NAME).bin ${BINDIR}/${SYMLINK}
@ln -sf $(BOOT_NAME).bin ${BINDIR}/${SYMLINK_BOOT}
%.o : %.c .config
@echo " CC "$<
@$(CC) $(CPPFLAGS) -c -o $@ $<
%.o : %.S .config
@echo " AS "$<
@$(AS) $(ASFLAGS) -c -o $@ $<
$(AT91BOOTSTRAP).pmecc: $(AT91BOOTSTRAP)
ifeq ($(CONFIG_NANDFLASH), y)
ifeq ($(CONFIG_USE_PMECC), y)
$(Q)./scripts/addpmecchead.py $(AT91BOOTSTRAP) $(AT91BOOTSTRAP).pmecc $(BOARDNAME)
endif
endif
PHONY+= bootstrap
rebuild: clean all
ChkFileSize: $(AT91BOOTSTRAP)
@( fsize=`./scripts/get_sram_size.sh $(BINDIR)/$(BOOT_NAME).map`; \
if [ $$? -ne 0 ] ; then \
rm $(BINDIR)/$(BOOT_NAME).bin ;\
rm ${BINDIR}/${SYMLINK}; \
rm ${BINDIR}/${SYMLINK_BOOT}; \
exit 3; \
fi ; \
echo "Size of $(BOOT_NAME).bin is $$fsize bytes"; \
if [ "$$fsize" -gt "$(BOOTSTRAP_MAXSIZE)" ] ; then \
echo "[Failed***] It's too big to fit into SRAM area. the support maxium size is $(BOOTSTRAP_MAXSIZE)"; \
rm $(BINDIR)/$(BOOT_NAME).bin ;\
rm ${BINDIR}/${SYMLINK}; \
rm ${BINDIR}/${SYMLINK_BOOT}; \
exit 2;\
else \
echo "[Succeeded] It's OK to fit into SRAM area"; \
stack_space=`expr $(BOOTSTRAP_MAXSIZE) - $$fsize`; \
echo "[Attention] The space left for stack is $$stack_space bytes"; \
fi )
endif # HAVE_DOT_CONFIG
PHONY+= rebuild
%_defconfig:
@(conf_file=`find ./ -name $@`; \
if [ "$$conf_file"x != "x" ]; then \
cp $$conf_file .config; \
else \
echo "Error: *** Cannot find file: $@"; \
exit 2; \
fi )
@$(MAKE) defconfig
update:
cp .config $(BOARD_LOCATE)/$(BOARDNAME)_defconfig
no-cross-compiler:
@echo
@echo
@echo
@echo " You should consider using a cross compiler for ARM !"
@echo " I.E: CROSS_COMPILE should contains something useful."
@echo
debug:
@echo CONFIG=$(CONFIG)
@echo AS=$(AS)
@echo CROSS_COMPILE=$(CROSS_COMPILE)
PHONY+=update no-cross-compiler debug
distrib: mrproper
$(Q)find . -type f \( -name .depend \
-o -name '*.srec' \
-o -name '*.elf' \
-o -name '*.map' \
-o -name '*.o' \
-o -name '*~' \) \
-print0 \
| xargs -0 rm -f
$(Q)rm -fr result
$(Q)rm -fr build
$(Q)rm -fr ..make.deps.tmp
$(Q)rm -fr config/conf
config-clean:
@echo " CLEAN "configuration files!
$(Q)make -C config distclean
$(Q)rm -fr config/at91bootstrap-config
$(Q)rm -f config/.depend
clean:
@echo " CLEAN "obj and misc files!
$(Q)find . -type f \( -name .depend \
-o -name '*.srec' \
-o -name '*.o' \
-o -name '*~' \) \
-print0 \
| xargs -0 rm -f
distclean: clean config-clean
# rm -fr $(BINDIR)
$(Q)rm -fr .config .config.cmd .config.old
$(Q)rm -fr .auto.deps
$(Q)rm -f .installed
$(Q)rm -f ..*.tmp
$(Q)rm -f .configured
mrproper: distclean
@echo " CLEAN "binary files!
$(Q)rm -fr $(BINDIR)
$(Q)rm -fr log
PHONY+=distrib config-clean clean distclean mrproper
tarball:
@echo "Tar the source code to ${TARBALL_NAME}"
$(Q)mkdir -p ${TARBALL_DIR}
$(Q)git archive --prefix=${TARBALL_PREFIX} HEAD | gzip > ${TARBALL_DIR}/${TARBALL_NAME}
$(Q)echo "RECORD_SCMINFO=${SCMINFO}" > ${TARBALL_DIR}/scminfo.mk
$(Q)cd ${TARBALL_DIR}; tar -xzf ${TARBALL_NAME}
$(Q)cd ${TARBALL_DIR}; cp scminfo.mk ${TARBALL_PREFIX}
$(Q)cd ${TARBALL_DIR}; tar czf ${TARBALL_NAME} ${TARBALL_PREFIX}
$(Q)cp ${TARBALL_DIR}/${TARBALL_NAME} .
$(Q)rm -rf ${TARBALL_DIR}
PHONY+=tarball
.PHONY: $(PHONY)