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 -c
$(if
$(DEVICE_DTS_CONFIG
),$(DEVICE_DTS_CONFIG
),"config@1") \
162 -A
$(LINUX_KARCH
) -v
$(LINUX_VERSION
)
163 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
168 $(call Build
/lzma-no-dict
,-lc1
-lp2
-pb2
$(1))
171 define Build
/lzma-no-dict
172 $(STAGING_DIR_HOST
)/bin
/lzma e
$@
$(1) $@.new
177 gzip
-f
-9n
-c
$@
$(1) > $@.new
186 $(if
$(SOURCE_DATE_EPOCH
),--mtime
="$(SOURCE_DATE_EPOCH)") \
187 $@
$@.tmp
/$(if
$(1),$(1),$@
)
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
/kernel-bin
211 define Build
/patch-cmdline
212 $(STAGING_DIR_HOST
)/bin
/patch-cmdline
$@
'$(CMDLINE)'
215 define Build
/append-kernel
216 dd if
=$(IMAGE_KERNEL
) >> $@
219 define Build
/append-rootfs
220 dd if
=$(IMAGE_ROOTFS
) >> $@
223 define Build
/append-ubi
224 sh
$(TOPDIR
)/scripts
/ubinize-image.sh \
225 $(if
$(UBOOTENV_IN_UBI
),--uboot-env
) \
226 $(if
$(KERNEL_IN_UBI
),--kernel
$(IMAGE_KERNEL
)) \
227 $(foreach part
,$(UBINIZE_PARTS
),--part
$(part
)) \
230 -p
$(BLOCKSIZE
:%k
=%KiB
) -m
$(PAGESIZE
) \
231 $(if
$(SUBPAGESIZE
),-s
$(SUBPAGESIZE
)) \
232 $(if
$(VID_HDR_OFFSET
),-O
$(VID_HDR_OFFSET
)) \
238 define Build
/append-uboot
239 dd if
=$(UBOOT_PATH
) >> $@
243 $(call Image
/pad-to
,$@
,$(1))
246 define Build
/pad-extra
247 dd if
=/dev
/zero bs
=$(1) count
=1 >> $@
250 define Build
/pad-rootfs
251 $(STAGING_DIR_HOST
)/bin
/padjffs2
$@
$(1) \
252 $(if
$(BLOCKSIZE
),$(BLOCKSIZE
:%k
=%),4 8 16 64 128 256)
255 define Build
/pad-offset
257 size
="$$(stat -c%s $@)" \
258 pad
="$(subst k,* 1024,$(word 1, $(1)))" \
259 offset
="$(subst k,* 1024,$(word 2, $(1)))" \
260 pad
="(pad - ((size + offset) % pad)) % pad" \
261 newsize
='size + pad'; \
262 dd if
=$@ of
=$@.new bs
=$$newsize count
=1 conv
=sync
266 define Build
/xor-image
267 $(STAGING_DIR_HOST
)/bin
/xorimage
-i
$@
-o
$@.xor
$(1)
271 define Build
/check-size
272 @
[ $$(($(subst k
,* 1024,$(subst m
, * 1024k
,$(1))))) -ge
"$$(stat -c%s $@)" ] ||
{ \
273 echo
"WARNING: Image file $@ is too big" >&2; \
278 define Build
/combined-image
279 -sh
$(TOPDIR
)/scripts
/combined-image.sh \
286 define Build
/linksys-image
287 $(TOPDIR
)/scripts
/linksys-image.sh \
288 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
293 define Build
/openmesh-image
294 $(TOPDIR
)/scripts
/om-fwupgradecfg-gen.sh \
295 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
297 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
298 "$(call param_get_default,rootfs,$(1),$@)"
299 $(TOPDIR
)/scripts
/combined-ext-image.sh \
300 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
301 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
302 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
303 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
306 define Build
/qsdk-ipq-factory-nand
307 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
309 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
313 define Build
/qsdk-ipq-factory-nor
314 $(TOPDIR
)/scripts
/mkits-qsdk-ipq-image.sh \
315 $@.its hlos
$(IMAGE_KERNEL
) rootfs
$(IMAGE_ROOTFS
)
316 PATH
=$(LINUX_DIR
)/scripts
/dtc
:$(PATH
) mkimage
-f
$@.its
$@.new
320 define Build
/senao-header
321 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
325 define Build
/sysupgrade-tar
326 sh
$(TOPDIR
)/scripts
/sysupgrade-tar.sh \
327 --board
$(if
$(BOARD_NAME
),$(BOARD_NAME
),$(DEVICE_NAME
)) \
328 --kernel
$(call param_get_default
,kernel
,$(1),$(IMAGE_KERNEL
)) \
329 --rootfs
$(call param_get_default
,rootfs
,$(1),$(IMAGE_ROOTFS
)) \
333 define Build
/tplink-v1-header
334 $(STAGING_DIR_HOST
)/bin
/mktplinkfw \
335 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
336 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
337 -m
$(TPLINK_HEADER_VERSION
) -N
"$(VERSION_DIST)" -V
$(REVISION
) \
342 # combine kernel and rootfs into one image
343 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
344 # <type> is "sysupgrade" or "factory"
346 # -a align the rootfs start on an <align> bytes boundary
347 # -j add jffs2 end-of-filesystem markers
348 # -s strip padding from end of the image
349 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
350 define Build
/tplink-v1-image
351 -$(STAGING_DIR_HOST
)/bin
/mktplinkfw \
352 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -F
$(TPLINK_FLASHLAYOUT
) \
353 -N
"$(VERSION_DIST)" -V
$(REVISION
) -m
$(TPLINK_HEADER_VERSION
) \
354 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
-j
-X
0x40000 \
355 -a
$(call rootfs_align
,$(FILESYSTEM
)) \
356 $(wordlist
2,$(words $(1)),$(1)) \
357 $(if
$(findstring sysupgrade
,$(word 1,$(1))),-s
) && mv
$@.new
$@ ||
rm -f
$@
360 define Build
/tplink-v2-header
361 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
362 -c
-H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) -L
$(KERNEL_LOADADDR
) \
363 -E
$(if
$(KERNEL_ENTRY
),$(KERNEL_ENTRY
),$(KERNEL_LOADADDR
)) \
364 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
365 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" \
370 define Build
/tplink-v2-image
371 $(STAGING_DIR_HOST
)/bin
/mktplinkfw2 \
372 -H
$(TPLINK_HWID
) -W
$(TPLINK_HWREV
) \
373 -w
$(TPLINK_HWREVADD
) -F
"$(TPLINK_FLASHLAYOUT)" \
374 -T
$(TPLINK_HVERSION
) -V
"ver. 2.0" -a
0x4 -j \
375 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) -o
$@.new
$(1)
380 json_quote
=$(subst ','\'',$(subst ",\",$(1)))
382 metadata_devices
=$(if
$(1),$(subst "$(space)","$(comma)",$(strip $(foreach v
,$(1),"$(call json_quote,$(v))"))))
384 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
385 "metadata_version": "1.0", \
386 "supported_devices":[$(call metadata_devices,$(1))], \
388 "dist": "$(call json_quote,$(VERSION_DIST))", \
389 "version": "$(call json_quote,$(VERSION_NUMBER))", \
390 "revision": "$(call json_quote,$(REVISION))", \
391 "target": "$(call json_quote,$(TARGETID))", \
392 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
396 define Build
/append-metadata
397 $(if
$(SUPPORTED_DEVICES
),-echo
$(call metadata_json
,$(SUPPORTED_DEVICES
)) | fwtool
-I
- $@
)
398 [ ! -s
"$(BUILD_KEY)" -o
! -s
"$(BUILD_KEY).ucert" -o
! -s
"$@" ] ||
{ \
399 cp
"$(BUILD_KEY).ucert" "$@.ucert" ;\
400 usign
-S
-m
"$@" -s
"$(BUILD_KEY)" -x
"$@.sig" ;\
401 ucert
-A
-c
"$@.ucert" -x
"$@.sig" ;\
402 fwtool
-S
"$@.ucert" "$@" ;\
406 define Build
/kernel2minor
407 kernel2minor
-k
$@
-r
$@.new
$(1)