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) >> $@
34 compat_version
=$(if
$(DEVICE_COMPAT_VERSION
),$(DEVICE_COMPAT_VERSION
),1.0)
35 json_quote
=$(subst ','\'',$(subst ",\",$(1)))
38 legacy_supported_message
=$(SUPPORTED_DEVICES
) - Image version mismatch
: image
$(compat_version
), \
39 device
1.0. Please wipe config during upgrade
(force required
) or reinstall. \
40 $(if
$(DEVICE_COMPAT_MESSAGE
),Reason
: $(DEVICE_COMPAT_MESSAGE
),Please
check documentation ...
)
42 metadata_devices
=$(if
$(1),$(subst "$(space)","$(comma)",$(strip $(foreach v
,$(1),"$(call json_quote,$(v))"))))
44 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
45 "metadata_version": "1.1", \
46 "compat_version": "$(call json_quote,$(compat_version))", \
47 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
48 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
49 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
50 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
51 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
53 "dist": "$(call json_quote,$(VERSION_DIST))", \
54 "version": "$(call json_quote,$(VERSION_NUMBER))", \
55 "revision": "$(call json_quote,$(REVISION))", \
56 "target": "$(call json_quote,$(TARGETID))", \
57 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
61 define Build
/append-metadata
62 $(if
$(SUPPORTED_DEVICES
),-echo
$(call metadata_json
) | fwtool
-I
- $@
)
63 [ ! -s
"$(BUILD_KEY)" -o
! -s
"$(BUILD_KEY).ucert" -o
! -s
"$@" ] ||
{ \
64 cp
"$(BUILD_KEY).ucert" "$@.ucert" ;\
65 usign
-S
-m
"$@" -s
"$(BUILD_KEY)" -x
"$@.sig" ;\
66 ucert
-A
-c
"$@.ucert" -x
"$@.sig" ;\
67 fwtool
-S
"$@.ucert" "$@" ;\
71 define Build
/append-rootfs
72 dd if
=$(IMAGE_ROOTFS
) >> $@
75 define Build
/append-squashfs-fakeroot-be
76 rm -rf
$@.fakefs
$@.fakesquashfs
78 $(STAGING_DIR_HOST
)/bin
/mksquashfs-lzma \
79 $@.fakefs
$@.fakesquashfs \
80 -noappend
-root-owned
-be
-nopad
-b
65536 \
81 $(if
$(SOURCE_DATE_EPOCH
),-fixed-time
$(SOURCE_DATE_EPOCH
))
82 cat
$@.fakesquashfs
>> $@
85 define Build
/append-string
89 define Build
/append-ubi
90 sh
$(TOPDIR
)/scripts
/ubinize-image.sh \
91 $(if
$(UBOOTENV_IN_UBI
),--uboot-env
) \
92 $(if
$(KERNEL_IN_UBI
),--kernel
$(IMAGE_KERNEL
)) \
93 $(foreach part
,$(UBINIZE_PARTS
),--part
$(part
)) \
96 -p
$(BLOCKSIZE
:%k
=%KiB
) -m
$(PAGESIZE
) \
97 $(if
$(SUBPAGESIZE
),-s
$(SUBPAGESIZE
)) \
98 $(if
$(VID_HDR_OFFSET
),-O
$(VID_HDR_OFFSET
)) \
104 define Build
/append-uboot
105 dd if
=$(UBOOT_PATH
) >> $@
108 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
110 define Build
/append-uImage-fakehdr
111 $(eval type
=$(word 1,$(1)))
112 $(eval magic
=$(word 2,$(1)))
114 $(STAGING_DIR_HOST
)/bin
/mkimage \
115 -A
$(LINUX_KARCH
) -O linux
-T
$(type
) -C none \
116 -n
'$(VERSION_DIST) fake $(type)' \
117 $(if
$(magic
),-M
$(magic
)) \
124 define Build
/buffalo-dhp-image
125 $(STAGING_DIR_HOST
)/bin
/mkdhpimg
$@
$@.new
129 define Build
/buffalo-enc
130 $(eval product
=$(word 1,$(1)))
131 $(eval version
=$(word 2,$(1)))
132 $(eval args
=$(wordlist
3,$(words $(1)),$(1)))
133 $(STAGING_DIR_HOST
)/bin
/buffalo-enc \
134 -p
$(product
) -v
$(version
) $(args
) \
139 define Build
/buffalo-enc-tag
140 $(call Build
/buffalo-enc
,'' '' -S
152 $(1))
143 define Build
/buffalo-tag-dhp
144 $(eval product
=$(word 1,$(1)))
145 $(eval region
=$(word 2,$(1)))
146 $(eval language
=$(word 3,$(1)))
147 $(STAGING_DIR_HOST
)/bin
/buffalo-tag \
149 -a
$(BUFFALO_TAG_PLATFORM
) \
150 -v
$(BUFFALO_TAG_VERSION
) -m
$(BUFFALO_TAG_MINOR
) \
151 -b
$(product
) -p
$(product
) \
152 -r
$(region
) -r
$(region
) -l
$(language
) \
157 define Build
/check-size
158 @imagesize
="$$(stat -c%s $@)"; \
159 limitsize
="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
160 [ $$limitsize -ge
$$imagesize ] ||
{ \
161 echo
"WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
166 define Build
/elecom-product-header
167 $(eval product
=$(word 1,$(1)))
168 $(eval fw
=$(if
$(word 2,$(1)),$(word 2,$(1)),$@
))
171 echo
-n
-e
"ELECOM\x00\x00$(product)" | dd bs
=40 count
=1 conv
=sync
; \
172 echo
-n
"0.00" | dd bs
=16 count
=1 conv
=sync
; \
178 define Build
/elx-header
179 $(eval hw_id
=$(word 1,$(1)))
180 $(eval xor_pattern
=$(word 2,$(1)))
182 echo
-ne
"\x00\x00\x00\x00\x00\x00\x00\x03" | \
183 dd bs
=42 count
=1 conv
=sync
; \
185 echo
-ne
"\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
186 dd bs
=20 count
=1 conv
=sync
; \
187 echo
-ne
"$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
188 dd bs
=8 count
=1 conv
=sync
; \
189 echo
-ne
"$$($(STAGING_DIR_HOST)/bin/mkhash md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
190 dd bs
=58 count
=1 conv
=sync
; \
191 ) > $(KDIR
)/tmp
/$(DEVICE_NAME
).header
192 $(call Build
/xor-image
,-p
$(xor_pattern
) -x
)
193 cat
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
$@
> $@.new
195 rm -rf
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
198 define Build
/eva-image
199 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
203 define Build
/initrd_compression
204 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2
),.bzip2
) \
205 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP
),.gzip
) \
206 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA
),.lzma
) \
207 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ
),.xz
) \
208 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD
),.zstd
)
212 $(TOPDIR
)/scripts
/mkits.sh \
213 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
214 -C
$(word 1,$(1)) $(if
$(word 2,$(1)),\
215 $(if
$(DEVICE_DTS_OVERLAY
),-d
$(KERNEL_BUILD_DIR
)/image-
$$(basename $(word 2,$(1))),\
216 -d
$(word 2,$(1)))) \
217 $(if
$(findstring with-rootfs
,$(word 3,$(1))),-r
$(IMAGE_ROOTFS
)) \
218 $(if
$(findstring with-initrd
,$(word 3,$(1))), \
219 $(if
$(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE
), \
220 -i
$(KERNEL_BUILD_DIR
)/initrd.cpio
$(strip $(call Build
/initrd_compression
)))) \
221 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
222 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
223 $(if
$(DEVICE_DTS_OVERLAY
),$(foreach dtso
,$(DEVICE_DTS_OVERLAY
), -O
$(dtso
):$(KERNEL_BUILD_DIR
)/image-
$(dtso
).dtb
)) \
224 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config-1") \
225 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
226 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
$(if
$(findstring external
,$(word 3,$(1))),\
227 -E
-B
0x1000 $(if
$(findstring static
,$(word 3,$(1))),-p
0x1000)) -f
$@.its
$@.new
232 gzip
-f
-9n
-c
$@
$(1) > $@.new
236 define Build
/install-dtb
238 $(foreach dts
,$(DEVICE_DTS
), \
240 $(DTS_DIR
)/$(dts
).dtb \
241 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
243 install-dtb-
$(IMG_PREFIX
) \
248 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
249 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
250 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
251 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
252 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
253 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
255 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
256 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
257 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
258 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
262 define Build
/kernel2minor
263 kernel2minor
-k
$@
-r
$@.new
$(1)
267 define Build
/kernel-bin
272 define Build
/linksys-image
273 $(TOPDIR
)/scripts
/linksys-image.sh \
274 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
280 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
283 define Build
/lzma-no-dict
284 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
288 define Build
/netgear-chk
289 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
292 -b
$(NETGEAR_BOARD_ID
) \
293 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
297 define Build
/netgear-dni
298 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
299 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
300 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
306 define Build
/openmesh-image
307 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
308 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
310 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
311 "$(call param_get_default,rootfs,$(1),$@)"
312 $(TOPDIR
)/scripts
/combined-ext-image.sh \
313 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
314 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
315 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
316 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
319 define Build
/pad-extra
320 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
323 define Build
/pad-offset
325 size
="$$(stat -c%s $@)" \
326 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
327 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
328 pad
="(pad - ((size + offset) % pad)) % pad" \
329 newsize
='size + pad'; \
330 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
334 define Build
/pad-rootfs
335 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
336 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
340 $(call Image
/pad-to
,$@
,$(1))
343 define Build
/patch-cmdline
344 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
347 # Convert a raw image into a $1 type image.
348 # E.g. | qemu-image vdi
349 define Build
/qemu-image
350 if command
-v qemu-img
; then \
351 qemu-img convert
-f raw
-O
$1 $@
$@.new
; \
354 echo
"WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit
1; \
358 define Build
/qsdk-ipq-factory-nand
359 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
361 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
365 define Build
/qsdk-ipq-factory-nor
366 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
367 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
368 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
373 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
374 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
378 define Build
/seama-seal
379 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
380 -m
"signature=$(SEAMA_SIGNATURE)"
384 define Build
/senao-header
385 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
389 define Build
/sysupgrade-tar
390 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
391 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
392 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
393 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
397 define Build
/tplink-safeloader
398 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
399 -B
$(TPLINK_BOARD_ID
) \
405 $(wordlist
2,$(words $(1)),$(1)) \
406 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
409 define Build
/tplink-v1-header
410 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
411 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
412 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
413 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
418 # combine kernel and rootfs into one image
419 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
420 # <type> is "sysupgrade" or "factory"
422 # -a align the rootfs start on an <align> bytes boundary
423 # -j add jffs2 end-of-filesystem markers
424 # -s strip padding from end of the image
425 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
426 define Build
/tplink-v1-image
427 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
428 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
429 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
430 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
431 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
432 $(wordlist
2,$(words $(1)),$(1)) \
433 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
436 define Build
/tplink-v2-header
437 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
438 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
439 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
440 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
441 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
446 define Build
/tplink-v2-image
447 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
448 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
449 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
450 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
451 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
462 -a
$(KERNEL_LOADADDR
) \
463 -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
464 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
465 $(if
$(UIMAGE_MAGIC
),-M
$(UIMAGE_MAGIC
)) \
466 $(wordlist
2,$(words $(1)),$(1)) \
471 define Build
/xor-image
472 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
481 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
482 $@
$@.tmp
/$(if
$(1),$(1),$@
)
486 define Build
/zyxel-ras-image
488 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
489 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
495 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \