image: strip metadata from images when used in other artifacts
[openwrt/staging/hauke.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 ModelNameLimit16
7 $(shell expr substr "$(word 2, $(subst _, ,$(1)))" 1 16)
8 endef
9
10 define rootfs_align
11 $(patsubst %-256k,0x40000,$(patsubst %-128k,0x20000,$(patsubst %-64k,0x10000,$(patsubst squashfs%,0x4,$(patsubst root.%,%,$(1))))))
12 endef
13
14
15 define Build/append-dtb
16 cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
17 endef
18
19 define Build/append-dtb-elf
20 $(TARGET_CROSS)objcopy \
21 --set-section-flags=.appended_dtb=alloc,contents \
22 --update-section \
23 .appended_dtb=$(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb $@
24 endef
25
26 define Build/append-kernel
27 dd if=$(IMAGE_KERNEL) >> $@
28 endef
29
30 define Build/package-kernel-ubifs
31 mkdir $@.kernelubifs
32 cp $@ $@.kernelubifs/kernel
33 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
34 $(KERNEL_UBIFS_OPTS) \
35 -r $@.kernelubifs $@
36 rm -r $@.kernelubifs
37 endef
38
39 define Build/append-image
40 cp "$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1)" "$@.stripmeta"
41 fwtool -s /dev/null -t "$@.stripmeta" || :
42 fwtool -i /dev/null -t "$@.stripmeta" || :
43 dd if="$@.stripmeta" >> "$@"
44 rm "$@.stripmeta"
45 endef
46
47 ifdef IB
48 define Build/append-image-stage
49 dd if=$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))-$(DEVICE_NAME)-$(1) >> $@
50 endef
51 else
52 define Build/append-image-stage
53 cp "$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1)" "$@.stripmeta"
54 fwtool -s /dev/null -t "$@.stripmeta" || :
55 fwtool -i /dev/null -t "$@.stripmeta" || :
56 dd if="$@.stripmeta" of="$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))-$(DEVICE_NAME)-$(1)"
57 dd if="$@.stripmeta" >> "$@"
58 rm "$@.stripmeta"
59 endef
60 endif
61
62
63 compat_version=$(if $(DEVICE_COMPAT_VERSION),$(DEVICE_COMPAT_VERSION),1.0)
64 json_quote=$(subst ','\'',$(subst ",\",$(1)))
65 #")')
66
67 legacy_supported_message=$(SUPPORTED_DEVICES) - Image version mismatch: image $(compat_version), \
68 device 1.0. Please wipe config during upgrade (force required) or reinstall. \
69 $(if $(DEVICE_COMPAT_MESSAGE),Reason: $(DEVICE_COMPAT_MESSAGE),Please check documentation ...)
70
71 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
72 metadata_json = \
73 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
74 "metadata_version": "1.1", \
75 "compat_version": "$(call json_quote,$(compat_version))", \
76 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
77 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
78 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
79 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
80 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
81 "version": { \
82 "dist": "$(call json_quote,$(VERSION_DIST))", \
83 "version": "$(call json_quote,$(VERSION_NUMBER))", \
84 "revision": "$(call json_quote,$(REVISION))", \
85 "target": "$(call json_quote,$(TARGETID))", \
86 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
87 } \
88 }'
89
90 define Build/append-metadata
91 $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json) | fwtool -I - $@)
92 sha256sum "$@" | cut -d" " -f1 > "$@.sha256sum"
93 [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
94 cp "$(BUILD_KEY).ucert" "$@.ucert" ;\
95 usign -S -m "$@" -s "$(BUILD_KEY)" -x "$@.sig" ;\
96 ucert -A -c "$@.ucert" -x "$@.sig" ;\
97 fwtool -S "$@.ucert" "$@" ;\
98 }
99 endef
100
101 define Build/append-rootfs
102 dd if=$(IMAGE_ROOTFS) >> $@
103 endef
104
105 define Build/append-squashfs-fakeroot-be
106 rm -rf $@.fakefs $@.fakesquashfs
107 mkdir $@.fakefs
108 $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
109 $@.fakefs $@.fakesquashfs \
110 -noappend -root-owned -be -nopad -b 65536 \
111 $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
112 cat $@.fakesquashfs >> $@
113 endef
114
115 define Build/append-string
116 echo -n $(1) >> $@
117 endef
118
119 define Build/append-ubi
120 sh $(TOPDIR)/scripts/ubinize-image.sh \
121 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
122 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
123 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
124 --rootfs $(IMAGE_ROOTFS) \
125 $@.tmp \
126 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
127 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
128 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
129 $(UBINIZE_OPTS)
130 cat $@.tmp >> $@
131 rm $@.tmp
132 endef
133
134 define Build/ubinize-kernel
135 cp $@ $@.tmp
136 sh $(TOPDIR)/scripts/ubinize-image.sh \
137 --kernel $@.tmp \
138 $@ \
139 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
140 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
141 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
142 $(UBINIZE_OPTS)
143 rm $@.tmp
144 endef
145
146 define Build/append-uboot
147 dd if=$(UBOOT_PATH) >> $@
148 endef
149
150 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
151 # for example
152 define Build/append-uImage-fakehdr
153 $(eval type=$(word 1,$(1)))
154 $(eval magic=$(word 2,$(1)))
155 touch $@.fakehdr
156 $(STAGING_DIR_HOST)/bin/mkimage \
157 -A $(LINUX_KARCH) -O linux -T $(type) -C none \
158 -n '$(VERSION_DIST) fake $(type)' \
159 $(if $(magic),-M $(magic)) \
160 -d $@.fakehdr \
161 -s \
162 $@.fakehdr
163 cat $@.fakehdr >> $@
164 endef
165
166 define Build/buffalo-dhp-image
167 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
168 mv $@.new $@
169 endef
170
171 define Build/buffalo-enc
172 $(eval product=$(word 1,$(1)))
173 $(eval version=$(word 2,$(1)))
174 $(eval args=$(wordlist 3,$(words $(1)),$(1)))
175 $(STAGING_DIR_HOST)/bin/buffalo-enc \
176 -p $(product) -v $(version) $(args) \
177 -i $@ -o $@.new
178 mv $@.new $@
179 endef
180
181 define Build/buffalo-enc-tag
182 $(call Build/buffalo-enc,'' '' -S 152 $(1))
183 endef
184
185 define Build/buffalo-tag-dhp
186 $(eval product=$(word 1,$(1)))
187 $(eval region=$(word 2,$(1)))
188 $(eval language=$(word 3,$(1)))
189 $(STAGING_DIR_HOST)/bin/buffalo-tag \
190 -d 0x01000000 -w 1 \
191 -a $(BUFFALO_TAG_PLATFORM) \
192 -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
193 -b $(product) -p $(product) \
194 -r $(region) -r $(region) -l $(language) \
195 -I $@ -o $@.new
196 mv $@.new $@
197 endef
198
199 define Build/check-size
200 @imagesize="$$(stat -c%s $@)"; \
201 limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
202 [ $$limitsize -ge $$imagesize ] || { \
203 $(call ERROR_MESSAGE, WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
204 rm -f $@; \
205 }
206 endef
207
208 define Build/copy-file
209 cat "$(1)" > "$@"
210 endef
211
212 define Build/elecom-product-header
213 $(eval product=$(word 1,$(1)))
214 $(eval fw=$(if $(word 2,$(1)),$(word 2,$(1)),$@))
215
216 ( \
217 echo -n -e "ELECOM\x00\x00$(product)" | dd bs=40 count=1 conv=sync; \
218 echo -n "0.00" | dd bs=16 count=1 conv=sync; \
219 dd if=$(fw); \
220 ) > $(fw).new
221 mv $(fw).new $(fw)
222 endef
223
224 define Build/elecom-wrc-gs-factory
225 $(eval product=$(word 1,$(1)))
226 $(eval version=$(word 2,$(1)))
227 $(eval hash_opt=$(word 3,$(1)))
228 $(MKHASH) md5 $(hash_opt) $@ >> $@
229 ( \
230 echo -n "ELECOM $(product) v$(version)" | \
231 dd bs=32 count=1 conv=sync; \
232 dd if=$@; \
233 ) > $@.new
234 mv $@.new $@
235 endef
236
237 define Build/elx-header
238 $(eval hw_id=$(word 1,$(1)))
239 $(eval xor_pattern=$(word 2,$(1)))
240 ( \
241 echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
242 dd bs=42 count=1 conv=sync; \
243 hw_id="$(hw_id)"; \
244 echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
245 dd bs=20 count=1 conv=sync; \
246 echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
247 dd bs=8 count=1 conv=sync; \
248 echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
249 dd bs=58 count=1 conv=sync; \
250 ) > $(KDIR)/tmp/$(DEVICE_NAME).header
251 $(call Build/xor-image,-p $(xor_pattern) -x)
252 cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > $@.new
253 mv $@.new $@
254 rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
255 endef
256
257 define Build/eva-image
258 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
259 mv $@.new $@
260 endef
261
262 define Build/initrd_compression
263 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
264 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
265 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
266 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
267 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
268 endef
269
270 define Build/fit
271 $(TOPDIR)/scripts/mkits.sh \
272 -D $(DEVICE_NAME) -o $@.its -k $@ \
273 -C $(word 1,$(1)) $(if $(word 2,$(1)),\
274 $(if $(DEVICE_DTS_OVERLAY),-d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))),\
275 -d $(word 2,$(1)))) \
276 $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
277 $(if $(findstring with-initrd,$(word 3,$(1))), \
278 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
279 -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
280 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
281 $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
282 $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \
283 $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtb)) \
284 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
285 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
286 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
287 -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f $@.its $@.new
288 @mv $@.new $@
289 endef
290
291 define Build/gzip
292 gzip -f -9n -c $@ $(1) > $@.new
293 @mv $@.new $@
294 endef
295
296 define Build/install-dtb
297 $(call locked, \
298 $(foreach dts,$(DEVICE_DTS), \
299 $(CP) \
300 $(DTS_DIR)/$(dts).dtb \
301 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
302 ), \
303 install-dtb-$(IMG_PREFIX) \
304 )
305 endef
306
307 define Build/iptime-crc32
308 $(STAGING_DIR_HOST)/bin/iptime-crc32 $(1) $@ $@.new
309 mv $@.new $@
310 endef
311
312 define Build/iptime-naspkg
313 $(STAGING_DIR_HOST)/bin/iptime-naspkg $(1) $@ $@.new
314 mv $@.new $@
315 endef
316
317 define Build/jffs2
318 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
319 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
320 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
321 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
322 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
323 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
324 -o $@.new \
325 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
326 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
327 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
328 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
329 @mv $@.new $@
330 endef
331
332 define Build/kernel2minor
333 $(eval temp_file := $(shell mktemp))
334 cp $@ $(temp_file)
335 kernel2minor -k $(temp_file) -r $(temp_file).new $(1)
336 mv $(temp_file).new $@
337 rm -f $(temp_file)
338 endef
339
340 define Build/kernel-bin
341 rm -f $@
342 cp $< $@
343 endef
344
345 define Build/linksys-image
346 $(TOPDIR)/scripts/linksys-image.sh \
347 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
348 $@ $@.new
349 mv $@.new $@
350 endef
351
352 define Build/lzma
353 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
354 endef
355
356 define Build/lzma-no-dict
357 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
358 @mv $@.new $@
359 endef
360
361 define Build/netgear-chk
362 $(STAGING_DIR_HOST)/bin/mkchkimg \
363 -o $@.new \
364 -k $@ \
365 -b $(NETGEAR_BOARD_ID) \
366 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
367 mv $@.new $@
368 endef
369
370 define Build/netgear-dni
371 $(STAGING_DIR_HOST)/bin/mkdniimg \
372 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
373 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
374 -r "$(1)" \
375 -i $@ -o $@.new
376 mv $@.new $@
377 endef
378
379 define Build/openmesh-image
380 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
381 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
382 "$@-fwupgrade.cfg" \
383 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
384 "$(call param_get_default,rootfs,$(1),$@)"
385 $(TOPDIR)/scripts/combined-ext-image.sh \
386 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
387 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
388 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
389 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
390 endef
391
392 define Build/pad-extra
393 dd if=/dev/zero bs=$(1) count=1 >> $@
394 endef
395
396 define Build/pad-offset
397 let \
398 size="$$(stat -c%s $@)" \
399 pad="$(subst k,* 1024,$(word 1, $(1)))" \
400 offset="$(subst k,* 1024,$(word 2, $(1)))" \
401 pad="(pad - ((size + offset) % pad)) % pad" \
402 newsize='size + pad'; \
403 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
404 mv $@.new $@
405 endef
406
407 define Build/pad-rootfs
408 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
409 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
410 endef
411
412 define Build/pad-to
413 $(call Image/pad-to,$@,$(1))
414 endef
415
416 define Build/patch-cmdline
417 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
418 endef
419
420 # Convert a raw image into a $1 type image.
421 # E.g. | qemu-image vdi <optional extra arguments to qemu-img binary>
422 define Build/qemu-image
423 if command -v qemu-img; then \
424 qemu-img convert -f raw -O $1 $@ $@.new; \
425 mv $@.new $@; \
426 else \
427 echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
428 fi
429 endef
430
431 define Build/qsdk-ipq-factory-nand
432 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
433 $@.its ubi $@
434 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
435 @mv $@.new $@
436 endef
437
438 define Build/qsdk-ipq-factory-nor
439 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
440 $@.its hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
441 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
442 @mv $@.new $@
443 endef
444
445 define Build/seama
446 $(STAGING_DIR_HOST)/bin/seama -i $@ \
447 -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
448 mv $@.seama $@
449 endef
450
451 define Build/seama-seal
452 $(STAGING_DIR_HOST)/bin/seama -i $@ -s $@.seama \
453 -m "signature=$(SEAMA_SIGNATURE)"
454 mv $@.seama $@
455 endef
456
457 define Build/senao-header
458 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
459 mv $@.new $@
460 endef
461
462 define Build/sysupgrade-tar
463 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
464 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
465 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
466 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
467 $@
468 endef
469
470 define Build/tplink-safeloader
471 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
472 -B $(TPLINK_BOARD_ID) \
473 -V $(REVISION) \
474 -k $(IMAGE_KERNEL) \
475 -r $@ \
476 -o $@.new \
477 -j \
478 $(wordlist 2,$(words $(1)),$(1)) \
479 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
480 endef
481
482 define Build/tplink-v1-header
483 $(STAGING_DIR_HOST)/bin/mktplinkfw \
484 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
485 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
486 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
487 -k $@ -o $@.new $(1)
488 @mv $@.new $@
489 endef
490
491 # combine kernel and rootfs into one image
492 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
493 # <type> is "sysupgrade" or "factory"
494 #
495 # -a align the rootfs start on an <align> bytes boundary
496 # -j add jffs2 end-of-filesystem markers
497 # -s strip padding from end of the image
498 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
499 define Build/tplink-v1-image
500 -$(STAGING_DIR_HOST)/bin/mktplinkfw \
501 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
502 -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
503 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new -j -X 0x40000 \
504 -a $(call rootfs_align,$(FILESYSTEM)) \
505 $(wordlist 2,$(words $(1)),$(1)) \
506 $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv $@.new $@ || rm -f $@
507 endef
508
509 define Build/tplink-v2-header
510 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
511 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
512 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
513 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
514 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
515 -k $@ -o $@.new $(1)
516 @mv $@.new $@
517 endef
518
519 define Build/tplink-v2-image
520 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
521 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
522 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
523 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
524 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
525 cat $@.new >> $@
526 rm -rf $@.new
527 endef
528
529 define Build/uImage
530 mkimage \
531 -A $(LINUX_KARCH) \
532 -O linux \
533 -T kernel \
534 -C $(word 1,$(1)) \
535 -a $(KERNEL_LOADADDR) \
536 -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
537 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
538 $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
539 $(wordlist 2,$(words $(1)),$(1)) \
540 -d $@ $@.new
541 mv $@.new $@
542 endef
543
544 define Build/xor-image
545 $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o $@.xor $(1)
546 mv $@.xor $@
547 endef
548
549 define Build/zip
550 rm -rf $@.tmp
551 mkdir $@.tmp
552 mv $@ $@.tmp/$(word 1,$(1))
553 TZ=UTC $(STAGING_DIR_HOST)/bin/zip -j -X \
554 $(wordlist 2,$(words $(1)),$(1)) \
555 $@ $@.tmp/$(if $(word 1,$(1)),$(word 1,$(1)),$$(basename $@))
556 rm -rf $@.tmp
557 endef
558
559 define Build/zyxel-ras-image
560 let \
561 newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
562 $(STAGING_DIR_HOST)/bin/mkrasimage \
563 -b $(RAS_BOARD) \
564 -v $(RAS_VERSION) \
565 -r $@ \
566 -s $$newsize \
567 -o $@.new \
568 $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
569 && mv $@.new $@
570 endef