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 mkimage
-A
$(LINUX_KARCH
) \
13 -C
$(1) -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
14 -n
'$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' -d
$@
$@.new
18 define Build
/buffalo-enc
19 $(eval product
=$(word 1,$(1)))
20 $(eval version
=$(word 2,$(1)))
21 $(eval args
=$(wordlist
3,$(words $(1)),$(1)))
22 $(STAGING_DIR_HOST
)/bin
/buffalo-enc \
23 -p
$(product
) -v
$(version
) $(args
) \
28 define Build
/buffalo-enc-tag
29 $(call Build
/buffalo-enc
,'' '' -S
152 $(1))
32 define Build
/buffalo-tag-dhp
33 $(eval product
=$(word 1,$(1)))
34 $(eval region
=$(word 2,$(1)))
35 $(eval language
=$(word 3,$(1)))
36 $(STAGING_DIR_HOST
)/bin
/buffalo-tag \
38 -a
$(BUFFALO_TAG_PLATFORM
) \
39 -v
$(BUFFALO_TAG_VERSION
) -m
$(BUFFALO_TAG_MINOR
) \
40 -b
$(product
) -p
$(product
) \
41 -r
$(region
) -r
$(region
) -l
$(language
) \
46 define Build
/buffalo-dhp-image
47 $(STAGING_DIR_HOST
)/bin
/mkdhpimg
$@
$@.new
51 define Build
/eva-image
52 $(STAGING_DIR_HOST
)/bin
/lzma2eva
$(KERNEL_LOADADDR
) $(KERNEL_LOADADDR
) $@
$@.new
57 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@ \
58 -m
"dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m
"type=firmware"
62 define Build
/seama-seal
63 $(STAGING_DIR_HOST
)/bin
/seama
-i
$@
-s
$@.seama \
64 -m
"signature=$(SEAMA_SIGNATURE)"
68 define Build
/zyxel-ras-image
70 newsize
="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
71 $(STAGING_DIR_HOST
)/bin
/mkrasimage \
77 $(if
$(findstring separate-kernel
,$(word 1,$(1))),-k
$(IMAGE_KERNEL
)) \
81 define Build
/netgear-chk
82 $(STAGING_DIR_HOST
)/bin
/mkchkimg \
85 -b
$(NETGEAR_BOARD_ID
) \
86 $(if
$(NETGEAR_REGION
),-r
$(NETGEAR_REGION
),)
90 define Build
/netgear-dni
91 $(STAGING_DIR_HOST
)/bin
/mkdniimg \
92 -B
$(NETGEAR_BOARD_ID
) -v
$(VERSION_DIST
).
$(firstword $(subst -, ,$(REVISION
))) \
93 $(if
$(NETGEAR_HW_ID
),-H
$(NETGEAR_HW_ID
)) \
99 define Build
/append-squashfs-fakeroot-be
100 rm -rf
$@.fakefs
$@.fakesquashfs
102 $(STAGING_DIR_HOST
)/bin
/mksquashfs-lzma \
103 $@.fakefs
$@.fakesquashfs \
104 -noappend
-root-owned
-be
-nopad
-b
65536 \
105 $(if
$(SOURCE_DATE_EPOCH
),-fixed-time
$(SOURCE_DATE_EPOCH
))
106 cat
$@.fakesquashfs
>> $@
109 define Build
/append-string
113 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
115 define Build
/append-uImage-fakehdr
116 $(eval type
=$(word 1,$(1)))
117 $(eval magic
=$(word 2,$(1)))
119 $(STAGING_DIR_HOST
)/bin
/mkimage \
120 -A
$(LINUX_KARCH
) -O linux
-T
$(type
) -C none \
121 -n
'$(VERSION_DIST) fake $(type)' \
122 $(if
$(magic
),-M
$(magic
)) \
129 define Build
/tplink-safeloader
130 -$(STAGING_DIR_HOST
)/bin
/tplink-safeloader \
131 -B
$(TPLINK_BOARD_ID
) \
137 $(wordlist
2,$(words $(1)),$(1)) \
138 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-S
) && mv
$@.new
$@ ||
rm -f
$@
141 define Build
/append-dtb
142 cat
$(KDIR
)/image-
$(firstword $(DEVICE_DTS
)).dtb
>> $@
145 define Build
/install-dtb
147 $(foreach dts
,$(DEVICE_DTS
), \
149 $(DTS_DIR
)/$(dts
).dtb \
150 $(BIN_DIR
)/$(IMG_PREFIX
)-$(dts
).dtb
; \
152 install-dtb-
$(IMG_PREFIX
) \
157 $(TOPDIR
)/scripts
/mkits.sh \
158 -D
$(DEVICE_NAME
) -o
$@.its
-k
$@ \
159 $(if
$(word 2,$(1)),-d
$(word 2,$(1))) -C
$(word 1,$(1)) \
160 -a
$(KERNEL_LOADADDR
) -e
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
161 $(if
$(DEVICE_FDT_NUM
),-n
$(DEVICE_FDT_NUM
)) \
162 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config@1") \
163 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
164 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
169 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
172 define Build
/lzma-no-dict
173 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
178 gzip
-f
-9n
-c
$@
$(1) > $@.new
187 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
188 $@
$@.tmp
/$(if
$(1),$(1),$@
)
193 rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
&& \
194 mkdir
-p
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$$(dirname
$(1)) && \
195 cp
$@
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/$(1) && \
196 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2
--pad \
197 $(if
$(CONFIG_BIG_ENDIAN
),--big-endian
,--little-endian
) \
198 --squash-uids
-v
-e
$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
200 -d
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2 \
201 2>&1 1>/dev
/null | awk
'/^.+$$$$/' && \
202 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@.new
-J
$(patsubst %k
,,$(BLOCKSIZE
))
203 -rm -rf
$(KDIR_TMP
)/$(DEVICE_NAME
)/jffs2
/
207 define Build
/kernel-bin
212 define Build
/patch-cmdline
213 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
216 define Build
/append-kernel
217 dd if
=$(IMAGE_KERNEL
) >> $@
220 define Build
/append-rootfs
221 dd if
=$(IMAGE_ROOTFS
) >> $@
224 define Build
/append-ubi
225 sh
$(TOPDIR
)/scripts
/ubinize-image.sh \
226 $(if
$(UBOOTENV_IN_UBI
),--uboot-env
) \
227 $(if
$(KERNEL_IN_UBI
),--kernel
$(IMAGE_KERNEL
)) \
228 $(foreach part
,$(UBINIZE_PARTS
),--part
$(part
)) \
231 -p
$(BLOCKSIZE
:%k
=%KiB
) -m
$(PAGESIZE
) \
232 $(if
$(SUBPAGESIZE
),-s
$(SUBPAGESIZE
)) \
233 $(if
$(VID_HDR_OFFSET
),-O
$(VID_HDR_OFFSET
)) \
239 define Build
/append-uboot
240 dd if
=$(UBOOT_PATH
) >> $@
244 $(call Image
/pad-to
,$@
,$(1))
247 define Build
/pad-extra
248 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
251 define Build
/pad-rootfs
252 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
253 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
256 define Build
/pad-offset
258 size
="$$(stat -c%s $@)" \
259 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
260 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
261 pad
="(pad - ((size + offset) % pad)) % pad" \
262 newsize
='size + pad'; \
263 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
267 define Build
/xor-image
268 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
272 define Build
/check-size
273 @imagesize
="$$(stat -c%s $@)"; \
274 limitsize
="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
275 [ $$limitsize -ge
$$imagesize ] ||
{ \
276 echo
"WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
281 define Build
/combined-image
282 -sh
$(TOPDIR
)/scripts
/combined-image.sh \
289 define Build
/linksys-image
290 $(TOPDIR
)/scripts
/linksys-image.sh \
291 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
296 define Build
/openmesh-image
297 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
298 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
300 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
301 "$(call param_get_default,rootfs,$(1),$@)"
302 $(TOPDIR
)/scripts
/combined-ext-image.sh \
303 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
304 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
305 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
306 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
309 define Build
/qsdk-ipq-factory-nand
310 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
312 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
316 define Build
/qsdk-ipq-factory-nor
317 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
318 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
319 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
323 define Build
/senao-header
324 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
328 define Build
/sysupgrade-tar
329 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
330 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
331 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
332 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
336 define Build
/tplink-v1-header
337 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
338 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
339 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
340 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
345 # combine kernel and rootfs into one image
346 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
347 # <type> is "sysupgrade" or "factory"
349 # -a align the rootfs start on an <align> bytes boundary
350 # -j add jffs2 end-of-filesystem markers
351 # -s strip padding from end of the image
352 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
353 define Build
/tplink-v1-image
354 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
355 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
356 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
357 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
358 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
359 $(wordlist
2,$(words $(1)),$(1)) \
360 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
363 define Build
/tplink-v2-header
364 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
365 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
366 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
367 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
368 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
373 define Build
/tplink-v2-image
374 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
375 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
376 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
377 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
378 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
383 compat_version
=$(if
$(DEVICE_COMPAT_VERSION
),$(DEVICE_COMPAT_VERSION
),1.0)
384 json_quote
=$(subst ','\'',$(subst ",\",$(1)))
387 legacy_supported_message
=$(SUPPORTED_DEVICES
) - Image version mismatch
: image
$(compat_version
), \
388 device
1.0. Please wipe config during upgrade
(force required
) or reinstall. \
389 $(if
$(DEVICE_COMPAT_MESSAGE
),Reason
: $(DEVICE_COMPAT_MESSAGE
),Please
check documentation ...
)
391 metadata_devices
=$(if
$(1),$(subst "$(space)","$(comma)",$(strip $(foreach v
,$(1),"$(call json_quote,$(v))"))))
393 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
394 "metadata_version": "1.1", \
395 "compat_version": "$(call json_quote,$(compat_version))", \
396 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
397 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
398 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
399 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
400 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
402 "dist": "$(call json_quote,$(VERSION_DIST))", \
403 "version": "$(call json_quote,$(VERSION_NUMBER))", \
404 "revision": "$(call json_quote,$(REVISION))", \
405 "target": "$(call json_quote,$(TARGETID))", \
406 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
410 define Build
/append-metadata
411 $(if
$(SUPPORTED_DEVICES
),-echo
$(call metadata_json
) | fwtool
-I
- $@
)
412 [ ! -s
"$(BUILD_KEY)" -o
! -s
"$(BUILD_KEY).ucert" -o
! -s
"$@" ] ||
{ \
413 cp
"$(BUILD_KEY).ucert" "$@.ucert" ;\
414 usign
-S
-m
"$@" -s
"$(BUILD_KEY)" -x
"$@.sig" ;\
415 ucert
-A
-c
"$@.ucert" -x
"$@.sig" ;\
416 fwtool
-S
"$@.ucert" "$@" ;\
420 define Build
/kernel2minor
421 kernel2minor
-k
$@
-r
$@.new
$(1)
425 # Convert a raw image into a $1 type image.
426 # E.g. | qemu-image vdi
427 define Build
/qemu-image
428 qemu-img convert
-f raw
-O
$1 $@
$@.new