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