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