1f6ba1c15a47e983692a0a100721e4420476818a
[openwrt/staging/noltari.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 printf %.16s "$(word 2, $(subst _, ,$(1)))")
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-squashfs4-fakeroot
116 rm -rf $@.fakefs $@.fakesquashfs
117 mkdir $@.fakefs
118 $(STAGING_DIR_HOST)/bin/mksquashfs4 \
119 $@.fakefs $@.fakesquashfs \
120 -nopad -noappend -root-owned
121 cat $@.fakesquashfs >> $@
122 endef
123
124 define Build/append-string
125 echo -n $(1) >> $@
126 endef
127
128 define Build/append-ubi
129 sh $(TOPDIR)/scripts/ubinize-image.sh \
130 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
131 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
132 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
133 --rootfs $(IMAGE_ROOTFS) \
134 $@.tmp \
135 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
136 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
137 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
138 $(UBINIZE_OPTS)
139 cat $@.tmp >> $@
140 rm $@.tmp
141 endef
142
143 define Build/ubinize-kernel
144 cp $@ $@.tmp
145 sh $(TOPDIR)/scripts/ubinize-image.sh \
146 --kernel $@.tmp \
147 $@ \
148 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
149 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
150 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
151 $(UBINIZE_OPTS)
152 rm $@.tmp
153 endef
154
155 define Build/append-uboot
156 dd if=$(UBOOT_PATH) >> $@
157 endef
158
159 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
160 # for example
161 define Build/append-uImage-fakehdr
162 $(eval type=$(word 1,$(1)))
163 $(eval magic=$(word 2,$(1)))
164 touch $@.fakehdr
165 $(STAGING_DIR_HOST)/bin/mkimage \
166 -A $(LINUX_KARCH) -O linux -T $(type) -C none \
167 -n '$(VERSION_DIST) fake $(type)' \
168 $(if $(magic),-M $(magic)) \
169 -d $@.fakehdr \
170 -s \
171 $@.fakehdr
172 cat $@.fakehdr >> $@
173 endef
174
175 define Build/buffalo-dhp-image
176 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
177 mv $@.new $@
178 endef
179
180 define Build/buffalo-enc
181 $(eval product=$(word 1,$(1)))
182 $(eval version=$(word 2,$(1)))
183 $(eval args=$(wordlist 3,$(words $(1)),$(1)))
184 $(STAGING_DIR_HOST)/bin/buffalo-enc \
185 -p $(product) -v $(version) $(args) \
186 -i $@ -o $@.new
187 mv $@.new $@
188 endef
189
190 define Build/buffalo-enc-tag
191 $(call Build/buffalo-enc,'' '' -S 152 $(1))
192 endef
193
194 define Build/buffalo-tag-dhp
195 $(eval product=$(word 1,$(1)))
196 $(eval region=$(word 2,$(1)))
197 $(eval language=$(word 3,$(1)))
198 $(STAGING_DIR_HOST)/bin/buffalo-tag \
199 -d 0x01000000 -w 1 \
200 -a $(BUFFALO_TAG_PLATFORM) \
201 -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
202 -b $(product) -p $(product) \
203 -r $(region) -r $(region) -l $(language) \
204 -I $@ -o $@.new
205 mv $@.new $@
206 endef
207
208 define Build/check-size
209 @imagesize="$$(stat -c%s $@)"; \
210 limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
211 [ $$limitsize -ge $$imagesize ] || { \
212 $(call ERROR_MESSAGE, WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
213 rm -f $@; \
214 }
215 endef
216
217 define Build/copy-file
218 cat "$(1)" > "$@"
219 endef
220
221 define Build/edimax-header
222 $(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o $@.new $(1)
223 @mv $@.new $@
224 endef
225
226 define Build/elecom-product-header
227 $(eval product=$(word 1,$(1)))
228 $(eval fw=$(if $(word 2,$(1)),$(word 2,$(1)),$@))
229
230 ( \
231 echo -n -e "ELECOM\x00\x00$(product)" | dd bs=40 count=1 conv=sync; \
232 echo -n "0.00" | dd bs=16 count=1 conv=sync; \
233 dd if=$(fw); \
234 ) > $(fw).new
235 mv $(fw).new $(fw)
236 endef
237
238 define Build/elecom-wrc-gs-factory
239 $(eval product=$(word 1,$(1)))
240 $(eval version=$(word 2,$(1)))
241 $(eval hash_opt=$(word 3,$(1)))
242 $(MKHASH) md5 $(hash_opt) $@ >> $@
243 ( \
244 echo -n "ELECOM $(product) v$(version)" | \
245 dd bs=32 count=1 conv=sync; \
246 dd if=$@; \
247 ) > $@.new
248 mv $@.new $@
249 endef
250
251 define Build/elx-header
252 $(eval hw_id=$(word 1,$(1)))
253 $(eval xor_pattern=$(word 2,$(1)))
254 ( \
255 echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
256 dd bs=42 count=1 conv=sync; \
257 hw_id="$(hw_id)"; \
258 echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
259 dd bs=20 count=1 conv=sync; \
260 echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
261 dd bs=8 count=1 conv=sync; \
262 echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
263 dd bs=58 count=1 conv=sync; \
264 ) > $(KDIR)/tmp/$(DEVICE_NAME).header
265 $(call Build/xor-image,-p $(xor_pattern) -x)
266 cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > $@.new
267 mv $@.new $@
268 rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
269 endef
270
271 define Build/eva-image
272 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
273 mv $@.new $@
274 endef
275
276 define Build/initrd_compression
277 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
278 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
279 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
280 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
281 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
282 endef
283
284 define Build/fit
285 $(TOPDIR)/scripts/mkits.sh \
286 -D $(DEVICE_NAME) -o $@.its -k $@ \
287 -C $(word 1,$(1)) \
288 $(if $(word 2,$(1)),\
289 $(if $(findstring 11,$(if $(DEVICE_DTS_OVERLAY),1)$(if $(findstring $(KERNEL_BUILD_DIR)/image-,$(word 2,$(1))),,1)), \
290 -d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))), \
291 -d $(word 2,$(1)))) \
292 $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
293 $(if $(findstring with-initrd,$(word 3,$(1))), \
294 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
295 -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
296 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
297 $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
298 $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \
299 $(if $(DEVICE_DTS_LOADADDR),-s $(DEVICE_DTS_LOADADDR)) \
300 $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtb)) \
301 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
302 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
303 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
304 -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f $@.its $@.new
305 @mv $@.new $@
306 endef
307
308 define Build/gzip
309 gzip -f -9n -c $@ $(1) > $@.new
310 @mv $@.new $@
311 endef
312
313 define Build/install-dtb
314 $(call locked, \
315 $(foreach dts,$(DEVICE_DTS), \
316 $(CP) \
317 $(DTS_DIR)/$(dts).dtb \
318 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
319 ), \
320 install-dtb-$(IMG_PREFIX) \
321 )
322 endef
323
324 define Build/iptime-crc32
325 $(STAGING_DIR_HOST)/bin/iptime-crc32 $(1) $@ $@.new
326 mv $@.new $@
327 endef
328
329 define Build/iptime-naspkg
330 $(STAGING_DIR_HOST)/bin/iptime-naspkg $(1) $@ $@.new
331 mv $@.new $@
332 endef
333
334 define Build/jffs2
335 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
336 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
337 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
338 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
339 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
340 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
341 -o $@.new \
342 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
343 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
344 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
345 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
346 @mv $@.new $@
347 endef
348
349 define Build/kernel2minor
350 $(eval temp_file := $(shell mktemp))
351 cp $@ $(temp_file)
352 kernel2minor -k $(temp_file) -r $(temp_file).new $(1)
353 mv $(temp_file).new $@
354 rm -f $(temp_file)
355 endef
356
357 define Build/kernel-bin
358 rm -f $@
359 cp $< $@
360 endef
361
362 define Build/linksys-image
363 $(TOPDIR)/scripts/linksys-image.sh \
364 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
365 $@ $@.new
366 mv $@.new $@
367 endef
368
369 define Build/lzma
370 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
371 endef
372
373 define Build/lzma-no-dict
374 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
375 @mv $@.new $@
376 endef
377
378 define Build/netgear-chk
379 $(STAGING_DIR_HOST)/bin/mkchkimg \
380 -o $@.new \
381 -k $@ \
382 -b $(NETGEAR_BOARD_ID) \
383 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
384 mv $@.new $@
385 endef
386
387 define Build/netgear-dni
388 $(STAGING_DIR_HOST)/bin/mkdniimg \
389 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
390 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
391 -r "$(1)" \
392 -i $@ -o $@.new
393 mv $@.new $@
394 endef
395
396 define Build/netgear-encrypted-factory
397 $(TOPDIR)/scripts/netgear-encrypted-factory.py \
398 --input-file $@ \
399 --output-file $@ \
400 --model $(NETGEAR_ENC_MODEL) \
401 --region $(NETGEAR_ENC_REGION) \
402 --version V1.0.0.0.$(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
403 --encryption-block-size 0x20000 \
404 --openssl-bin "$(STAGING_DIR_HOST)/bin/openssl" \
405 --key 6865392d342b4d212964363d6d7e7765312c7132613364316e26322a5a5e2538 \
406 --iv 4a253169516c38243d6c6d2d3b384145
407 endef
408
409 define Build/openmesh-image
410 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
411 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
412 "$@-fwupgrade.cfg" \
413 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
414 "$(call param_get_default,rootfs,$(1),$@)"
415 $(TOPDIR)/scripts/combined-ext-image.sh \
416 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
417 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
418 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
419 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
420 endef
421
422 define Build/pad-extra
423 dd if=/dev/zero bs=$(1) count=1 >> $@
424 endef
425
426 define Build/pad-offset
427 let \
428 size="$$(stat -c%s $@)" \
429 pad="$(subst k,* 1024,$(word 1, $(1)))" \
430 offset="$(subst k,* 1024,$(word 2, $(1)))" \
431 pad="(pad - ((size + offset) % pad)) % pad" \
432 newsize='size + pad'; \
433 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
434 mv $@.new $@
435 endef
436
437 define Build/pad-rootfs
438 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
439 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
440 endef
441
442 define Build/pad-to
443 $(call Image/pad-to,$@,$(1))
444 endef
445
446 define Build/patch-cmdline
447 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
448 endef
449
450 # Convert a raw image into a $1 type image.
451 # E.g. | qemu-image vdi <optional extra arguments to qemu-img binary>
452 define Build/qemu-image
453 if command -v qemu-img; then \
454 qemu-img convert -f raw -O $1 $@ $@.new; \
455 mv $@.new $@; \
456 else \
457 echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
458 fi
459 endef
460
461 define Build/qsdk-ipq-factory-nand
462 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
463 $@.its ubi $@
464 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
465 @mv $@.new $@
466 endef
467
468 define Build/qsdk-ipq-factory-nor
469 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
470 $@.its hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
471 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
472 @mv $@.new $@
473 endef
474
475 define Build/seama
476 $(STAGING_DIR_HOST)/bin/seama -i $@ \
477 -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
478 mv $@.seama $@
479 endef
480
481 define Build/seama-seal
482 $(STAGING_DIR_HOST)/bin/seama -i $@ -s $@.seama \
483 -m "signature=$(SEAMA_SIGNATURE)"
484 mv $@.seama $@
485 endef
486
487 define Build/senao-header
488 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
489 mv $@.new $@
490 endef
491
492 define Build/sysupgrade-tar
493 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
494 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
495 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
496 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
497 $@
498 endef
499
500 define Build/tplink-safeloader
501 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
502 -B $(TPLINK_BOARD_ID) \
503 -V $(REVISION) \
504 -k $(IMAGE_KERNEL) \
505 -r $@ \
506 -o $@.new \
507 -j \
508 $(wordlist 2,$(words $(1)),$(1)) \
509 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
510 endef
511
512 define Build/tplink-v1-header
513 $(STAGING_DIR_HOST)/bin/mktplinkfw \
514 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
515 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
516 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
517 -k $@ -o $@.new $(1)
518 @mv $@.new $@
519 endef
520
521 # combine kernel and rootfs into one image
522 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
523 # <type> is "sysupgrade" or "factory"
524 #
525 # -a align the rootfs start on an <align> bytes boundary
526 # -j add jffs2 end-of-filesystem markers
527 # -s strip padding from end of the image
528 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
529 define Build/tplink-v1-image
530 -$(STAGING_DIR_HOST)/bin/mktplinkfw \
531 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
532 -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
533 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new -j -X 0x40000 \
534 -a $(call rootfs_align,$(FILESYSTEM)) \
535 $(wordlist 2,$(words $(1)),$(1)) \
536 $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv $@.new $@ || rm -f $@
537 endef
538
539 define Build/tplink-v2-header
540 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
541 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
542 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
543 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
544 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
545 -k $@ -o $@.new $(1)
546 @mv $@.new $@
547 endef
548
549 define Build/tplink-v2-image
550 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
551 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
552 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
553 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
554 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
555 cat $@.new >> $@
556 rm -rf $@.new
557 endef
558
559 define Build/uImage
560 mkimage \
561 -A $(LINUX_KARCH) \
562 -O linux \
563 -T kernel \
564 -C $(word 1,$(1)) \
565 -a $(KERNEL_LOADADDR) \
566 -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
567 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
568 $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
569 $(wordlist 2,$(words $(1)),$(1)) \
570 -d $@ $@.new
571 mv $@.new $@
572 endef
573
574 define Build/xor-image
575 $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o $@.xor $(1)
576 mv $@.xor $@
577 endef
578
579 define Build/zip
580 rm -rf $@.tmp
581 mkdir $@.tmp
582 mv $@ $@.tmp/$(word 1,$(1))
583 TZ=UTC $(STAGING_DIR_HOST)/bin/zip -j -X \
584 $(wordlist 2,$(words $(1)),$(1)) \
585 $@ $@.tmp/$(if $(word 1,$(1)),$(word 1,$(1)),$$(basename $@))
586 rm -rf $@.tmp
587 endef
588
589 define Build/zyxel-ras-image
590 let \
591 newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
592 $(STAGING_DIR_HOST)/bin/mkrasimage \
593 -b $(RAS_BOARD) \
594 -v $(RAS_VERSION) \
595 -r $@ \
596 -s $$newsize \
597 -o $@.new \
598 $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
599 && mv $@.new $@
600 endef