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
/elx-header
191 $(eval hw_id
=$(word 1,$(1)))
192 $(eval xor_pattern
=$(word 2,$(1)))
194 echo
-ne
"\x00\x00\x00\x00\x00\x00\x00\x03" | \
195 dd bs
=42 count
=1 conv
=sync
; \
197 echo
-ne
"\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
198 dd bs
=20 count
=1 conv
=sync
; \
199 echo
-ne
"$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
200 dd bs
=8 count
=1 conv
=sync
; \
201 echo
-ne
"$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
202 dd bs
=58 count
=1 conv
=sync
; \
203 ) > $(KDIR
)/tmp
/$(DEVICE_NAME
).header
204 $(call Build
/xor-image
,-p
$(xor_pattern
) -x
)
205 cat
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
$@
> $@.new
207 rm -rf
$(KDIR
)/tmp
/$(DEVICE_NAME
).header
210 define Build
/eva-image
211 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
215 define Build
/initrd_compression
216 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2
),.bzip2
) \
217 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP
),.gzip
) \
218 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA
),.lzma
) \
219 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ
),.xz
) \
220 $(if
$(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD
),.zstd
)
224 $(TOPDIR
)/scripts
/mkits.sh \
225 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
226 -C
$(word 1,$(1)) $(if
$(word 2,$(1)),\
227 $(if
$(DEVICE_DTS_OVERLAY
),-d
$(KERNEL_BUILD_DIR
)/image-
$$(basename $(word 2,$(1))),\
228 -d
$(word 2,$(1)))) \
229 $(if
$(findstring with-rootfs
,$(word 3,$(1))),-r
$(IMAGE_ROOTFS
)) \
230 $(if
$(findstring with-initrd
,$(word 3,$(1))), \
231 $(if
$(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE
), \
232 -i
$(KERNEL_BUILD_DIR
)/initrd.cpio
$(strip $(call Build
/initrd_compression
)))) \
233 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
234 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
235 $(if
$(DEVICE_DTS_OVERLAY
),$(foreach dtso
,$(DEVICE_DTS_OVERLAY
), -O
$(dtso
):$(KERNEL_BUILD_DIR
)/image-
$(dtso
).dtb
)) \
236 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config-1") \
237 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
238 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
$(if
$(findstring external
,$(word 3,$(1))),\
239 -E
-B
0x1000 $(if
$(findstring static
,$(word 3,$(1))),-p
0x1000)) -f
$@.its
$@.new
244 gzip
-f
-9n
-c
$@
$(1) > $@.new
248 define Build
/install-dtb
250 $(foreach dts
,$(DEVICE_DTS
), \
252 $(DTS_DIR
)/$(dts
).dtb \
253 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
255 install-dtb-
$(IMG_PREFIX
) \
260 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
261 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
262 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
263 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
264 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
265 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
267 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
268 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
269 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
270 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
274 define Build
/kernel2minor
275 $(eval temp_file
:= $(shell mktemp
))
277 kernel2minor
-k
$(temp_file
) -r
$(temp_file
).new
$(1)
278 mv
$(temp_file
).new
$@
282 define Build
/kernel-bin
287 define Build
/linksys-image
288 $(TOPDIR
)/scripts
/linksys-image.sh \
289 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
295 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
298 define Build
/lzma-no-dict
299 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
303 define Build
/netgear-chk
304 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
307 -b
$(NETGEAR_BOARD_ID
) \
308 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
312 define Build
/netgear-dni
313 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
314 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
315 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
321 define Build
/openmesh-image
322 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
323 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
325 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
326 "$(call param_get_default,rootfs,$(1),$@)"
327 $(TOPDIR
)/scripts
/combined-ext-image.sh \
328 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
329 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
330 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
331 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
334 define Build
/pad-extra
335 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
338 define Build
/pad-offset
340 size
="$$(stat -c%s $@)" \
341 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
342 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
343 pad
="(pad - ((size + offset) % pad)) % pad" \
344 newsize
='size + pad'; \
345 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
349 define Build
/pad-rootfs
350 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
351 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
355 $(call Image
/pad-to
,$@
,$(1))
358 define Build
/patch-cmdline
359 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
362 # Convert a raw image into a $1 type image.
363 # E.g. | qemu-image vdi
364 define Build
/qemu-image
365 if command
-v qemu-img
; then \
366 qemu-img convert
-f raw
-O
$1 $@
$@.new
; \
369 echo
"WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit
1; \
373 define Build
/qsdk-ipq-factory-nand
374 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
376 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
380 define Build
/qsdk-ipq-factory-nor
381 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
382 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
383 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
388 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
389 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
393 define Build
/seama-seal
394 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
395 -m
"signature=$(SEAMA_SIGNATURE)"
399 define Build
/senao-header
400 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
404 define Build
/sysupgrade-tar
405 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
406 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
407 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
408 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
412 define Build
/tplink-safeloader
413 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
414 -B
$(TPLINK_BOARD_ID
) \
420 $(wordlist
2,$(words $(1)),$(1)) \
421 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
424 define Build
/tplink-v1-header
425 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
426 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
427 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
428 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
433 # combine kernel and rootfs into one image
434 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
435 # <type> is "sysupgrade" or "factory"
437 # -a align the rootfs start on an <align> bytes boundary
438 # -j add jffs2 end-of-filesystem markers
439 # -s strip padding from end of the image
440 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
441 define Build
/tplink-v1-image
442 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
443 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
444 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
445 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
446 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
447 $(wordlist
2,$(words $(1)),$(1)) \
448 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
451 define Build
/tplink-v2-header
452 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
453 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
454 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
455 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
456 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
461 define Build
/tplink-v2-image
462 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
463 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
464 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
465 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
466 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
477 -a
$(KERNEL_LOADADDR
) \
478 -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
479 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
480 $(if
$(UIMAGE_MAGIC
),-M
$(UIMAGE_MAGIC
)) \
481 $(wordlist
2,$(words $(1)),$(1)) \
486 define Build
/xor-image
487 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
496 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
497 $@
$@.tmp
/$(if
$(1),$(1),$@
)
501 define Build
/zyxel-ras-image
503 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
504 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
510 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \