This repository has been archived by the owner on Oct 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 537
/
Makefile
326 lines (267 loc) · 7.81 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
#
# Copyright (C) 2016 Piotr Dymacz <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0
#
SHELL = bash
HOSTARCH := $(shell uname -m | \
sed -e s/i.86/x86_32/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ \
-e s/sa110/arm/ \
-e s/powerpc/ppc/ \
-e s/macppc/ppc/)
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
sed -e 's/\(cygwin\).*/cygwin/')
ifneq ($(HOSTOS), darwin)
ifneq ($(HOSTOS), linux)
$(error Error! Unsupported host operating system/arch: "$(HOSTOS)-$(HOSTARCH)")
endif
endif
export HOSTOS
export HOSTARCH
export BUILD_TOPDIR = $(PWD)
export STAGING_DIR = $(BUILD_TOPDIR)/tmp
export SOURCE_DIR = $(BUILD_TOPDIR)/u-boot
export BIN_DIR = $(BUILD_TOPDIR)/bin
export SUB_MAKE_CMD = $(MAKE) --silent --no-print-directory \
ARCH=mips V=1 SHELL=$(SHELL)
# ==========================================================================
# You can override some default configuration options below or pass them on
# command line, for example:
# make ... IMG_SIZE=256 IMG_LZMA=0 CROSS_COMPILE=...
# Set to 1 if you want to build RAM-loadable image, without low level
# initialization of the hardware (PLL/clocks, DRAM):
# IMG_RAM =
# You can change limit of the image size in KB with below option (image will
# be filled up to the selected size with 0xFF):
# IMG_SIZE =
# If you don't want LZMA compressed image, set below option to 1 (by default
# images for all targets are LZMA compressed):
# IMG_LZMA =
# Define _absolute_ path to your toolchain directory, for example:
# export TOOLCHAIN_DIR:=/home/user/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.15
# export PATH:=$(TOOLCHAIN_DIR)/bin:$(PATH)
ifndef CROSS_COMPILE
CROSS_COMPILE = mips-openwrt-linux-musl-
endif
export CROSS_COMPILE
# By default, optimization for size (-Os) is enabled, set below option
# to n or remove it if you want only basic optimization (-O/-O1)
# BUILD_OPTIMIZED = n
ifneq ($(BUILD_OPTIMIZED), n)
BUILD_OPTIMIZED = y
endif
export BUILD_OPTIMIZED
# ==========================================================================
# =======================
# CUSTOM HELPER FUNCTIONS
# =======================
define echo_green
echo -e "\e[92m$(1)\e[0m"
endef
define echo_red
echo -e "\e[91m$(1)\e[0m"
endef
define echo_blue
echo -e "\e[96m$(1)\e[0m"
endef
# $(1): size
define img_size
$(if $(IMG_SIZE),$(strip $(IMG_SIZE)),$(strip $(1)))
endef
# $(1): value
define is_lzma
$(if $(IMG_LZMA),\
$(if $(filter $(strip $(IMG_LZMA)),1),1,0),\
$(if $(filter $(strip $(1)),1),1,0)\
)
endef
define git_branch
$(shell git symbolic-ref --short -q HEAD 2>/dev/null || echo "unknown")
endef
define git_hash
$(shell git rev-parse --short=8 -q HEAD 2>/dev/null || echo "unknown")
endef
define git_branch_hash
git_$(call git_branch)-$(call git_hash)
endef
# $(1): file extension
define img_name
u-boot_mod__$@__$(shell date +"%Y%m%d")__$(call git_branch_hash)$(if \
$(filter $(IMG_RAM),1),__RAM-LOAD-ONLY)$(if $(1),.$(1))
endef
define md5_sum
$(call echo_green,Calculating MD5 sum for the final image...)
md5sum $(BIN_DIR)/$(call img_name,bin) | \
awk '{print $$1}' | \
tr -d '\n' > $(BIN_DIR)/$(call img_name).md5
echo ' *'$(call img_name,bin) >> $(BIN_DIR)/$(call img_name,md5)
endef
# $(1): size
define padded_img
$(call echo_green,Preparing $(1) KB image padded with 0xFF...)
tr "\000" "\377" < /dev/zero | dd ibs=1k count=$(1) \
of=$(BIN_DIR)/$(call img_name,bin) 2> /dev/null
endef
define final_img
$(call echo_green,Preparing final image...)
dd if=$(BIN_DIR)/temp.bin of=$(BIN_DIR)/$(call img_name,bin) \
conv=notrunc 2> /dev/null
rm -f $(BIN_DIR)/temp.bin
endef
# $(1): path to image
# $(2): size limit in KB
define size_chk
$(call echo_green,Checking size of the image...)
if [ `wc -c < $(1)` -gt $$(($(2) * 1024)) ]; then \
echo; \
$(call echo_red, ======================); \
$(call echo_red, IMAGE SIZE IS TOO BIG!); \
$(call echo_red, ======================); \
echo; \
rm -f $(1); \
exit 1; \
fi;
endef
# $(1): filename of image to copy
# $(2): image size limit (check if set)
define copy_img
echo;
$(call echo_green,Copying compiled image...)
cp $(SOURCE_DIR)/$(strip $(1)).bin $(BIN_DIR)/temp.bin
$(if $(2),$(call size_chk,$(BIN_DIR)/temp.bin,$(2)))
endef
# $(1): size limit in KB
# $(2): if set to 1, use LZMA
# $(3): other parameters passed to subdir make
define build
args="IMG_SIZE=$$((1024*$(call img_size,$(1)))) \
IMG_LZMA=$(strip $(call is_lzma,$(2))) \
$(strip $(3))"; \
cd $(SOURCE_DIR) && \
$(SUB_MAKE_CMD) $@ $$args && \
$(SUB_MAKE_CMD) all $$args
$(if $(filter $(IMG_RAM),1),\
$(call copy_img,u-boot), \
$(if $(filter $(strip $(call is_lzma,$(2))),1), \
$(call copy_img,tuboot,$(call img_size,$(1))), \
$(call copy_img,u-boot,$(call img_size,$(1))) \
) \
)
$(if $(filter $(IMG_RAM),1),,$(call padded_img,$(1)))
$(call final_img)
$(call md5_sum)
echo;
$(call echo_green,DONE!)
$(call echo_green,Image 'bin/$(call img_name,bin)' is ready!)
if [ "x$$IMG_RAM" = "x1" ]; then \
echo; \
$(call echo_blue, ================================); \
$(call echo_blue, THIS IMAGE IS ONLY FOR RAM LOAD!); \
$(call echo_blue, DO NOT WRITE IT INTO FLASH CHIP!); \
$(call echo_blue, ================================); \
echo; \
fi;
endef
# ===========================================
# TARGETS IN ALPHABETICAL ORDER, SHARED FIRST
# ===========================================
COMMON_AR933X_TARGETS = \
gainstrong_oolite_v1_dev \
gl-inet_6416 \
hak5_lan-turtle \
hak5_packet-squirrel \
hak5_wifi-pineapple-nano \
tp-link_tl-mr10u_v1 \
tp-link_tl-mr13u_v1 \
tp-link_tl-mr3020_v1 \
tp-link_tl-mr3040_v1v2 \
tp-link_tl-mr3220_v2 \
tp-link_tl-wr703n_v1 \
tp-link_tl-wr710n_v1 \
tp-link_tl-wr720n_v3_CN \
tp-link_tl-wr740n_v4
$(COMMON_AR933X_TARGETS):
@$(call build,123,1)
COMMON_ETHS27_TARGETS = \
gainstrong_oolite_v5.2 \
gainstrong_oolite_v5.2_dev \
tp-link_tl-mr22u_v1 \
tp-link_tl-mr3420_v2 \
tp-link_tl-mr3420_v3 \
tp-link_tl-mr6400_v1v2 \
tp-link_tl-wa801nd_v2 \
tp-link_tl-wa830re_v2 \
tp-link_tl-wa850re_v2 \
tp-link_tl-wdr3500_v1 \
tp-link_tl-wr802n_v1 \
tp-link_tl-wr810n_v1 \
tp-link_tl-wr810n_v2 \
tp-link_tl-wr820n_v1_CN \
tp-link_tl-wr841n_v10 \
tp-link_tl-wr841n_v11 \
tp-link_tl-wr841n_v8 \
tp-link_tl-wr841n_v9 \
tp-link_tl-wr842n_v3 \
tp-link_tl-wr902ac_v1
$(COMMON_ETHS27_TARGETS):
@$(call build,123,1,ETH_CONFIG=_s27)
8devices_carambola2 \
alfa-network_hornet-ub \
alfa-network_tube2h \
creatcomm-technology_d3321 \
gl-inet_gl-ar150 \
gl-inet_gl-usb150:
@$(call build,256,1)
alfa-network_ap121f:
@$(call build,192,1)
alfa-network_n5q \
alfa-network_r36a:
@$(call build,384,1,ETH_CONFIG=_s27)
comfast_cf-e314n \
comfast_cf-e320n_v2 \
comfast_cf-e520n \
comfast_cf-e530n:
@$(call build,64,1,ETH_CONFIG=_s27)
d-link_dir-505_a1:
@$(call build,64,1)
dragino_ms14:
@$(call build,192,1,DEVICE_VENDOR=dragino)
engenius_ens202ext \
gl-inet_gl-ar300 \
gl-inet_gl-ar300m-lite \
gl-inet_gl-ar750 \
p2w_cpe505n \
p2w_r602n \
yuncore_ap90q \
yuncore_cpe830 \
yuncore_t830 \
whqx_e600g_v2 \
whqx_e600gac_v2 \
zbtlink_zbt-we1526:
@$(call build,256,1,ETH_CONFIG=_s27)
tp-link_tl-wdr3600_v1 \
tp-link_tl-wdr43x0_v1 \
tp-link_tl-wr1041n_v2:
@$(call build,123,1,ETH_CONFIG=_s17)
unwireddevices_unwired-one:
@$(call build,128,1,DEVICE_VENDOR=SE)
village-telco_mesh-potato_v2:
@$(call build,192,1,DEVICE_VENDOR=villagetelco)
wallys_dr531:
@$(call build,192,1,ETH_CONFIG=_s27)
yuncore_cpe870:
@$(call build,64,1,ETH_CONFIG=_s27)
# =============
# CLEAN TARGETS
# =============
lzma_host_clean:
@cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) $@
clean:
@cd $(SOURCE_DIR) && $(SUB_MAKE_CMD) distclean
@rm -f $(SOURCE_DIR)/httpd/fsdata.c
clean_all: clean
@$(call echo_green,Removing all binary images...)
@rm -f $(BIN_DIR)/*.bin
@rm -f $(BIN_DIR)/*.md5