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