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