1 # Build commands that can be called from Device/* templates
3 IMAGE_KERNEL
= $(word 1,$^
)
4 IMAGE_ROOTFS
= $(word 2,$^
)
7 $(patsubst %-256k
,0x40000,$(patsubst %-128k
,0x20000,$(patsubst %-64k
,0x10000,$(patsubst squashfs
%,0x4,$(patsubst root.
%,%,$(1))))))
11 define Build
/append-dtb
12 cat
$(KDIR
)/image-
$(firstword $(DEVICE_DTS
)).dtb
>> $@
15 define Build
/append-dtb-elf
16 $(TARGET_CROSS
)objcopy \
17 --set-section-flags
=.appended_dtb
=alloc
,contents \
19 .appended_dtb
=$(KDIR
)/image-
$(firstword $(DEVICE_DTS
)).dtb
$@
22 define Build
/append-kernel
23 dd if
=$(IMAGE_KERNEL
) >> $@
26 compat_version
=$(if
$(DEVICE_COMPAT_VERSION
),$(DEVICE_COMPAT_VERSION
),1.0)
27 json_quote
=$(subst ','\'',$(subst ",\",$(1)))
30 legacy_supported_message
=$(SUPPORTED_DEVICES
) - Image version mismatch
: image
$(compat_version
), \
31 device
1.0. Please wipe config during upgrade
(force required
) or reinstall. \
32 $(if
$(DEVICE_COMPAT_MESSAGE
),Reason
: $(DEVICE_COMPAT_MESSAGE
),Please
check documentation ...
)
34 metadata_devices
=$(if
$(1),$(subst "$(space)","$(comma)",$(strip $(foreach v
,$(1),"$(call json_quote,$(v))"))))
36 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
37 "metadata_version": "1.1", \
38 "compat_version": "$(call json_quote,$(compat_version))", \
39 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
40 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
41 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
42 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
43 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
45 "dist": "$(call json_quote,$(VERSION_DIST))", \
46 "version": "$(call json_quote,$(VERSION_NUMBER))", \
47 "revision": "$(call json_quote,$(REVISION))", \
48 "target": "$(call json_quote,$(TARGETID))", \
49 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
53 define Build
/append-metadata
54 $(if
$(SUPPORTED_DEVICES
),-echo
$(call metadata_json
) | fwtool
-I
- $@
)
55 [ ! -s
"$(BUILD_KEY)" -o
! -s
"$(BUILD_KEY).ucert" -o
! -s
"$@" ] ||
{ \
56 cp
"$(BUILD_KEY).ucert" "$@.ucert" ;\
57 usign
-S
-m
"$@" -s
"$(BUILD_KEY)" -x
"$@.sig" ;\
58 ucert
-A
-c
"$@.ucert" -x
"$@.sig" ;\
59 fwtool
-S
"$@.ucert" "$@" ;\
63 define Build
/append-rootfs
64 dd if
=$(IMAGE_ROOTFS
) >> $@
67 define Build
/append-squashfs-fakeroot-be
68 rm -rf
$@.fakefs
$@.fakesquashfs
70 $(STAGING_DIR_HOST
)/bin
/mksquashfs-lzma \
71 $@.fakefs
$@.fakesquashfs \
72 -noappend
-root-owned
-be
-nopad
-b
65536 \
73 $(if
$(SOURCE_DATE_EPOCH
),-fixed-time
$(SOURCE_DATE_EPOCH
))
74 cat
$@.fakesquashfs
>> $@
77 define Build
/append-string
81 define Build
/append-ubi
82 sh
$(TOPDIR
)/scripts
/ubinize-image.sh \
83 $(if
$(UBOOTENV_IN_UBI
),--uboot-env
) \
84 $(if
$(KERNEL_IN_UBI
),--kernel
$(IMAGE_KERNEL
)) \
85 $(foreach part
,$(UBINIZE_PARTS
),--part
$(part
)) \
88 -p
$(BLOCKSIZE
:%k
=%KiB
) -m
$(PAGESIZE
) \
89 $(if
$(SUBPAGESIZE
),-s
$(SUBPAGESIZE
)) \
90 $(if
$(VID_HDR_OFFSET
),-O
$(VID_HDR_OFFSET
)) \
96 define Build
/append-uboot
97 dd if
=$(UBOOT_PATH
) >> $@
100 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
102 define Build
/append-uImage-fakehdr
103 $(eval type
=$(word 1,$(1)))
104 $(eval magic
=$(word 2,$(1)))
106 $(STAGING_DIR_HOST
)/bin
/mkimage \
107 -A
$(LINUX_KARCH
) -O linux
-T
$(type
) -C none \
108 -n
'$(VERSION_DIST) fake $(type)' \
109 $(if
$(magic
),-M
$(magic
)) \
116 define Build
/buffalo-dhp-image
117 $(STAGING_DIR_HOST
)/bin
/mkdhpimg
$@
$@.new
121 define Build
/buffalo-enc
122 $(eval product
=$(word 1,$(1)))
123 $(eval version
=$(word 2,$(1)))
124 $(eval args
=$(wordlist
3,$(words $(1)),$(1)))
125 $(STAGING_DIR_HOST
)/bin
/buffalo-enc \
126 -p
$(product
) -v
$(version
) $(args
) \
131 define Build
/buffalo-enc-tag
132 $(call Build
/buffalo-enc
,'' '' -S
152 $(1))
135 define Build
/buffalo-tag-dhp
136 $(eval product
=$(word 1,$(1)))
137 $(eval region
=$(word 2,$(1)))
138 $(eval language
=$(word 3,$(1)))
139 $(STAGING_DIR_HOST
)/bin
/buffalo-tag \
141 -a
$(BUFFALO_TAG_PLATFORM
) \
142 -v
$(BUFFALO_TAG_VERSION
) -m
$(BUFFALO_TAG_MINOR
) \
143 -b
$(product
) -p
$(product
) \
144 -r
$(region
) -r
$(region
) -l
$(language
) \
149 define Build
/check-size
150 @imagesize
="$$(stat -c%s $@)"; \
151 limitsize
="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
152 [ $$limitsize -ge
$$imagesize ] ||
{ \
153 echo
"WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
158 define Build
/eva-image
159 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
164 $(TOPDIR
)/scripts
/mkits.sh \
165 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
166 $(if
$(word 2,$(1)),-d
$(word 2,$(1))) -C
$(word 1,$(1)) \
167 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
168 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
169 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config@1") \
170 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
171 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
176 gzip
-f
-9n
-c
$@
$(1) > $@.new
180 define Build
/install-dtb
182 $(foreach dts
,$(DEVICE_DTS
), \
184 $(DTS_DIR
)/$(dts
).dtb \
185 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
187 install-dtb-
$(IMG_PREFIX
) \
192 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
193 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
194 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
195 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
196 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
197 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
199 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
200 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
201 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
202 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
206 define Build
/kernel2minor
207 kernel2minor
-k
$@
-r
$@.new
$(1)
211 define Build
/kernel-bin
216 define Build
/linksys-image
217 $(TOPDIR
)/scripts
/linksys-image.sh \
218 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
224 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
227 define Build
/lzma-no-dict
228 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
232 define Build
/netgear-chk
233 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
236 -b
$(NETGEAR_BOARD_ID
) \
237 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
241 define Build
/netgear-dni
242 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
243 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
244 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
250 define Build
/openmesh-image
251 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
252 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
254 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
255 "$(call param_get_default,rootfs,$(1),$@)"
256 $(TOPDIR
)/scripts
/combined-ext-image.sh \
257 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
258 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
259 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
260 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
263 define Build
/pad-extra
264 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
267 define Build
/pad-offset
269 size
="$$(stat -c%s $@)" \
270 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
271 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
272 pad
="(pad - ((size + offset) % pad)) % pad" \
273 newsize
='size + pad'; \
274 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
278 define Build
/pad-rootfs
279 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
280 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
284 $(call Image
/pad-to
,$@
,$(1))
287 define Build
/patch-cmdline
288 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
291 # Convert a raw image into a $1 type image.
292 # E.g. | qemu-image vdi
293 define Build
/qemu-image
294 qemu-img convert
-f raw
-O
$1 $@
$@.new
298 define Build
/qsdk-ipq-factory-nand
299 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
301 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
305 define Build
/qsdk-ipq-factory-nor
306 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
307 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
308 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
313 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
314 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
318 define Build
/seama-seal
319 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
320 -m
"signature=$(SEAMA_SIGNATURE)"
324 define Build
/senao-header
325 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
329 define Build
/sysupgrade-tar
330 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
331 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
332 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
333 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
337 define Build
/tplink-safeloader
338 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
339 -B
$(TPLINK_BOARD_ID
) \
345 $(wordlist
2,$(words $(1)),$(1)) \
346 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
349 define Build
/tplink-v1-header
350 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
351 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
352 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
353 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
358 # combine kernel and rootfs into one image
359 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
360 # <type> is "sysupgrade" or "factory"
362 # -a align the rootfs start on an <align> bytes boundary
363 # -j add jffs2 end-of-filesystem markers
364 # -s strip padding from end of the image
365 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
366 define Build
/tplink-v1-image
367 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
368 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
369 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
370 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
371 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
372 $(wordlist
2,$(words $(1)),$(1)) \
373 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
376 define Build
/tplink-v2-header
377 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
378 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
379 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
380 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
381 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
386 define Build
/tplink-v2-image
387 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
388 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
389 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
390 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
391 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
402 -a
$(KERNEL_LOADADDR
) \
403 -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
404 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
405 $(wordlist
2,$(words $(1)),$(1)) \
410 define Build
/xor-image
411 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
420 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
421 $@
$@.tmp
/$(if
$(1),$(1),$@
)
425 define Build
/zyxel-ras-image
427 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
428 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
434 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \