Add support for TP-Link TL-WA850RE v2 (QCA9533 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 # ==========================================================================
62
63 # =======================
64 # CUSTOM HELPER FUNCTIONS
65 # =======================
66
67 define echo_green
68   echo -e "\e[92m$(1)\e[0m"
69 endef
70
71 define echo_red
72   echo -e "\e[91m$(1)\e[0m"
73 endef
74
75 define echo_blue
76   echo -e "\e[96m$(1)\e[0m"
77 endef
78
79 # $(1): size
80 define img_size
81 $(if $(IMG_SIZE),$(strip $(IMG_SIZE)),$(strip $(1)))
82 endef
83
84 # $(1): value
85 define is_lzma
86 $(if $(IMG_LZMA),\
87   $(if $(filter $(strip $(IMG_LZMA)),1),1,0),\
88   $(if $(filter $(strip $(1)),1),1,0)\
89 )
90 endef
91
92 define git_branch
93 $(shell git symbolic-ref --short -q HEAD 2>/dev/null || echo "unknown")
94 endef
95
96 define git_hash
97 $(shell git rev-parse --short=8 -q HEAD 2>/dev/null || echo "unknown")
98 endef
99
100 define git_branch_hash
101 git_$(call git_branch)-$(call git_hash)
102 endef
103
104 # $(1): file extension
105 define img_name
106 u-boot_mod__$(shell date +"%Y%m%d")__$(call git_branch_hash)__$@$(if \
107 $(filter $(IMG_RAM),1),__RAM-LOAD-ONLY)$(if $(1),.$(1))
108 endef
109
110 define md5_sum
111   $(call echo_green,Calculating MD5 sum for the final image...)
112
113   md5sum $(BIN_DIR)/$(call img_name,bin) | \
114          awk '{print $$1}' | \
115          tr -d '\n' > $(BIN_DIR)/$(call img_name).md5
116
117   echo ' *'$(call img_name,bin) >> $(BIN_DIR)/$(call img_name,md5)
118 endef
119
120 # $(1): size
121 define padded_img
122   $(call echo_green,Preparing $(1) KB image padded with 0xFF...)
123   tr "\000" "\377" < /dev/zero | dd ibs=1k count=$(1) \
124      of=$(BIN_DIR)/$(call img_name,bin) 2> /dev/null
125 endef
126
127 define final_img
128   $(call echo_green,Preparing final image...)
129   dd if=$(BIN_DIR)/temp.bin of=$(BIN_DIR)/$(call img_name,bin) \
130      conv=notrunc 2> /dev/null
131
132   rm -f $(BIN_DIR)/temp.bin
133 endef
134
135 # $(1): path to image
136 # $(2): size limit in KB
137 define size_chk
138   $(call echo_green,Checking size of the image...)
139
140   if [ `wc -c < $(1)` -gt $$(($(2) * 1024)) ]; then \
141     echo; \
142     $(call echo_red,  ======================); \
143     $(call echo_red,  IMAGE SIZE IS TOO BIG!); \
144     $(call echo_red,  ======================); \
145     echo; \
146     rm -f $(1); \
147     exit 1; \
148   fi;
149 endef
150
151 # $(1): filename of image to copy
152 # $(2): image size limit (check if set)
153 define copy_img
154   echo;
155   $(call echo_green,Copying compiled image...)
156
157   cp $(SOURCE_DIR)/$(strip $(1)).bin $(BIN_DIR)/temp.bin
158   $(if $(2),$(call size_chk,$(BIN_DIR)/temp.bin,$(2)))
159 endef
160
161 # $(1): size limit in KB
162 # $(2): if set to 1, use LZMA
163 # $(3): other parameters passed to subdir make
164 define build
165   args="IMG_SIZE=$$((1024*$(call img_size,$(1)))) \
166         IMG_LZMA=$(strip $(call is_lzma,$(2))) \
167         $(strip $(3))"; \
168   cd $(SOURCE_DIR) && \
169      $(SUB_MAKE_CMD) $@ $$args && \
170      $(SUB_MAKE_CMD) all $$args
171
172   $(if $(filter $(IMG_RAM),1),\
173     $(call copy_img,u-boot), \
174     $(if $(filter $(strip $(call is_lzma,$(2))),1), \
175       $(call copy_img,tuboot,$(call img_size,$(1))), \
176       $(call copy_img,u-boot,$(call img_size,$(1))) \
177     ) \
178   )
179
180   $(if $(filter $(IMG_RAM),1),,$(call padded_img,$(1)))
181   $(call final_img)
182   $(call md5_sum)
183   echo;
184   $(call echo_green,DONE!)
185   $(call echo_green,Image 'bin/$(call img_name,bin)' is ready!)
186
187   if [ "x$$IMG_RAM" = "x1" ]; then \
188     echo; \
189     $(call echo_blue,  ================================); \
190     $(call echo_blue,  THIS IMAGE IS ONLY FOR RAM LOAD!); \
191     $(call echo_blue,  DO NOT WRITE IT INTO FLASH CHIP!); \
192     $(call echo_blue,  ================================); \
193     echo; \
194   fi;
195 endef
196
197 # ===========================================
198 # TARGETS IN ALPHABETICAL ORDER, SHARED FIRST
199 # ===========================================
200
201 COMMON_AR933X_TARGETS = \
202         gainstrong_oolite_v1_dev \
203         gl-innovations_gl-inet-6416 \
204         tp-link_tl-mr10u \
205         tp-link_tl-mr13u \
206         tp-link_tl-mr3020 \
207         tp-link_tl-mr3040 \
208         tp-link_tl-mr3220_v2 \
209         tp-link_tl-wr703n \
210         tp-link_tl-wr710n \
211         tp-link_tl-wr720n_v3_CN \
212         tp-link_tl-wr740n_v4
213
214 $(COMMON_AR933X_TARGETS):
215         @$(call build,123,1)
216
217 COMMON_ETHS27_TARGETS = \
218         tp-link_tl-mr3420_v2 \
219         tp-link_tl-wa801nd_v2 \
220         tp-link_tl-wa850re_v2 \
221         tp-link_tl-wa830re_v2 \
222         tp-link_tl-wdr3500 \
223         tp-link_tl-wr802n \
224         tp-link_tl-wr810n \
225         tp-link_tl-wr820n_CN \
226         tp-link_tl-wr841n_v10 \
227         tp-link_tl-wr841n_v11 \
228         tp-link_tl-wr841n_v8 \
229         tp-link_tl-wr841n_v9
230
231 $(COMMON_ETHS27_TARGETS):
232         @$(call build,123,1,ETH_CONFIG=_s27)
233
234 8devices_carambola2 \
235 alfa-network_hornet-ub \
236 gl-innovations_gl-ar150:
237         @$(call build,256,1)
238
239 comfast_cf-e314n \
240 comfast_cf-e320n_v2 \
241 comfast_cf-e520n \
242 comfast_cf-e530n:
243         @$(call build,64,1,ETH_CONFIG=_s27)
244
245 d-link_dir-505:
246         @$(call build,64,1)
247
248 dragino_v2_ms14:
249         @$(call build,192,1,DEVICE_VENDOR=dragino)
250
251 p2w_cpe505n \
252 p2w_r602n \
253 yuncore_ap90q \
254 yuncore_cpe830 \
255 zbtlink_zbt-we1526:
256         @$(call build,256,1,ETH_CONFIG=_s27)
257
258 tp-link_tl-wdr3600 \
259 tp-link_tl-wdr43x0:
260         @$(call build,123,1,ETH_CONFIG=_s17)
261
262 unwireddevices_unwired-one:
263         @$(call build,128,1,DEVICE_VENDOR=SE)
264
265 village-telco_mesh-potato_v2:
266         @$(call build,192,1,DEVICE_VENDOR=villagetelco)
267
268 wallys_dr531:
269         @$(call build,192,1,ETH_CONFIG=_s27)
270
271 yuncore_cpe870:
272         @$(call build,64,1,ETH_CONFIG=_s27)
273
274 # =============
275 # CLEAN TARGETS
276 # =============
277
278 lzma_host_clean:
279         @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) $@
280
281 clean:
282         @cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) distclean
283         @rm -f $(SOURCE_DIR)/httpd/fsdata.c
284
285 clean_all: clean
286         @$(call echo_green,Removing all binary images...)
287         @rm -f $(BIN_DIR)/*.bin
288         @rm -f $(BIN_DIR)/*.md5