ramips: Add support for ZTE ZXECS EBG3130 aka BDCOM WAP2100-SK
[openwrt/openwrt.git] / include / image-commands.mk
1 # Build commands that can be called from Device/* templates
2
3 IMAGE_KERNEL = $(word 1,$^)
4 IMAGE_ROOTFS = $(word 2,$^)
5
6 define Build/uImage
7 mkimage -A $(LINUX_KARCH) \
8 -O linux -T kernel \
9 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
10 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' -d $@ $@.new
11 mv $@.new $@
12 endef
13
14 define Build/buffalo-enc
15 $(eval product=$(word 1,$(1)))
16 $(eval version=$(word 2,$(1)))
17 $(eval args=$(wordlist 3,$(words $(1)),$(1)))
18 $(STAGING_DIR_HOST)/bin/buffalo-enc \
19 -p $(product) -v $(version) $(args) \
20 -i $@ -o $@.new
21 mv $@.new $@
22 endef
23
24 define Build/buffalo-enc-tag
25 $(call Build/buffalo-enc,'' '' -S 152 $(1))
26 endef
27
28 define Build/buffalo-tag-dhp
29 $(eval product=$(word 1,$(1)))
30 $(eval region=$(word 2,$(1)))
31 $(eval language=$(word 3,$(1)))
32 $(STAGING_DIR_HOST)/bin/buffalo-tag \
33 -d 0x01000000 -w 1 \
34 -a $(BUFFALO_TAG_PLATFORM) \
35 -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
36 -b $(product) -p $(product) \
37 -r $(region) -r $(region) -l $(language) \
38 -I $@ -o $@.new
39 mv $@.new $@
40 endef
41
42 define Build/buffalo-dhp-image
43 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
44 mv $@.new $@
45 endef
46
47 define Build/eva-image
48 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
49 mv $@.new $@
50 endef
51
52 define Build/zyxel-ras-image
53 let \
54 newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
55 $(STAGING_DIR_HOST)/bin/mkrasimage \
56 -b $(RAS_BOARD) \
57 -v $(RAS_VERSION) \
58 -r $@ \
59 -s $$newsize \
60 -o $@.new \
61 $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
62 && mv $@.new $@
63 endef
64
65 define Build/mkbuffaloimg
66 $(STAGING_DIR_HOST)/bin/mkbuffaloimg -B $(BOARDNAME) \
67 -R $$(($(subst k, * 1024,$(ROOTFS_SIZE)))) \
68 -K $$(($(subst k, * 1024,$(KERNEL_SIZE)))) \
69 -i $@ -o $@.new
70 mv $@.new $@
71 endef
72
73 define Build/netgear-chk
74 $(STAGING_DIR_HOST)/bin/mkchkimg \
75 -o $@.new \
76 -k $@ \
77 -b $(NETGEAR_BOARD_ID) \
78 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
79 mv $@.new $@
80 endef
81
82 define Build/netgear-dni
83 $(STAGING_DIR_HOST)/bin/mkdniimg \
84 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
85 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
86 -r "$(1)" \
87 -i $@ -o $@.new
88 mv $@.new $@
89 endef
90
91 define Build/append-squashfs-fakeroot-be
92 rm -rf $@.fakefs $@.fakesquashfs
93 mkdir $@.fakefs
94 $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
95 $@.fakefs $@.fakesquashfs \
96 -noappend -root-owned -be -nopad -b 65536 \
97 $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
98 cat $@.fakesquashfs >> $@
99 endef
100
101 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
102 # for example
103 define Build/append-uImage-fakehdr
104 touch $@.fakehdr
105 $(STAGING_DIR_HOST)/bin/mkimage \
106 -A $(LINUX_KARCH) -O linux -T $(1) -C none \
107 -n '$(VERSION_DIST) fake $(1)' \
108 -d $@.fakehdr \
109 -s \
110 $@.fakehdr
111 cat $@.fakehdr >> $@
112 endef
113
114 define Build/tplink-safeloader
115 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
116 -B $(TPLINK_BOARD_ID) \
117 -V $(REVISION) \
118 -k $(IMAGE_KERNEL) \
119 -r $@ \
120 -o $@.new \
121 -j \
122 $(wordlist 2,$(words $(1)),$(1)) \
123 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
124 endef
125
126 define Build/mksercommfw
127 -$(STAGING_DIR_HOST)/bin/mksercommfw \
128 $@ \
129 $(KERNEL_OFFSET) \
130 $(HWID) \
131 $(HWVER) \
132 $(SWVER)
133 endef
134
135
136 define Build/append-dtb
137 cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
138 endef
139
140 define Build/install-dtb
141 $(foreach dts,$(DEVICE_DTS), \
142 $(CP) \
143 $(DTS_DIR)/$(dts).dtb \
144 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
145 )
146 endef
147
148 define Build/fit
149 $(TOPDIR)/scripts/mkits.sh \
150 -D $(DEVICE_NAME) -o $@.its -k $@ \
151 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
152 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
153 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
154 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
155 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
156 @mv $@.new $@
157 endef
158
159 define Build/lzma
160 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
161 endef
162
163 define Build/lzma-no-dict
164 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
165 @mv $@.new $@
166 endef
167
168 define Build/gzip
169 gzip -f -9n -c $@ $(1) > $@.new
170 @mv $@.new $@
171 endef
172
173 define Build/jffs2
174 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
175 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
176 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
177 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
178 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
179 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
180 -o $@.new \
181 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
182 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
183 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
184 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
185 @mv $@.new $@
186 endef
187
188 define Build/kernel-bin
189 rm -f $@
190 cp $< $@
191 endef
192
193 define Build/patch-cmdline
194 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
195 endef
196
197 define Build/append-kernel
198 dd if=$(IMAGE_KERNEL) >> $@
199 endef
200
201 define Build/append-rootfs
202 dd if=$(IMAGE_ROOTFS) >> $@
203 endef
204
205 define Build/append-ubi
206 sh $(TOPDIR)/scripts/ubinize-image.sh \
207 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
208 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
209 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
210 $(IMAGE_ROOTFS) \
211 $@.tmp \
212 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
213 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
214 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
215 $(UBINIZE_OPTS)
216 cat $@.tmp >> $@
217 rm $@.tmp
218 endef
219
220 define Build/append-uboot
221 dd if=$(UBOOT_PATH) >> $@
222 endef
223
224 define Build/pad-to
225 dd if=$@ of=$@.new bs=$(1) conv=sync
226 mv $@.new $@
227 endef
228
229 define Build/pad-extra
230 dd if=/dev/zero bs=$(1) count=1 >> $@
231 endef
232
233 define Build/pad-rootfs
234 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
235 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
236 endef
237
238 define Build/pad-offset
239 let \
240 size="$$(stat -c%s $@)" \
241 pad="$(subst k,* 1024,$(word 1, $(1)))" \
242 offset="$(subst k,* 1024,$(word 2, $(1)))" \
243 pad="(pad - ((size + offset) % pad)) % pad" \
244 newsize='size + pad'; \
245 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
246 mv $@.new $@
247 endef
248
249 define Build/check-size
250 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
251 echo "WARNING: Image file $@ is too big" >&2; \
252 rm -f $@; \
253 }
254 endef
255
256 define Build/combined-image
257 -sh $(TOPDIR)/scripts/combined-image.sh \
258 "$(IMAGE_KERNEL)" \
259 "$@" \
260 "$@.new"
261 @mv $@.new $@
262 endef
263
264 define Build/openmesh-image
265 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
266 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
267 "$@-fwupgrade.cfg" \
268 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
269 "$(call param_get_default,rootfs,$(1),$@)"
270 $(TOPDIR)/scripts/combined-ext-image.sh \
271 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
272 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
273 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
274 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
275 endef
276
277 define Build/senao-header
278 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
279 mv $@.new $@
280 endef
281
282 define Build/sysupgrade-tar
283 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
284 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
285 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
286 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
287 $@
288 endef
289
290 define Build/tplink-v1-header
291 $(STAGING_DIR_HOST)/bin/mktplinkfw \
292 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
293 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
294 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
295 -k $@ -o $@.new $(1)
296 @mv $@.new $@
297 endef
298
299 define Build/tplink-v2-header
300 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
301 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
302 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
303 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
304 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
305 -k $@ -o $@.new $(1)
306 @mv $@.new $@
307 endef
308
309 define Build/tplink-v2-image
310 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
311 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
312 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
313 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
314 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
315 cat $@.new >> $@
316 rm -rf $@.new
317 endef
318
319 json_quote=$(subst ','\'',$(subst ",\",$(1)))
320 #")')
321 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
322 metadata_json = \
323 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
324 "supported_devices":[$(call metadata_devices,$(1))], \
325 "version": { \
326 "dist": "$(call json_quote,$(VERSION_DIST))", \
327 "version": "$(call json_quote,$(VERSION_NUMBER))", \
328 "revision": "$(call json_quote,$(REVISION))", \
329 "board": "$(call json_quote,$(BOARD))" \
330 } \
331 }'
332
333 define Build/append-metadata
334 $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
335 [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
336 cp "$(BUILD_KEY).ucert" "$@.ucert" ;\
337 usign -S -m "$@" -s "$(BUILD_KEY)" -x "$@.sig" ;\
338 ucert -A -c "$@.ucert" -x "$@.sig" ;\
339 fwtool -S "$@.ucert" "$@" ;\
340 }
341 endef
342
343 define Build/kernel2minor
344 kernel2minor -k $@ -r $@.new $(1)
345 mv $@.new $@
346 endef