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
/elecom-product-header
159 $(eval product
=$(word 1,$(1)))
160 $(eval fw
=$(if
$(word 2,$(1)),$(word 2,$(1)),$@
))
163 echo
-n
-e
"ELECOM\x00\x00$(product)" | dd bs
=40 count
=1 conv
=sync
; \
164 echo
-n
"0.00" | dd bs
=16 count
=1 conv
=sync
; \
170 define Build
/eva-image
171 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
176 $(TOPDIR
)/scripts
/mkits.sh \
177 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
178 $(if
$(word 2,$(1)),-d
$(word 2,$(1))) -C
$(word 1,$(1)) \
179 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
180 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
181 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config@1") \
182 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
183 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
188 gzip
-f
-9n
-c
$@
$(1) > $@.new
192 define Build
/install-dtb
194 $(foreach dts
,$(DEVICE_DTS
), \
196 $(DTS_DIR
)/$(dts
).dtb \
197 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
199 install-dtb-
$(IMG_PREFIX
) \
204 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
205 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
206 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
207 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
208 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
209 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
211 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
212 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
213 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
214 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
218 define Build
/kernel2minor
219 kernel2minor
-k
$@
-r
$@.new
$(1)
223 define Build
/kernel-bin
228 define Build
/linksys-image
229 $(TOPDIR
)/scripts
/linksys-image.sh \
230 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
236 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
239 define Build
/lzma-no-dict
240 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
244 define Build
/netgear-chk
245 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
248 -b
$(NETGEAR_BOARD_ID
) \
249 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
253 define Build
/netgear-dni
254 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
255 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
256 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
262 define Build
/openmesh-image
263 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
264 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
266 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
267 "$(call param_get_default,rootfs,$(1),$@)"
268 $(TOPDIR
)/scripts
/combined-ext-image.sh \
269 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
270 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
271 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
272 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
275 define Build
/pad-extra
276 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
279 define Build
/pad-offset
281 size
="$$(stat -c%s $@)" \
282 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
283 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
284 pad
="(pad - ((size + offset) % pad)) % pad" \
285 newsize
='size + pad'; \
286 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
290 define Build
/pad-rootfs
291 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
292 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
296 $(call Image
/pad-to
,$@
,$(1))
299 define Build
/patch-cmdline
300 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
303 # Convert a raw image into a $1 type image.
304 # E.g. | qemu-image vdi
305 define Build
/qemu-image
306 if command
-v qemu-img
; then \
307 qemu-img convert
-f raw
-O
$1 $@
$@.new
; \
310 echo
"WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit
1; \
314 define Build
/qsdk-ipq-factory-nand
315 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
317 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
321 define Build
/qsdk-ipq-factory-nor
322 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
323 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
324 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
329 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
330 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
334 define Build
/seama-seal
335 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
336 -m
"signature=$(SEAMA_SIGNATURE)"
340 define Build
/senao-header
341 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
345 define Build
/sysupgrade-tar
346 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
347 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
348 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
349 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
353 define Build
/tplink-safeloader
354 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
355 -B
$(TPLINK_BOARD_ID
) \
361 $(wordlist
2,$(words $(1)),$(1)) \
362 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
365 define Build
/tplink-v1-header
366 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
367 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
368 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
369 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
374 # combine kernel and rootfs into one image
375 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
376 # <type> is "sysupgrade" or "factory"
378 # -a align the rootfs start on an <align> bytes boundary
379 # -j add jffs2 end-of-filesystem markers
380 # -s strip padding from end of the image
381 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
382 define Build
/tplink-v1-image
383 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
384 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
385 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
386 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
387 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
388 $(wordlist
2,$(words $(1)),$(1)) \
389 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
392 define Build
/tplink-v2-header
393 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
394 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
395 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
396 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
397 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
402 define Build
/tplink-v2-image
403 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
404 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
405 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
406 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
407 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
418 -a
$(KERNEL_LOADADDR
) \
419 -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
420 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
421 $(if
$(UIMAGE_MAGIC
),-M
$(UIMAGE_MAGIC
)) \
422 $(wordlist
2,$(words $(1)),$(1)) \
427 define Build
/xor-image
428 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
437 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
438 $@
$@.tmp
/$(if
$(1),$(1),$@
)
442 define Build
/zyxel-ras-image
444 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
445 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
451 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \