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