Add support for GainStrong Oolite v5.2 (QCA9531 based)
[oweals/u-boot_mod.git] / Makefile
1 #
2 # Copyright (C) 2016 Piotr Dymacz <piotr@dymacz.pl>
3 #
4 # SPDX-License-Identifier: GPL-2.0
5 #
6
7 SHELL = bash
8
9 HOSTARCH := $(shell uname -m |        \
10               sed -e s/i.86/x86_32/   \
11                   -e s/sun4u/sparc64/ \
12                   -e s/arm.*/arm/     \
13                   -e s/sa110/arm/     \
14                   -e s/powerpc/ppc/   \
15                   -e s/macppc/ppc/)
16
17 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
18             sed -e 's/\(cygwin\).*/cygwin/')
19
20 ifneq ($(HOSTOS), darwin)
21   ifneq ($(HOSTOS), linux)
22     $(error Error! Unsupported host operating system/arch: "$(HOSTOS)-$(HOSTARCH)")
23   endif
24 endif
25
26 export HOSTOS
27 export 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)
34
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=...
39
40 # Set to 1 if you want to build RAM-loadable image, without low level
41 # initialization of the hardware (PLL/clocks, DRAM):
42 # IMG_RAM =
43
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):
46 # IMG_SIZE =
47
48 # If you don't want LZMA compressed image, set below option to 1 (by default
49 # images for all targets are LZMA compressed):
50 # IMG_LZMA =
51
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)
55
56 ifndef CROSS_COMPILE
57   CROSS_COMPILE = mips-openwrt-linux-musl-
58 endif
59 export CROSS_COMPILE
60
61 # By default, optimization for size (-Os) is enabled, set below option
62 # to n or remove it if you want only basic optimization (-O/-O1)
63 # BUILD_OPTIMIZED = n
64
65 ifneq ($(BUILD_OPTIMIZED), n)
66   BUILD_OPTIMIZED = y
67 endif
68 export BUILD_OPTIMIZED
69
70 # ==========================================================================
71
72 # =======================
73 # CUSTOM HELPER FUNCTIONS
74 # =======================
75
76 define echo_green
77   echo -e "\e[92m$(1)\e[0m"
78 endef
79
80 define echo_red
81   echo -e "\e[91m$(1)\e[0m"
82 endef
83
84 define echo_blue
85   echo -e "\e[96m$(1)\e[0m"
86 endef
87
88 # $(1): size
89 define img_size
90 $(if $(IMG_SIZE),$(strip $(IMG_SIZE)),$(strip $(1)))
91 endef
92
93 # $(1): value
94 define is_lzma
95 $(if $(IMG_LZMA),\
96   $(if $(filter $(strip $(IMG_LZMA)),1),1,0),\
97   $(if $(filter $(strip $(1)),1),1,0)\
98 )
99 endef
100
101 define git_branch
102 $(shell git symbolic-ref --short -q HEAD 2>/dev/null || echo "unknown")
103 endef
104
105 define git_hash
106 $(shell git rev-parse --short=8 -q HEAD 2>/dev/null || echo "unknown")
107 endef
108
109 define git_branch_hash
110 git_$(call git_branch)-$(call git_hash)
111 endef
112
113 # $(1): file extension
114 define img_name
115 u-boot_mod__$@__$(shell date +"%Y%m%d")__$(call git_branch_hash)$(if \
116 $(filter $(IMG_RAM),1),__RAM-LOAD-ONLY)$(if $(1),.$(1))
117 endef
118
119 define md5_sum
120   $(call echo_green,Calculating MD5 sum for the final image...)
121
122   md5sum $(BIN_DIR)/$(call img_name,bin) | \
123          awk '{print $$1}' | \
124          tr -d '\n' > $(BIN_DIR)/$(call img_name).md5
125
126   echo ' *'$(call img_name,bin) >> $(BIN_DIR)/$(call img_name,md5)
127 endef
128
129 # $(1): size
130 define padded_img
131   $(call echo_green,Preparing $(1) KB image padded with 0xFF...)
132   tr "\000" "\377" < /dev/zero | dd ibs=1k count=$(1) \
133      of=$(BIN_DIR)/$(call img_name,bin) 2> /dev/null
134 endef
135
136 define final_img
137   $(call echo_green,Preparing final image...)
138   dd if=$(BIN_DIR)/temp.bin of=$(BIN_DIR)/$(call img_name,bin) \
139      conv=notrunc 2> /dev/null
140
141   rm -f $(BIN_DIR)/temp.bin
142 endef
143
144 # $(1): path to image
145 # $(2): size limit in KB
146 define size_chk
147   $(call echo_green,Checking size of the image...)
148
149   if [ `wc -c < $(1)` -gt $$(($(2) * 1024)) ]; then \
150     echo; \
151     $(call echo_red,  ======================); \
152     $(call echo_red,  IMAGE SIZE IS TOO BIG!); \
153     $(call echo_red,  ======================); \
154     echo; \
155     rm -f $(1); \
156     exit 1; \
157   fi;
158 endef
159
160 # $(1): filename of image to copy
161 # $(2): image size limit (check if set)
162 define copy_img
163   echo;
164   $(call echo_green,Copying compiled image...)
165
166   cp $(SOURCE_DIR)/$(strip $(1)).bin $(BIN_DIR)/temp.bin
167   $(if $(2),$(call size_chk,$(BIN_DIR)/temp.bin,$(2)))
168 endef
169
170 # $(1): size limit in KB
171 # $(2): if set to 1, use LZMA
172 # $(3): other parameters passed to subdir make
173 define build
174   args="IMG_SIZE=$$((1024*$(call img_size,$(1)))) \
175         IMG_LZMA=$(strip $(call is_lzma,$(2))) \
176         $(strip $(3))"; \
177   cd $(SOURCE_DIR) && \
178      $(SUB_MAKE_CMD) $@ $$args && \
179      $(SUB_MAKE_CMD) all $$args
180
181   $(if $(filter $(IMG_RAM),1),\
182     $(call copy_img,u-boot), \
183     $(if $(filter $(strip $(call is_lzma,$(2))),1), \
184       $(call copy_img,tuboot,$(call img_size,$(1))), \
185       $(call copy_img,u-boot,$(call img_size,$(1))) \
186     ) \
187   )
188
189   $(if $(filter $(IMG_RAM),1),,$(call padded_img,$(1)))
190   $(call final_img)
191   $(call md5_sum)
192   echo;
193   $(call echo_green,DONE!)
194   $(call echo_green,Image 'bin/$(call img_name,bin)' is ready!)
195
196   if [ "x$$IMG_RAM" = "x1" ]; then \
197     echo; \
198     $(call echo_blue,  ================================); \
199     $(call echo_blue,  THIS IMAGE IS ONLY FOR RAM LOAD!); \
200     $(call echo_blue,  DO NOT WRITE IT INTO FLASH CHIP!); \
201     $(call echo_blue,  ================================); \
202     echo; \
203   fi;
204 endef
205
206 # ===========================================
207 # TARGETS IN ALPHABETICAL ORDER, SHARED FIRST
208 # ===========================================
209
210 COMMON_AR933X_TARGETS = \
211         gainstrong_oolite_v1_dev \
212         gl-inet_6416 \
213         hak5_lan-turtle \
214         hak5_packet-squirrel \
215         hak5_wifi-pineapple-nano \
216         tp-link_tl-mr10u_v1 \
217         tp-link_tl-mr13u_v1 \
218         tp-link_tl-mr3020_v1 \
219         tp-link_tl-mr3040_v1v2 \
220         tp-link_tl-mr3220_v2 \
221         tp-link_tl-wr703n_v1 \
222         tp-link_tl-wr710n_v1 \
223         tp-link_tl-wr720n_v3_CN \
224         tp-link_tl-wr740n_v4
225
226 $(COMMON_AR933X_TARGETS):
227         @$(call build,123,1)
228
229 COMMON_ETHS27_TARGETS = \
230         gainstrong_oolite_v5.2 \
231         gainstrong_oolite_v5.2_dev \
232         tp-link_tl-mr22u_v1 \
233         tp-link_tl-mr3420_v2 \
234         tp-link_tl-mr3420_v3 \
235         tp-link_tl-mr6400_v1v2 \
236         tp-link_tl-wa801nd_v2 \
237         tp-link_tl-wa830re_v2 \
238         tp-link_tl-wa850re_v2 \
239         tp-link_tl-wdr3500_v1 \
240         tp-link_tl-wr802n_v1 \
241         tp-link_tl-wr810n_v1 \
242         tp-link_tl-wr810n_v2 \
243         tp-link_tl-wr820n_v1_CN \
244         tp-link_tl-wr841n_v10 \
245         tp-link_tl-wr841n_v11 \
246         tp-link_tl-wr841n_v8 \
247         tp-link_tl-wr841n_v9 \
248         tp-link_tl-wr842n_v3 \
249         tp-link_tl-wr902ac_v1
250
251 $(COMMON_ETHS27_TARGETS):
252         @$(call build,123,1,ETH_CONFIG=_s27)
253
254 8devices_carambola2 \
255 alfa-network_hornet-ub \
256 alfa-network_tube2h \
257 creatcomm-technology_d3321 \
258 gl-inet_gl-ar150 \
259 gl-inet_gl-usb150:
260         @$(call build,256,1)
261
262 alfa-network_ap121f:
263         @$(call build,192,1)
264
265 alfa-network_n5q \
266 alfa-network_r36a:
267         @$(call build,384,1,ETH_CONFIG=_s27)
268
269 comfast_cf-e314n \
270 comfast_cf-e320n_v2 \
271 comfast_cf-e520n \
272 comfast_cf-e530n:
273         @$(call build,64,1,ETH_CONFIG=_s27)
274
275 d-link_dir-505_a1:
276         @$(call build,64,1)
277
278 dragino_ms14:
279         @$(call build,192,1,DEVICE_VENDOR=dragino)
280
281 engenius_ens202ext \
282 gl-inet_gl-ar300 \
283 gl-inet_gl-ar300m-lite \
284 gl-inet_gl-ar750 \
285 p2w_cpe505n \
286 p2w_r602n \
287 yuncore_ap90q \
288 yuncore_cpe830 \
289 yuncore_t830 \
290 whqx_e600g_v2 \
291 whqx_e600gac_v2 \
292 zbtlink_zbt-we1526:
293         @$(call build,256,1,ETH_CONFIG=_s27)
294
295 tp-link_tl-wdr3600_v1 \
296 tp-link_tl-wdr43x0_v1 \
297 tp-link_tl-wr1041n_v2:
298         @$(call build,123,1,ETH_CONFIG=_s17)
299
300 unwireddevices_unwired-one:
301         @$(call build,128,1,DEVICE_VENDOR=SE)
302
303 village-telco_mesh-potato_v2:
304         @$(call build,192,1,DEVICE_VENDOR=villagetelco)
305
306 wallys_dr531:
307         @$(call build,192,1,ETH_CONFIG=_s27)
308
309 yuncore_cpe870:
310         @$(call build,64,1,ETH_CONFIG=_s27)
311
312 # =============
313 # CLEAN TARGETS
314 # =============
315
316 lzma_host_clean:
317         @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) $@
318
319 clean:
320         @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) distclean
321         @rm -f $(SOURCE_DIR)/httpd/fsdata.c
322
323 clean_all: clean
324         @$(call echo_green,Removing all binary images...)
325         @rm -f $(BIN_DIR)/*.bin
326         @rm -f $(BIN_DIR)/*.md5