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