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 compat_version
=$(if
$(DEVICE_COMPAT_VERSION
),$(DEVICE_COMPAT_VERSION
),1.0)
31 json_quote
=$(subst ','\'',$(subst ",\",$(1)))
34 legacy_supported_message
=$(SUPPORTED_DEVICES
) - Image version mismatch
: image
$(compat_version
), \
35 device
1.0. Please wipe config during upgrade
(force required
) or reinstall. \
36 $(if
$(DEVICE_COMPAT_MESSAGE
),Reason
: $(DEVICE_COMPAT_MESSAGE
),Please
check documentation ...
)
38 metadata_devices
=$(if
$(1),$(subst "$(space)","$(comma)",$(strip $(foreach v
,$(1),"$(call json_quote,$(v))"))))
40 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
41 "metadata_version": "1.1", \
42 "compat_version": "$(call json_quote,$(compat_version))", \
43 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
44 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
45 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
46 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
47 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
49 "dist": "$(call json_quote,$(VERSION_DIST))", \
50 "version": "$(call json_quote,$(VERSION_NUMBER))", \
51 "revision": "$(call json_quote,$(REVISION))", \
52 "target": "$(call json_quote,$(TARGETID))", \
53 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
57 define Build
/append-metadata
58 $(if
$(SUPPORTED_DEVICES
),-echo
$(call metadata_json
) | fwtool
-I
- $@
)
59 [ ! -s
"$(BUILD_KEY)" -o
! -s
"$(BUILD_KEY).ucert" -o
! -s
"$@" ] ||
{ \
60 cp
"$(BUILD_KEY).ucert" "$@.ucert" ;\
61 usign
-S
-m
"$@" -s
"$(BUILD_KEY)" -x
"$@.sig" ;\
62 ucert
-A
-c
"$@.ucert" -x
"$@.sig" ;\
63 fwtool
-S
"$@.ucert" "$@" ;\
67 define Build
/append-rootfs
68 dd if
=$(IMAGE_ROOTFS
) >> $@
71 define Build
/append-squashfs-fakeroot-be
72 rm -rf
$@.fakefs
$@.fakesquashfs
74 $(STAGING_DIR_HOST
)/bin
/mksquashfs-lzma \
75 $@.fakefs
$@.fakesquashfs \
76 -noappend
-root-owned
-be
-nopad
-b
65536 \
77 $(if
$(SOURCE_DATE_EPOCH
),-fixed-time
$(SOURCE_DATE_EPOCH
))
78 cat
$@.fakesquashfs
>> $@
81 define Build
/append-string
85 define Build
/append-ubi
86 sh
$(TOPDIR
)/scripts
/ubinize-image.sh \
87 $(if
$(UBOOTENV_IN_UBI
),--uboot-env
) \
88 $(if
$(KERNEL_IN_UBI
),--kernel
$(IMAGE_KERNEL
)) \
89 $(foreach part
,$(UBINIZE_PARTS
),--part
$(part
)) \
92 -p
$(BLOCKSIZE
:%k
=%KiB
) -m
$(PAGESIZE
) \
93 $(if
$(SUBPAGESIZE
),-s
$(SUBPAGESIZE
)) \
94 $(if
$(VID_HDR_OFFSET
),-O
$(VID_HDR_OFFSET
)) \
100 define Build
/append-uboot
101 dd if
=$(UBOOT_PATH
) >> $@
104 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
106 define Build
/append-uImage-fakehdr
107 $(eval type
=$(word 1,$(1)))
108 $(eval magic
=$(word 2,$(1)))
110 $(STAGING_DIR_HOST
)/bin
/mkimage \
111 -A
$(LINUX_KARCH
) -O linux
-T
$(type
) -C none \
112 -n
'$(VERSION_DIST) fake $(type)' \
113 $(if
$(magic
),-M
$(magic
)) \
120 define Build
/buffalo-dhp-image
121 $(STAGING_DIR_HOST
)/bin
/mkdhpimg
$@
$@.new
125 define Build
/buffalo-enc
126 $(eval product
=$(word 1,$(1)))
127 $(eval version
=$(word 2,$(1)))
128 $(eval args
=$(wordlist
3,$(words $(1)),$(1)))
129 $(STAGING_DIR_HOST
)/bin
/buffalo-enc \
130 -p
$(product
) -v
$(version
) $(args
) \
135 define Build
/buffalo-enc-tag
136 $(call Build
/buffalo-enc
,'' '' -S
152 $(1))
139 define Build
/buffalo-tag-dhp
140 $(eval product
=$(word 1,$(1)))
141 $(eval region
=$(word 2,$(1)))
142 $(eval language
=$(word 3,$(1)))
143 $(STAGING_DIR_HOST
)/bin
/buffalo-tag \
145 -a
$(BUFFALO_TAG_PLATFORM
) \
146 -v
$(BUFFALO_TAG_VERSION
) -m
$(BUFFALO_TAG_MINOR
) \
147 -b
$(product
) -p
$(product
) \
148 -r
$(region
) -r
$(region
) -l
$(language
) \
153 define Build
/check-size
154 @imagesize
="$$(stat -c%s $@)"; \
155 limitsize
="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
156 [ $$limitsize -ge
$$imagesize ] ||
{ \
157 echo
"WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
162 define Build
/elecom-product-header
163 $(eval product
=$(word 1,$(1)))
164 $(eval fw
=$(if
$(word 2,$(1)),$(word 2,$(1)),$@
))
167 echo
-n
-e
"ELECOM\x00\x00$(product)" | dd bs
=40 count
=1 conv
=sync
; \
168 echo
-n
"0.00" | dd bs
=16 count
=1 conv
=sync
; \
174 define Build
/elx-header
175 $(eval hw_id
=$(word 1,$(1)))
176 $(eval xor_pattern
=$(word 2,$(1)))
178 echo
-ne
"\x00\x00\x00\x00\x00\x00\x00\x03" | \
179 dd bs
=42 count
=1 conv
=sync
; \
181 echo
-ne
"\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
182 dd bs
=20 count
=1 conv
=sync
; \
183 echo
-ne
"$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
184 dd bs
=8 count
=1 conv
=sync
; \
185 echo
-ne
"$$($(STAGING_DIR_HOST)/bin/mkhash md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
186 dd bs
=58 count
=1 conv
=sync
; \
187 ) > $(KDIR
)/tmp
/$(DEVICE_NAME
).header
188 $(call Build
/xor-image
,-p
$(xor_pattern
) -x
)
189 cat
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
$@
> $@.new
191 rm -rf
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
194 define Build
/eva-image
195 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
199 define Build
/initrd_compression
200 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2
),.bzip2
) \
201 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP
),.gzip
) \
202 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA
),.lzma
) \
203 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ
),.xz
) \
204 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD
),.zstd
)
208 $(TOPDIR
)/scripts
/mkits.sh \
209 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
210 -C
$(word 1,$(1)) $(if
$(word 2,$(1)),\
211 $(if
$(DEVICE_DTS_OVERLAY
),-d
$(KERNEL_BUILD_DIR
)/image-
$$(basename $(word 2,$(1))),\
212 -d
$(word 2,$(1)))) \
213 $(if
$(findstring with-rootfs
,$(word 3,$(1))),-r
$(IMAGE_ROOTFS
)) \
214 $(if
$(findstring with-initrd
,$(word 3,$(1))), \
215 $(if
$(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE
), \
216 -i
$(KERNEL_BUILD_DIR
)/initrd.cpio
$(strip $(call Build
/initrd_compression
)))) \
217 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
218 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
219 $(if
$(DEVICE_DTS_OVERLAY
),$(foreach dtso
,$(DEVICE_DTS_OVERLAY
), -O
$(dtso
):$(KERNEL_BUILD_DIR
)/image-
$(dtso
).dtb
)) \
220 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config-1") \
221 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
222 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
$(if
$(findstring external
,$(word 3,$(1))),\
223 -E
-B
0x1000 $(if
$(findstring static
,$(word 3,$(1))),-p
0x1000)) -f
$@.its
$@.new
228 gzip
-f
-9n
-c
$@
$(1) > $@.new
232 define Build
/install-dtb
234 $(foreach dts
,$(DEVICE_DTS
), \
236 $(DTS_DIR
)/$(dts
).dtb \
237 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
239 install-dtb-
$(IMG_PREFIX
) \
244 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
245 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
246 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
247 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
248 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
249 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
251 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
252 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
253 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
254 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
258 define Build
/kernel2minor
259 kernel2minor
-k
$@
-r
$@.new
$(1)
263 define Build
/kernel-bin
268 define Build
/linksys-image
269 $(TOPDIR
)/scripts
/linksys-image.sh \
270 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
276 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
279 define Build
/lzma-no-dict
280 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
284 define Build
/netgear-chk
285 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
288 -b
$(NETGEAR_BOARD_ID
) \
289 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
293 define Build
/netgear-dni
294 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
295 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
296 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
302 define Build
/openmesh-image
303 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
304 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
306 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
307 "$(call param_get_default,rootfs,$(1),$@)"
308 $(TOPDIR
)/scripts
/combined-ext-image.sh \
309 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
310 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
311 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
312 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
315 define Build
/pad-extra
316 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
319 define Build
/pad-offset
321 size
="$$(stat -c%s $@)" \
322 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
323 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
324 pad
="(pad - ((size + offset) % pad)) % pad" \
325 newsize
='size + pad'; \
326 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
330 define Build
/pad-rootfs
331 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
332 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
336 $(call Image
/pad-to
,$@
,$(1))
339 define Build
/patch-cmdline
340 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
343 # Convert a raw image into a $1 type image.
344 # E.g. | qemu-image vdi
345 define Build
/qemu-image
346 if command
-v qemu-img
; then \
347 qemu-img convert
-f raw
-O
$1 $@
$@.new
; \
350 echo
"WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit
1; \
354 define Build
/qsdk-ipq-factory-nand
355 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
357 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
361 define Build
/qsdk-ipq-factory-nor
362 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
363 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
364 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
369 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
370 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
374 define Build
/seama-seal
375 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
376 -m
"signature=$(SEAMA_SIGNATURE)"
380 define Build
/senao-header
381 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
385 define Build
/sysupgrade-tar
386 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
387 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
388 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
389 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
393 define Build
/tplink-safeloader
394 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
395 -B
$(TPLINK_BOARD_ID
) \
401 $(wordlist
2,$(words $(1)),$(1)) \
402 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
405 define Build
/tplink-v1-header
406 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
407 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
408 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
409 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
414 # combine kernel and rootfs into one image
415 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
416 # <type> is "sysupgrade" or "factory"
418 # -a align the rootfs start on an <align> bytes boundary
419 # -j add jffs2 end-of-filesystem markers
420 # -s strip padding from end of the image
421 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
422 define Build
/tplink-v1-image
423 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
424 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
425 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
426 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
427 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
428 $(wordlist
2,$(words $(1)),$(1)) \
429 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
432 define Build
/tplink-v2-header
433 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
434 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
435 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
436 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
437 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
442 define Build
/tplink-v2-image
443 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
444 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
445 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
446 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
447 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
458 -a
$(KERNEL_LOADADDR
) \
459 -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
460 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
461 $(if
$(UIMAGE_MAGIC
),-M
$(UIMAGE_MAGIC
)) \
462 $(wordlist
2,$(words $(1)),$(1)) \
467 define Build
/xor-image
468 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
477 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
478 $@
$@.tmp
/$(if
$(1),$(1),$@
)
482 define Build
/zyxel-ras-image
484 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
485 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
491 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \