2 # Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
4 # (C) Copyright 2000-2006 Wolfgang Denk,
5 # DENX Software Engineering, wd@denx.de.
7 # SPDX-License-Identifier: GPL-2.0
13 EXTRAVERSION = -$(shell git rev-parse --short=8 HEAD)
14 ISREPODIRTY = $(shell if git diff-files | read dummy; then echo 1; else echo 0; fi)
15 VERSION_FILE = include/version_autogenerated.h
17 MKCONFIG = $(BUILD_TOPDIR)/u-boot/mkconfig
18 MKIMAGE = $(BUILD_TOPDIR)/u-boot/tools/mkimage
19 LZMA = $(BUILD_TOPDIR)/host_util/$(HOSTOS)-$(HOSTARCH)/lzma
21 # Show in version string if we are not building from clean repository
22 ifeq ($(ISREPODIRTY),1)
23 U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)"-dirty"
25 U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)"-clean"
28 # ===============================================================
30 TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
33 # Some variables passed as arguments in cmd
35 CONFIG_MAX_UBOOT_SIZE_KB = $(IMG_SIZE)
36 export CONFIG_MAX_UBOOT_SIZE_KB
41 export COMPRESSED_UBOOT
45 CONFIG_SKIP_LOWLEVEL_INIT = 1
46 export CONFIG_SKIP_LOWLEVEL_INIT
49 ifneq ($(DEVICE_VENDOR),)
50 DEVICE_VENDOR = $(DEVICE_VENDOR)
54 # Never use LZMA compression
55 # for a RAM version of image
56 ifdef CONFIG_SKIP_LOWLEVEL_INIT
57 unexport COMPRESSED_UBOOT
62 $(error "CROSS_COMPILE is not defined!")
67 $(error "STAGING_DIR is not defined!")
77 # =======================
78 # CUSTOM HELPER FUNCTIONS
79 # =======================
82 echo -e "\e[92m$(1)\e[0m"
86 echo -e "\e[91m$(1)\e[0m"
90 echo -e "\e[93m$(1)\e[0m"
94 u-boot_mod $(if $(filter $(IMG_RAM),1),RAM,$(if $(filter $(IMG_LZMA),1),LZMA FLASH,FLASH)) image
100 len=$$((5 - ($$(expr length $(1))/8))); \
101 tab=`printf '%*s' "$$len" | tr ' ' "\t"`; \
102 echo -ne "#define $(strip $(1))$${tab}" >> include/config.h; \
103 echo -e '$(strip $(2))' >> include/config.h
108 echo -e '#undef $(strip $(1))' >> include/config.h
113 echo -e '#include <$(strip $(1))>' >> include/config.h
118 $(if $(1),$(strip $(1)),OEM/Unknown)
123 $(if $(1),$(strip $(1)),4)
126 # $(1): vendor, board name/model
127 # $(2): default FLASH size in MB
128 # $(3): reset button GPIO number
129 # $(4): 1 if reset button is active low
132 $(call echo_green,Preparing configuration for target: $@)
135 $(call echo_yellow, Device vendor/model:\t$(call board_name,$(1)))
136 $(if $(DEVICE_VENDOR), \
137 $(call echo_yellow, Custom recovery web:\tyes ($(DEVICE_VENDOR))), \
138 $(call echo_yellow, Custom recovery web:\tno) \
141 $(if $(CONFIG_MAX_UBOOT_SIZE_KB), \
142 $(call echo_yellow, Image size limit:\t$(CONFIG_MAX_UBOOT_SIZE_KB) KB),
143 $(call echo_yellow, Image size limit:\tnot specified)
146 $(call echo_yellow, Default FLASH size:\t$(call flash_size,$(2)) MB)
149 $(call echo_yellow, GPIO reset button:\t$(strip $(3))), \
150 $(call echo_yellow, GPIO reset button:\tnot specified) \
153 $(if $(filter $(4),1),
154 $(call echo_yellow, Button active low:\tyes), \
155 $(call echo_yellow, Button active low:\tno) \
158 $(if $(filter $(COMPRESSED_UBOOT),1), \
159 $(call echo_yellow, LZMA compression:\tyes), \
160 $(call echo_yellow, LZMA compression:\tno) \
163 $(if $(filter $(CONFIG_SKIP_LOWLEVEL_INIT),1), \
164 $(call echo_yellow, RAM-loadable only:\tyes), \
165 $(call echo_yellow, RAM-loadable only:\tno) \
168 $(if $(3),$(call define_add,CONFIG_GPIO_RESET_BTN,$(strip $(3))))
169 $(if $(filter $(4),1),$(call define_add,CONFIG_GPIO_RESET_BTN_ACTIVE_LOW,1))
170 $(if $(CONFIG_MAX_UBOOT_SIZE_KB), \
171 $(call define_add,CONFIG_MAX_UBOOT_SIZE_KB,$(CONFIG_MAX_UBOOT_SIZE_KB))
174 $(if $(filter $(CONFIG_SKIP_LOWLEVEL_INIT),1), \
175 $(call define_add,CONFIG_SKIP_LOWLEVEL_INIT,1) \
177 $(if $(filter $(CONFIG_SKIP_LOWLEVEL_INIT),1), \
178 $(call undef_add,COMPRESSED_UBOOT) \
182 $(call define_add,SOC_TYPE,$(5)) \
185 $(call define_add,CONFIG_BOARD_CUSTOM_STRING,"$(call board_name,$(1))")
186 $(call define_add,CONFIG_DEFAULT_FLASH_SIZE_IN_MB,$(call flash_size,$(2)))
191 # ===============================================================
193 # First, check if configuration was done
194 ifneq (include/config.mk, $(wildcard include/config.mk))
195 all install u-boot u-boot.srec depend dep:
196 $(error "System was not configured!")
198 # Load ARCH, BOARD, and CPU configuration
199 include include/config.mk
200 export ARCH CPU BOARD VENDOR SOC
202 # Load other configuration
203 include $(TOPDIR)/config.mk
205 # ===============================================================
206 # U-Boot objects....order is important (i.e. start must be first)
207 OBJS = cpu/$(CPU)/start.o
209 LIBS = lib_generic/libgeneric.a
210 LIBS += common/libcommon.a
212 LIBS += lib_$(ARCH)/lib$(ARCH).a
213 LIBS += drivers/libdrivers.a
216 LIBS += httpd/libhttpd.a
219 LIBS_SHARED = board/$(BOARDDIR)/lib$(BOARD).a
221 LIBS_SHARED += cpu/$(CPU)/$(SOC)/lib$(SOC).a
223 LIBS_SHARED += cpu/$(CPU)/lib$(CPU).a
225 ifdef COMPRESSED_UBOOT
226 OBJS_BOOTSTRAP = cpu/$(CPU)/start_bootstrap.o
227 LIBS_BOOTSTRAP = lib_bootstrap/libbootstrap.a
228 PHONY_LIBS = $(LIBS_BOOTSTRAP) $(LIBS_SHARED)
230 PHONY_LIBS = $(LIBS) $(LIBS_SHARED)
232 .PHONY: $(PHONY_LIBS)
235 PLATFORM_LIBS += -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
237 # The "tools" are needed early, so put this first
238 # Don't include stuff already done in $(LIBS)
243 # ===============================================================
245 ALL = u-boot.srec u-boot.bin System.map
247 ifdef COMPRESSED_UBOOT
248 all: $(ALL) tuboot.bin
250 all: $(ALL) u-boot.img
254 $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@
257 $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@
260 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
262 u-boot.img: u-boot.bin
264 $(call echo_green,Preparing regular U-Boot image $@...)
265 $(MKIMAGE) -A $(ARCH) -T firmware -C none -a $(TEXT_BASE) \
266 -e 0 -n '$(call ih_name)' -d $< $@
269 $(OBJDUMP) -d $< > $@
271 u-boot: depend version $(SUBDIRS) $(OBJS) $(LIBS) $(LIBS_SHARED) $(LDSCRIPT)
272 UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) $(LIBS_SHARED) | \
273 sed -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p' | \
275 $(LD) $(LDFLAGS) $$UNDEF_SYM $(OBJS) \
276 --start-group $(LIBS) $(LIBS_SHARED) \
277 --end-group $(PLATFORM_LIBS) \
278 -Map u-boot.map -o u-boot
281 $(MAKE) -C `dirname $@`
284 $(MAKE) -C `dirname $@`
289 # For LZMA compressed image
290 ifdef COMPRESSED_UBOOT
291 tuboot.bin: System.map bootstrap.bin u-boot.lzimg
292 @cat bootstrap.bin > $@
293 @cat u-boot.lzimg >> $@
295 u-boot.lzimg: $(obj)u-boot.bin System.map
297 @rm -rf u-boot.bin.lzma
298 @$(call echo_green,Compressing U-Boot image $<...)
299 @$(LZMA) --best --keep $(obj)u-boot.bin
300 $(call echo_green,Preparing LZMA compressed U-Boot image $@...)
301 $(MKIMAGE) -A $(ARCH) -T firmware -C lzma \
302 -a 0x$(shell grep "T _start" $(TOPDIR)/System.map | \
303 awk '{ printf "%s", $$1 }') \
304 -e 0x$(shell grep "T _start" $(TOPDIR)/System.map | \
305 awk '{ printf "%s", $$1 }') \
306 -n '$(call ih_name)' -d $(obj)u-boot.bin.lzma $@
308 bootstrap.bin: bootstrap
309 $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
311 bootstrap: depend version $(SUBDIRS) $(OBJS_BOOTSTRAP) $(LIBS_BOOTSTRAP) $(LIBS_SHARED) $(LDSCRIPT_BOOTSTRAP)
312 UNDEF_SYM=`$(OBJDUMP) -x $(LIBS_BOOTSTRAP) | \
313 sed -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p' | \
315 $(LD) $(LDFLAGS_BOOTSTRAP) $$UNDEF_SYM $(OBJS_BOOTSTRAP) \
316 --start-group $(LIBS_BOOTSTRAP) $(LIBS_SHARED) \
317 --end-group $(PLATFORM_LIBS) \
318 -Map bootstrap.map -o bootstrap
321 $(MAKE) -C `dirname $@`
322 endif # ifdef COMPRESSED_UBOOT
325 @echo -n "#define U_BOOT_VERSION \"U-Boot $(U_BOOT_VERSION)\"" > $(VERSION_FILE)
328 @for dir in $(SUBDIRS); do $(MAKE) -C $$dir .depend; done
332 grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
334 endif # include/config.mk
336 # =====================
337 # COMMON/SHARED TARGETS
338 # =====================
341 @$(call echo_green,Removing configuration...)
342 @rm -f include/config.h include/config.mk board/*/config.tmp
346 @$(call include_add,soc/soc_list.h)
347 @$(call define_add,CONFIG_MAX_BUTTON_PRESSING,10)
348 @$(call define_add,CONFIG_DELAY_TO_AUTORUN_HTTPD,3)
349 @$(call define_add,CONFIG_DELAY_TO_AUTORUN_CONSOLE,5)
350 @$(call define_add,CONFIG_DELAY_TO_AUTORUN_NETCONSOLE,7)
352 ar933x_common: unconfig config_common
353 @$(call define_add,CFG_AG7240_NMACS,2)
354 @$(call define_add,CFG_ATHRS26_PHY,1)
355 @$(call define_add,CONFIG_MACH_HORNET,1)
357 ar934x_common: unconfig config_common
358 @$(call define_add,CONFIG_WASP,1)
359 @$(call define_add,CONFIG_WASP_SUPPORT,1)
361 qca953x_common: unconfig config_common
362 @$(call define_add,CONFIG_ATHEROS,1)
363 @$(call define_add,CONFIG_MACH_QCA953x,1)
365 # =============================
366 # TARGETS IN ALPHABETICAL ORDER
367 # =============================
369 8devices_carambola2: ar933x_common
370 @$(call config_init,8devices Carambola 2,16,11,1,QCA_AR933X_SOC)
371 @$(call define_add,CONFIG_FOR_8DEVICES_CARAMBOLA2,1)
372 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
374 d-link_dir-505: ar933x_common
375 @$(call config_init,D-Link DIR-505,8,11,1,QCA_AR933X_SOC)
376 @$(call define_add,CONFIG_FOR_DLINK_DIR505_A1,1)
377 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
379 dragino_v2_ms14: ar933x_common
380 @$(call config_init,Dragino v2 (MS14),16,11,1,QCA_AR933X_SOC)
381 @$(call define_add,CONFIG_FOR_DRAGINO_V2,1)
382 @$(call define_add,WEBFAILSAFE_DISABLE_ART_UPGRADE,1)
383 @$(call define_add,WEBFAILSAFE_DISABLE_UBOOT_UPGRADE,1)
384 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
386 gainstrong_oolite_v1_dev: ar933x_common
387 @$(call config_init,Gainstrong Oolite v1 (dev board),16,11,,QCA_AR933X_SOC)
388 @$(call define_add,CONFIG_FOR_GS_OOLITE_V1_DEV,1)
389 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
391 gl-innovations_gl-inet-6416: ar933x_common
392 @$(call config_init,GL-Innovations GL.iNet 6416,8,11,,QCA_AR933X_SOC)
393 @$(call define_add,CONFIG_FOR_GL_INET,1)
394 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
396 tp-link_tl-mr10u: ar933x_common
397 @$(call config_init,TP-Link TL-MR10U,4,11,,QCA_AR933X_SOC)
398 @$(call define_add,CONFIG_FOR_TPLINK_MR10U_V1,1)
399 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
401 tp-link_tl-mr13u: ar933x_common
402 @$(call config_init,TP-Link TL-MR13U,4,11,,QCA_AR933X_SOC)
403 @$(call define_add,CONFIG_FOR_TPLINK_MR13U_V1,1)
404 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
406 tp-link_tl-mr3020: ar933x_common
407 @$(call config_init,TP-Link TL-MR3020,4,11,,QCA_AR933X_SOC)
408 @$(call define_add,CONFIG_FOR_TPLINK_MR3020_V1,1)
409 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
411 tp-link_tl-mr3040: ar933x_common
412 @$(call config_init,TP-Link TL-MR3040,4,11,,QCA_AR933X_SOC)
413 @$(call define_add,CONFIG_FOR_TPLINK_MR3040_V1V2,1)
414 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
416 tp-link_tl-mr3220_v2: ar933x_common
417 @$(call config_init,TP-Link TL-MR3220 v2,4,11,,QCA_AR933X_SOC)
418 @$(call define_add,CONFIG_FOR_TPLINK_MR3220_V2,1)
419 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
421 tp-link_tl-mr3420_v2: ar934x_common
422 @$(call config_init,TP-Link TL-MR3420 v2,4,17,1,QCA_AR9341_SOC)
423 @$(call define_add,CONFIG_FOR_TPLINK_MR3420_V2,1)
424 @$(call define_add,CFG_ATHRS27_PHY,1)
425 @$(call define_add,CFG_AG7240_NMACS,2)
426 @$(MKCONFIG) -a db12x mips mips db12x ar7240 ar7240
428 tp-link_tl-wa830re_v2_tl-wa801nd_v2: ar934x_common
429 @$(call config_init,TP-Link TL-WA830RE/TL-WA801ND v2,4,17,1,QCA_AR9341_SOC)
430 @$(call define_add,CONFIG_FOR_TPLINK_WA830RE_V2_WA801ND_V2,1)
431 @$(call define_add,CFG_ATHRS27_PHY,1)
432 @$(call define_add,CFG_AG7240_NMACS,2)
433 @$(MKCONFIG) -a db12x mips mips db12x ar7240 ar7240
435 tp-link_tl-wdr3500: ar934x_common
436 @$(call config_init,TP-Link TL-WDR3500,8,16,1,QCA_AR9344_SOC)
437 @$(call define_add,CONFIG_FOR_TPLINK_WDR3500_V1,1)
438 @$(call define_add,CFG_ATHRS27_PHY,1)
439 @$(call define_add,CFG_AG7240_NMACS,2)
440 @$(call define_add,CONFIG_PCI,1)
441 @$(MKCONFIG) -a db12x mips mips db12x ar7240 ar7240
443 tp-link_tl-wdr3600_tl-43x0: ar934x_common
444 @$(call config_init,TP-Link TL-WDR3600/43x0,8,16,1,QCA_AR9344_SOC)
445 @$(call define_add,CONFIG_FOR_TPLINK_WDR3600_WDR43X0_V1,1)
446 @$(call define_add,CFG_ATHRS17_PHY,1)
447 @$(call define_add,CFG_AG7240_NMACS,1)
448 @$(call define_add,CONFIG_PCI,1)
449 @$(call define_add,CFG_DUAL_PHY_SUPPORT,1)
450 @$(MKCONFIG) -a db12x mips mips db12x ar7240 ar7240
452 tp-link_tl-wr703n: ar933x_common
453 @$(call config_init,TP-Link TL-WR703N,4,11,,QCA_AR933X_SOC)
454 @$(call define_add,CONFIG_FOR_TPLINK_WR703N_V1,1)
455 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
457 tp-link_tl-wr710n: ar933x_common
458 @$(call config_init,TP-Link TL-WR710N,8,11,,QCA_AR933X_SOC)
459 @$(call define_add,CONFIG_FOR_TPLINK_WR710N_V1,1)
460 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
462 tp-link_tl-wr720n_v3_CN: ar933x_common
463 @$(call config_init,TP-Link TL-WR720N v3 CN,4,11,,QCA_AR933X_SOC)
464 @$(call define_add,CONFIG_FOR_TPLINK_WR720N_V3,1)
465 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
467 tp-link_tl-wr740n_v4: ar933x_common
468 @$(call config_init,TP-Link TL-WR74xN/D v4,4,11,,QCA_AR933X_SOC)
469 @$(call define_add,CONFIG_FOR_TPLINK_WR740N_V4,1)
470 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
472 tp-link_tl-wr802n: qca953x_common
473 @$(call config_init,TP-Link TL-WR802N,4,12,1,QCA_QCA953X_SOC)
474 @$(call define_add,CONFIG_FOR_TPLINK_WR802N,1)
475 @$(call define_add,CFG_ATHRS27_PHY,1)
476 @$(call define_add,CFG_ATH_GMAC_NMACS,2)
477 @$(MKCONFIG) -a ap143 mips mips ap143 ar7240 ar7240
479 tp-link_tl-wr820n_CN: qca953x_common
480 @$(call config_init,TP-Link TL-WR820N CN,4,12,1,QCA_QCA953X_SOC)
481 @$(call define_add,CONFIG_FOR_TPLINK_WR820N_CN,1)
482 @$(call define_add,CFG_ATHRS27_PHY,1)
483 @$(call define_add,CFG_ATH_GMAC_NMACS,2)
484 @$(MKCONFIG) -a ap143 mips mips ap143 ar7240 ar7240
486 tp-link_tl-wr841n_v8: ar934x_common
487 @$(call config_init,TP-Link TL-WR841N/D v8,4,17,1,QCA_AR9341_SOC)
488 @$(call define_add,CONFIG_FOR_TPLINK_WR841N_V8,1)
489 @$(call define_add,CFG_ATHRS27_PHY,1)
490 @$(call define_add,CFG_AG7240_NMACS,2)
491 @$(MKCONFIG) -a db12x mips mips db12x ar7240 ar7240
493 tp-link_tl-wr841n_v9: qca953x_common
494 @$(call config_init,TP-Link TL-WR841N/D v9,4,12,1,QCA_QCA953X_SOC)
495 @$(call define_add,CONFIG_FOR_TPLINK_WR841N_V9,1)
496 @$(call define_add,CFG_ATHRS27_PHY,1)
497 @$(call define_add,CFG_ATH_GMAC_NMACS,2)
498 @$(MKCONFIG) -a ap143 mips mips ap143 ar7240 ar7240
500 unwireddevices_unwired-one: ar933x_common
501 @$(call config_init,Black Swift aka Unwired One,16,11,1,QCA_AR933X_SOC)
502 @$(call define_add,CONFIG_FOR_BLACK_SWIFT_BOARD,1)
503 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
505 village-telco_mesh-potato_v2: ar933x_common
506 @$(call config_init,Village Telco Mesh Potato 2,16,11,1,QCA_AR933X_SOC)
507 @$(call define_add,CONFIG_FOR_MESH_POTATO_V2,1)
508 @$(call define_add,WEBFAILSAFE_DISABLE_ART_UPGRADE,1)
509 @$(call define_add,WEBFAILSAFE_DISABLE_UBOOT_UPGRADE,1)
510 @$(MKCONFIG) -a ap121 mips mips ap121 ar7240 ar7240
512 wallys_dr531: qca953x_common
513 @$(call config_init,Wallys DR531,8,17,1,QCA_QCA953X_SOC)
514 @$(call define_add,CONFIG_FOR_WALLYS_DR531,1)
515 @$(call define_add,CFG_ATHRS27_PHY,1)
516 @$(call define_add,CFG_ATH_GMAC_NMACS,2)
517 @$(call define_add,CONFIG_PCI,1)
518 @$(MKCONFIG) -a ap143 mips mips ap143 ar7240 ar7240
520 zbtlink_zbt-we1526: qca953x_common
521 @$(call config_init,Zbtlink ZBT-WE1526,16,17,1,QCA_QCA953X_SOC)
522 @$(call define_add,CONFIG_FOR_ZBTLINK_ZBT_WE1526,1)
523 @$(call define_add,CFG_ATHRS27_PHY,1)
524 @$(call define_add,CFG_ATH_GMAC_NMACS,2)
525 @$(MKCONFIG) -a ap143 mips mips ap143 ar7240 ar7240
532 @$(call echo_green,Making $@...)
534 \( -name 'core' -o -name '*.bak' -o -name '*~' \
535 -o -name '*.o' -o -name '*.a' -o -name .depend \) -print \
537 @rm -f tools/mkimage tools/envcrc
538 @rm -f lib_bootstrap/*.o
539 @rm -f lib_bootstrap/*.a
540 @rm -f bootstrap bootstrap.bin tuboot.bin u-boot.lzimg u-boot.bin.lzma bootstrap.map
543 @$(call echo_green,Making $@...)
544 @find . -type f \( -name .depend \
545 -o -name '*.srec' -o -name '*.bin' -o -name u-boot.img \) \
548 @rm -f $(OBJS) *.bak include/version_autogenerated.h
550 @rm -f u-boot u-boot.map u-boot.hex $(ALL)
551 @rm -f tools/crc32.c tools/environment.c
552 @rm -f include/asm/proc include/asm/arch include/asm
554 distclean: clobber unconfig