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)) LEDE Linux-$(LINUX_VERSION))' -d $@ $@.new
14 define Build/netgear-chk
15 $(STAGING_DIR_HOST)/bin/mkchkimg \
18 -b $(NETGEAR_BOARD_ID) \
23 define Build/netgear-dni
24 $(STAGING_DIR_HOST)/bin/mkdniimg \
25 -B $(NETGEAR_BOARD_ID) -v LEDE.$(REVISION) \
26 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
32 define Build/tplink-safeloader
33 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
34 -B $(TPLINK_BOARD_NAME) \
40 $(wordlist 2,$(words $(1)),$(1)) \
41 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
44 define Build/append-dtb
45 $(call Image/BuildDTB,$(if $(DEVICE_DTS_DIR),$(DEVICE_DTS_DIR),$(DTS_DIR))/$(DEVICE_DTS).dts,$@.dtb)
49 define Build/install-dtb
50 $(foreach dts,$(DEVICE_DTS), \
52 $(DTS_DIR)/$(dts).dtb \
53 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
58 $(TOPDIR)/scripts/mkits.sh \
59 -D $(DEVICE_NAME) -o $@.its -k $@ \
60 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
61 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
62 -A $(ARCH) -v $(LINUX_VERSION)
63 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
68 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
71 define Build/lzma-no-dict
72 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
77 gzip -9n -c $@ $(1) > $@.new
82 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
83 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
84 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
85 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
86 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
87 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
89 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
90 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
91 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
92 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
96 define Build/kernel-bin
101 define Build/patch-cmdline
102 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
105 define Build/append-kernel
106 dd if=$(IMAGE_KERNEL) >> $@
109 define Build/append-rootfs
110 dd if=$(IMAGE_ROOTFS) >> $@
113 define Build/append-ubi
114 sh $(TOPDIR)/scripts/ubinize-image.sh \
115 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
116 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
117 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
120 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
121 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
122 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
129 dd if=$@ of=$@.new bs=$(1) conv=sync
133 define Build/pad-extra
134 dd if=/dev/zero bs=$(1) count=1 >> $@
137 define Build/pad-rootfs
138 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
139 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
142 define Build/pad-offset
144 size="$$(stat -c%s $@)" \
145 pad="$(subst k,* 1024,$(word 1, $(1)))" \
146 offset="$(subst k,* 1024,$(word 2, $(1)))" \
147 pad="(pad - ((size + offset) % pad)) % pad" \
148 newsize='size + pad'; \
149 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
153 define Build/check-size
154 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
155 echo "WARNING: Image file $@ is too big" >&2; \
160 define Build/combined-image
161 -sh $(TOPDIR)/scripts/combined-image.sh \
168 define Build/sysupgrade-tar
169 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
170 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
171 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
172 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
176 json_quote=$(subst ','\'',$(subst ",\",$(1)))
178 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
180 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
181 "supported_devices":[$(call metadata_devices,$(1))], \
183 "dist": "$(call json_quote,$(VERSION_DIST))", \
184 "version": "$(call json_quote,$(VERSION_NUMBER))", \
185 "revision": "$(call json_quote,$(REVISION))", \
186 "board": "$(call json_quote,$(BOARD))" \
190 define Build/append-metadata
191 $(if $(SUPPORTED_DEVICES),echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
194 define Build/kernel2minor
195 kernel2minor -k $@ -r $@.new $(1)