1 # Build commands that can be called from Device/* templates
3 IMAGE_KERNEL
= $(word 1,$^
)
4 IMAGE_ROOTFS
= $(word 2,$^
)
6 define ModelNameLimit16
7 $(shell expr substr
"$(word 2, $(subst _, ,$(1)))" 1 16)
11 $(patsubst %-256k
,0x40000,$(patsubst %-128k
,0x20000,$(patsubst %-64k
,0x10000,$(patsubst squashfs
%,0x4,$(patsubst root.
%,%,$(1))))))
15 define Build
/append-dtb
16 cat
$(KDIR
)/image-
$(firstword $(DEVICE_DTS
)).dtb
>> $@
19 define Build
/append-dtb-elf
20 $(TARGET_CROSS
)objcopy \
21 --set-section-flags
=.appended_dtb
=alloc
,contents \
23 .appended_dtb
=$(KDIR
)/image-
$(firstword $(DEVICE_DTS
)).dtb
$@
26 define Build
/append-kernel
27 dd if
=$(IMAGE_KERNEL
) >> $@
30 define Build
/append-image
31 dd if
=$(BIN_DIR
)/$(DEVICE_IMG_PREFIX
)-$(1) >> $@
35 define Build
/append-image-stage
36 dd if
=$(STAGING_DIR_IMAGE
)/$(BOARD
)$(if
$(SUBTARGET
),-$(SUBTARGET
))-$(DEVICE_NAME
)-$(1) >> $@
39 define Build
/append-image-stage
40 dd if
=$(BIN_DIR
)/$(DEVICE_IMG_PREFIX
)-$(1) of
=$(STAGING_DIR_IMAGE
)/$(BOARD
)$(if
$(SUBTARGET
),-$(SUBTARGET
))-$(DEVICE_NAME
)-$(1)
41 dd if
=$(BIN_DIR
)/$(DEVICE_IMG_PREFIX
)-$(1) >> $@
46 compat_version
=$(if
$(DEVICE_COMPAT_VERSION
),$(DEVICE_COMPAT_VERSION
),1.0)
47 json_quote
=$(subst ','\'',$(subst ",\",$(1)))
50 legacy_supported_message
=$(SUPPORTED_DEVICES
) - Image version mismatch
: image
$(compat_version
), \
51 device
1.0. Please wipe config during upgrade
(force required
) or reinstall. \
52 $(if
$(DEVICE_COMPAT_MESSAGE
),Reason
: $(DEVICE_COMPAT_MESSAGE
),Please
check documentation ...
)
54 metadata_devices
=$(if
$(1),$(subst "$(space)","$(comma)",$(strip $(foreach v
,$(1),"$(call json_quote,$(v))"))))
56 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
57 "metadata_version": "1.1", \
58 "compat_version": "$(call json_quote,$(compat_version))", \
59 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
60 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
61 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
62 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
63 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
65 "dist": "$(call json_quote,$(VERSION_DIST))", \
66 "version": "$(call json_quote,$(VERSION_NUMBER))", \
67 "revision": "$(call json_quote,$(REVISION))", \
68 "target": "$(call json_quote,$(TARGETID))", \
69 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
73 define Build
/append-metadata
74 $(if
$(SUPPORTED_DEVICES
),-echo
$(call metadata_json
) | fwtool
-I
- $@
)
75 [ ! -s
"$(BUILD_KEY)" -o
! -s
"$(BUILD_KEY).ucert" -o
! -s
"$@" ] ||
{ \
76 cp
"$(BUILD_KEY).ucert" "$@.ucert" ;\
77 usign
-S
-m
"$@" -s
"$(BUILD_KEY)" -x
"$@.sig" ;\
78 ucert
-A
-c
"$@.ucert" -x
"$@.sig" ;\
79 fwtool
-S
"$@.ucert" "$@" ;\
83 define Build
/append-rootfs
84 dd if
=$(IMAGE_ROOTFS
) >> $@
87 define Build
/append-squashfs-fakeroot-be
88 rm -rf
$@.fakefs
$@.fakesquashfs
90 $(STAGING_DIR_HOST
)/bin
/mksquashfs-lzma \
91 $@.fakefs
$@.fakesquashfs \
92 -noappend
-root-owned
-be
-nopad
-b
65536 \
93 $(if
$(SOURCE_DATE_EPOCH
),-fixed-time
$(SOURCE_DATE_EPOCH
))
94 cat
$@.fakesquashfs
>> $@
97 define Build
/append-string
101 define Build
/append-ubi
102 sh
$(TOPDIR
)/scripts
/ubinize-image.sh \
103 $(if
$(UBOOTENV_IN_UBI
),--uboot-env
) \
104 $(if
$(KERNEL_IN_UBI
),--kernel
$(IMAGE_KERNEL
)) \
105 $(foreach part
,$(UBINIZE_PARTS
),--part
$(part
)) \
108 -p
$(BLOCKSIZE
:%k
=%KiB
) -m
$(PAGESIZE
) \
109 $(if
$(SUBPAGESIZE
),-s
$(SUBPAGESIZE
)) \
110 $(if
$(VID_HDR_OFFSET
),-O
$(VID_HDR_OFFSET
)) \
116 define Build
/append-uboot
117 dd if
=$(UBOOT_PATH
) >> $@
120 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
122 define Build
/append-uImage-fakehdr
123 $(eval type
=$(word 1,$(1)))
124 $(eval magic
=$(word 2,$(1)))
126 $(STAGING_DIR_HOST
)/bin
/mkimage \
127 -A
$(LINUX_KARCH
) -O linux
-T
$(type
) -C none \
128 -n
'$(VERSION_DIST) fake $(type)' \
129 $(if
$(magic
),-M
$(magic
)) \
136 define Build
/buffalo-dhp-image
137 $(STAGING_DIR_HOST
)/bin
/mkdhpimg
$@
$@.new
141 define Build
/buffalo-enc
142 $(eval product
=$(word 1,$(1)))
143 $(eval version
=$(word 2,$(1)))
144 $(eval args
=$(wordlist
3,$(words $(1)),$(1)))
145 $(STAGING_DIR_HOST
)/bin
/buffalo-enc \
146 -p
$(product
) -v
$(version
) $(args
) \
151 define Build
/buffalo-enc-tag
152 $(call Build
/buffalo-enc
,'' '' -S
152 $(1))
155 define Build
/buffalo-tag-dhp
156 $(eval product
=$(word 1,$(1)))
157 $(eval region
=$(word 2,$(1)))
158 $(eval language
=$(word 3,$(1)))
159 $(STAGING_DIR_HOST
)/bin
/buffalo-tag \
161 -a
$(BUFFALO_TAG_PLATFORM
) \
162 -v
$(BUFFALO_TAG_VERSION
) -m
$(BUFFALO_TAG_MINOR
) \
163 -b
$(product
) -p
$(product
) \
164 -r
$(region
) -r
$(region
) -l
$(language
) \
169 define Build
/check-size
170 @imagesize
="$$(stat -c%s $@)"; \
171 limitsize
="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
172 [ $$limitsize -ge
$$imagesize ] ||
{ \
173 echo
"WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
178 define Build
/elecom-product-header
179 $(eval product
=$(word 1,$(1)))
180 $(eval fw
=$(if
$(word 2,$(1)),$(word 2,$(1)),$@
))
183 echo
-n
-e
"ELECOM\x00\x00$(product)" | dd bs
=40 count
=1 conv
=sync
; \
184 echo
-n
"0.00" | dd bs
=16 count
=1 conv
=sync
; \
190 define Build
/elecom-wrc-gs-factory
191 $(eval product
=$(word 1,$(1)))
192 $(eval version
=$(word 2,$(1)))
193 $(eval hash_opt
=$(word 3,$(1)))
194 $(MKHASH
) md5
$(hash_opt
) $@
>> $@
196 echo
-n
"ELECOM $(product) v$(version)" | \
197 dd bs
=32 count
=1 conv
=sync
; \
203 define Build
/elx-header
204 $(eval hw_id
=$(word 1,$(1)))
205 $(eval xor_pattern
=$(word 2,$(1)))
207 echo
-ne
"\x00\x00\x00\x00\x00\x00\x00\x03" | \
208 dd bs
=42 count
=1 conv
=sync
; \
210 echo
-ne
"\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
211 dd bs
=20 count
=1 conv
=sync
; \
212 echo
-ne
"$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
213 dd bs
=8 count
=1 conv
=sync
; \
214 echo
-ne
"$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
215 dd bs
=58 count
=1 conv
=sync
; \
216 ) > $(KDIR
)/tmp
/$(DEVICE_NAME
).header
217 $(call Build
/xor-image
,-p
$(xor_pattern
) -x
)
218 cat
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
$@
> $@.new
220 rm -rf
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
223 define Build
/eva-image
224 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
228 define Build
/initrd_compression
229 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2
),.bzip2
) \
230 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP
),.gzip
) \
231 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA
),.lzma
) \
232 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ
),.xz
) \
233 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD
),.zstd
)
237 $(TOPDIR
)/scripts
/mkits.sh \
238 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
239 -C
$(word 1,$(1)) $(if
$(word 2,$(1)),\
240 $(if
$(DEVICE_DTS_OVERLAY
),-d
$(KERNEL_BUILD_DIR
)/image-
$$(basename $(word 2,$(1))),\
241 -d
$(word 2,$(1)))) \
242 $(if
$(findstring with-rootfs
,$(word 3,$(1))),-r
$(IMAGE_ROOTFS
)) \
243 $(if
$(findstring with-initrd
,$(word 3,$(1))), \
244 $(if
$(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE
), \
245 -i
$(KERNEL_BUILD_DIR
)/initrd.cpio
$(strip $(call Build
/initrd_compression
)))) \
246 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
247 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
248 $(if
$(DEVICE_DTS_DELIMITER
),-l
$(DEVICE_DTS_DELIMITER
)) \
249 $(if
$(DEVICE_DTS_OVERLAY
),$(foreach dtso
,$(DEVICE_DTS_OVERLAY
), -O
$(dtso
):$(KERNEL_BUILD_DIR
)/image-
$(dtso
).dtb
)) \
250 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config-1") \
251 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
252 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
$(if
$(findstring external
,$(word 3,$(1))),\
253 -E
-B
0x1000 $(if
$(findstring static
,$(word 3,$(1))),-p
0x1000)) -f
$@.its
$@.new
258 gzip
-f
-9n
-c
$@
$(1) > $@.new
262 define Build
/install-dtb
264 $(foreach dts
,$(DEVICE_DTS
), \
266 $(DTS_DIR
)/$(dts
).dtb \
267 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
269 install-dtb-
$(IMG_PREFIX
) \
274 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
275 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
276 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
277 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
278 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
279 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
281 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
282 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
283 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
284 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
288 define Build
/kernel2minor
289 $(eval temp_file
:= $(shell mktemp
))
291 kernel2minor
-k
$(temp_file
) -r
$(temp_file
).new
$(1)
292 mv
$(temp_file
).new
$@
296 define Build
/kernel-bin
301 define Build
/linksys-image
302 $(TOPDIR
)/scripts
/linksys-image.sh \
303 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
309 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
312 define Build
/lzma-no-dict
313 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
317 define Build
/netgear-chk
318 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
321 -b
$(NETGEAR_BOARD_ID
) \
322 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
326 define Build
/netgear-dni
327 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
328 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
329 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
335 define Build
/openmesh-image
336 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
337 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
339 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
340 "$(call param_get_default,rootfs,$(1),$@)"
341 $(TOPDIR
)/scripts
/combined-ext-image.sh \
342 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
343 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
344 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
345 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
348 define Build
/pad-extra
349 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
352 define Build
/pad-offset
354 size
="$$(stat -c%s $@)" \
355 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
356 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
357 pad
="(pad - ((size + offset) % pad)) % pad" \
358 newsize
='size + pad'; \
359 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
363 define Build
/pad-rootfs
364 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
365 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
369 $(call Image
/pad-to
,$@
,$(1))
372 define Build
/patch-cmdline
373 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
376 # Convert a raw image into a $1 type image.
377 # E.g. | qemu-image vdi
378 define Build
/qemu-image
379 if command
-v qemu-img
; then \
380 qemu-img convert
-f raw
-O
$1 $@
$@.new
; \
383 echo
"WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit
1; \
387 define Build
/qsdk-ipq-factory-nand
388 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
390 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
394 define Build
/qsdk-ipq-factory-nor
395 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
396 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
397 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
402 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
403 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
407 define Build
/seama-seal
408 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
409 -m
"signature=$(SEAMA_SIGNATURE)"
413 define Build
/senao-header
414 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
418 define Build
/sysupgrade-tar
419 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
420 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
421 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
422 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
426 define Build
/tplink-safeloader
427 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
428 -B
$(TPLINK_BOARD_ID
) \
434 $(wordlist
2,$(words $(1)),$(1)) \
435 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
438 define Build
/tplink-v1-header
439 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
440 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
441 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
442 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
447 # combine kernel and rootfs into one image
448 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
449 # <type> is "sysupgrade" or "factory"
451 # -a align the rootfs start on an <align> bytes boundary
452 # -j add jffs2 end-of-filesystem markers
453 # -s strip padding from end of the image
454 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
455 define Build
/tplink-v1-image
456 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
457 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
458 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
459 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
460 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
461 $(wordlist
2,$(words $(1)),$(1)) \
462 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
465 define Build
/tplink-v2-header
466 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
467 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
468 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
469 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
470 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
475 define Build
/tplink-v2-image
476 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
477 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
478 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
479 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
480 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
491 -a
$(KERNEL_LOADADDR
) \
492 -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
493 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
494 $(if
$(UIMAGE_MAGIC
),-M
$(UIMAGE_MAGIC
)) \
495 $(wordlist
2,$(words $(1)),$(1)) \
500 define Build
/xor-image
501 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
510 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
511 $@
$@.tmp
/$(if
$(1),$(1),$@
)
515 define Build
/zyxel-ras-image
517 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
518 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
524 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \