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