1 # Build commands that can be called from Device/* templates
3 IMAGE_KERNEL = $(word 1,$^)
4 IMAGE_ROOTFS = $(word 2,$^)
7 mkimage -A $(LINUX_KARCH) \
9 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
10 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' -d $@ $@.new
14 define Build/buffalo-enc
15 $(eval product=$(word 1,$(1)))
16 $(eval version=$(word 2,$(1)))
17 $(eval args=$(wordlist 3,$(words $(1)),$(1)))
18 $(STAGING_DIR_HOST)/bin/buffalo-enc \
19 -p $(product) -v $(version) $(args) \
24 define Build/buffalo-enc-tag
25 $(call Build/buffalo-enc,'' '' -S 152 $(1))
28 define Build/buffalo-tag-dhp
29 $(eval product=$(word 1,$(1)))
30 $(eval region=$(word 2,$(1)))
31 $(eval language=$(word 3,$(1)))
32 $(STAGING_DIR_HOST)/bin/buffalo-tag \
34 -a $(BUFFALO_TAG_PLATFORM) \
35 -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
36 -b $(product) -p $(product) \
37 -r $(region) -r $(region) -l $(language) \
42 define Build/buffalo-dhp-image
43 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
47 define Build/eva-image
48 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
52 define Build/zyxel-ras-image
54 newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
55 $(STAGING_DIR_HOST)/bin/mkrasimage \
61 $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
65 define Build/netgear-chk
66 $(STAGING_DIR_HOST)/bin/mkchkimg \
69 -b $(NETGEAR_BOARD_ID) \
70 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
74 define Build/netgear-dni
75 $(STAGING_DIR_HOST)/bin/mkdniimg \
76 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
77 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
83 define Build/append-squashfs-fakeroot-be
84 rm -rf $@.fakefs $@.fakesquashfs
86 $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
87 $@.fakefs $@.fakesquashfs \
88 -noappend -root-owned -be -nopad -b 65536 \
89 $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
90 cat $@.fakesquashfs >> $@
93 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
95 define Build/append-uImage-fakehdr
97 $(STAGING_DIR_HOST)/bin/mkimage \
98 -A $(LINUX_KARCH) -O linux -T $(1) -C none \
99 -n '$(VERSION_DIST) fake $(1)' \
106 define Build/tplink-safeloader
107 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
108 -B $(TPLINK_BOARD_ID) \
114 $(wordlist 2,$(words $(1)),$(1)) \
115 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
118 define Build/mksercommfw
119 -$(STAGING_DIR_HOST)/bin/mksercommfw \
128 define Build/append-dtb
129 cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
132 define Build/install-dtb
133 $(foreach dts,$(DEVICE_DTS), \
135 $(DTS_DIR)/$(dts).dtb \
136 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
141 $(TOPDIR)/scripts/mkits.sh \
142 -D $(DEVICE_NAME) -o $@.its -k $@ \
143 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
144 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
145 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
146 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
147 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
152 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
155 define Build/lzma-no-dict
156 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
161 gzip -f -9n -c $@ $(1) > $@.new
166 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
167 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
168 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
169 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
170 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
171 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
173 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
174 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
175 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
176 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
180 define Build/kernel-bin
185 define Build/patch-cmdline
186 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
189 define Build/append-kernel
190 dd if=$(IMAGE_KERNEL) >> $@
193 define Build/append-rootfs
194 dd if=$(IMAGE_ROOTFS) >> $@
197 define Build/append-ubi
198 sh $(TOPDIR)/scripts/ubinize-image.sh \
199 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
200 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
201 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
204 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
205 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
206 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
212 define Build/append-uboot
213 dd if=$(UBOOT_PATH) >> $@
217 dd if=$@ of=$@.new bs=$(1) conv=sync
221 define Build/pad-extra
222 dd if=/dev/zero bs=$(1) count=1 >> $@
225 define Build/pad-rootfs
226 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
227 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
230 define Build/pad-offset
232 size="$$(stat -c%s $@)" \
233 pad="$(subst k,* 1024,$(word 1, $(1)))" \
234 offset="$(subst k,* 1024,$(word 2, $(1)))" \
235 pad="(pad - ((size + offset) % pad)) % pad" \
236 newsize='size + pad'; \
237 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
241 define Build/check-size
242 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
243 echo "WARNING: Image file $@ is too big" >&2; \
248 define Build/combined-image
249 -sh $(TOPDIR)/scripts/combined-image.sh \
256 define Build/openmesh-image
257 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
258 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
260 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
261 "$(call param_get_default,rootfs,$(1),$@)"
262 $(TOPDIR)/scripts/combined-ext-image.sh \
263 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
264 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
265 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
266 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
269 define Build/senao-header
270 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
274 define Build/sysupgrade-tar
275 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
276 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
277 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
278 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
282 define Build/tplink-v1-header
283 $(STAGING_DIR_HOST)/bin/mktplinkfw \
284 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
285 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
286 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
291 define Build/tplink-v2-header
292 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
293 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
294 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
295 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
296 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
301 define Build/tplink-v2-image
302 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
303 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
304 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
305 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
306 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
311 json_quote=$(subst ','\'',$(subst ",\",$(1)))
313 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
315 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
316 "supported_devices":[$(call metadata_devices,$(1))], \
318 "dist": "$(call json_quote,$(VERSION_DIST))", \
319 "version": "$(call json_quote,$(VERSION_NUMBER))", \
320 "revision": "$(call json_quote,$(REVISION))", \
321 "board": "$(call json_quote,$(BOARD))" \
325 define Build/append-metadata
326 $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
327 [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
328 cp "$(BUILD_KEY).ucert" "$@.ucert" ;\
329 usign -S -m "$@" -s "$(BUILD_KEY)" -x "$@.sig" ;\
330 ucert -A -c "$@.ucert" -x "$@.sig" ;\
331 fwtool -S "$@.ucert" "$@" ;\
335 define Build/kernel2minor
336 kernel2minor -k $@ -r $@.new $(1)