2 # Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
4 # SPDX-License-Identifier: GPL-2.0
9 HOSTARCH := $(shell uname -m | \
10 sed -e s/i.86/x86_32/ \
17 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
18 sed -e 's/\(cygwin\).*/cygwin/')
20 ifneq ($(HOSTOS), darwin)
21 ifneq ($(HOSTOS), linux)
22 $(error Error! Unsupported host operating system/arch: "$(HOSTOS)-$(HOSTARCH)")
28 export BUILD_TOPDIR = $(PWD)
29 export STAGING_DIR = $(BUILD_TOPDIR)/tmp
30 export SOURCE_DIR = $(BUILD_TOPDIR)/u-boot
31 export BIN_DIR = $(BUILD_TOPDIR)/bin
32 export SUB_MAKE_CMD = $(MAKE) --silent --no-print-directory \
33 ARCH=mips V=1 SHELL=$(SHELL)
35 # ==========================================================================
36 # You can override some default configuration options below or pass them on
37 # command line, for example:
38 # make ... IMG_SIZE=256 IMG_LZMA=0 CROSS_COMPILE=...
40 # Set to 1 if you want to build RAM-loadable image, without low level
41 # initialization of the hardware (PLL/clocks, DRAM):
44 # You can change limit of the image size in KB with below option (image will
45 # be filled up to the selected size with 0xFF):
48 # If you don't want LZMA compressed image, set below option to 1 (by default
49 # images for all targets are LZMA compressed):
52 # Define _absolute_ path to your toolchain directory, for example:
53 # export TOOLCHAIN_DIR:=/home/user/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.15
54 # export PATH:=$(TOOLCHAIN_DIR)/bin:$(PATH)
57 CROSS_COMPILE = mips-openwrt-linux-musl-
61 # ==========================================================================
63 # =======================
64 # CUSTOM HELPER FUNCTIONS
65 # =======================
68 echo -e "\e[92m$(1)\e[0m"
72 echo -e "\e[91m$(1)\e[0m"
76 echo -e "\e[96m$(1)\e[0m"
81 $(if $(IMG_SIZE),$(strip $(IMG_SIZE)),$(strip $(1)))
86 $(if $(filter $(strip $(1)),1),1,0)
89 # $(1): file extension
91 u-boot_mod__$(shell date +"%Y%m%d")__$@$(if \
92 $(filter $(IMG_RAM),1),__RAM-LOAD-ONLY)$(if $(1),.$(1))
96 $(call echo_green,Calculating MD5 sum for the final image...)
98 md5sum $(BIN_DIR)/$(call img_name,bin) | \
100 tr -d '\n' > $(BIN_DIR)/$(call img_name).md5
102 echo ' *'$(call img_name,bin) >> $(BIN_DIR)/$(call img_name,md5)
107 $(call echo_green,Preparing $(1) KB image padded with 0xFF...)
108 tr "\000" "\377" < /dev/zero | dd ibs=1k count=$(1) \
109 of=$(BIN_DIR)/$(call img_name,bin) 2> /dev/null
113 $(call echo_green,Preparing final image...)
114 dd if=$(BIN_DIR)/temp.bin of=$(BIN_DIR)/$(call img_name,bin) \
115 conv=notrunc 2> /dev/null
117 rm -f $(BIN_DIR)/temp.bin
120 # $(1): path to image
121 # $(2): size limit in KB
123 $(call echo_green,Checking size of the image...)
125 if [ `wc -c < $(1)` -gt `echo $(2)*1024 | bc` ]; then \
127 $(call echo_red, ======================); \
128 $(call echo_red, IMAGE SIZE IS TOO BIG!); \
129 $(call echo_red, ======================); \
136 # $(1): filename of image to copy
137 # $(2): image size limit (check if set)
140 $(call echo_green,Copying compiled image...)
142 cp $(SOURCE_DIR)/$(strip $(1)).bin $(BIN_DIR)/temp.bin
143 $(if $(2),$(call size_chk,$(BIN_DIR)/temp.bin,$(2)))
146 # $(1): size limit in KB
147 # $(2): if set to 1, use LZMA
148 # $(3): other parameters passed to subdir make
150 args="IMG_SIZE=$(call img_size,$(1)) \
151 IMG_LZMA=$(call is_one,$(2)) \
153 cd $(SOURCE_DIR) && \
154 $(SUB_MAKE_CMD) $@ $$args && \
155 $(SUB_MAKE_CMD) all $$args
157 $(if $(filter $(IMG_RAM),1),\
158 $(call copy_img,u-boot), \
159 $(if $(filter $(call is_one,$(2)),1), \
160 $(call copy_img,tuboot,$(call img_size,$(1))), \
161 $(call copy_img,u-boot,$(call img_size,$(1))) \
165 $(if $(filter $(IMG_RAM),1),,$(call padded_img,$(1)))
169 $(call echo_green,DONE!)
170 $(call echo_green,Image 'bin/$(call img_name,bin)' is ready!)
172 if [ "x$$IMG_RAM" = "x1" ]; then \
174 $(call echo_blue, ================================); \
175 $(call echo_blue, THIS IMAGE IS ONLY FOR RAM LOAD!); \
176 $(call echo_blue, DO NOT WRITE IT INTO FLASH CHIP!); \
177 $(call echo_blue, ================================); \
182 # ===========================================
183 # TARGETS IN ALPHABETICAL ORDER, SHARED FIRST
184 # ===========================================
186 COMMON_AR933X_TARGETS = \
187 gainstrong_oolite_v1_dev \
188 gl-innovations_gl-inet-6416 \
193 tp-link_tl-mr3220_v2 \
196 tp-link_tl-wr720n_v3_CN \
199 $(COMMON_AR933X_TARGETS):
202 COMMON_ETHS27_TARGETS = \
203 tp-link_tl-mr3420_v2 \
204 tp-link_tl-wa830re_v2_tl-wa801nd_v2 \
207 tp-link_tl-wr820n_CN \
208 tp-link_tl-wr841n_v8 \
211 $(COMMON_ETHS27_TARGETS):
212 @$(call build,123,1,ETH_CONFIG=_s27)
221 @$(call build,192,1,DEVICE_VENDOR=dragino)
223 tp-link_tl-wdr3600_tl-43x0:
224 @$(call build,123,1,ETH_CONFIG=_s17)
226 unwireddevices_unwired-one:
227 @$(call build,128,1,DEVICE_VENDOR=SE)
229 village-telco_mesh-potato_v2:
230 @$(call build,192,1,DEVICE_VENDOR=villagetelco)
233 @$(call build,192,1,ETH_CONFIG=_s27)
236 @$(call build,256,1,ETH_CONFIG=_s27)
243 @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) distclean
244 @rm -f $(SOURCE_DIR)/httpd/fsdata.c
247 @$(call echo_green,Removing all binary images...)
248 @rm -f $(BIN_DIR)/*.bin
249 @rm -f $(BIN_DIR)/*.md5