kernel: bump 4.9 to 4.9.106
[openwrt/staging/wigyori.git] / include / image-commands.mk
1 # Build commands that can be called from Device/* templates
2
3 IMAGE_KERNEL = $(word 1,$^)
4 IMAGE_ROOTFS = $(word 2,$^)
5
6 define Build/uImage
7 mkimage -A $(LINUX_KARCH) \
8 -O linux -T kernel \
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
11 mv $@.new $@
12 endef
13
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) \
20 -i $@ -o $@.new
21 mv $@.new $@
22 endef
23
24 define Build/buffalo-enc-tag
25 $(call Build/buffalo-enc,'' '' -S 152 $(1))
26 endef
27
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 \
33 -d 0x01000000 -w 1 \
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) \
38 -I $@ -o $@.new
39 mv $@.new $@
40 endef
41
42 define Build/buffalo-dhp-image
43 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
44 mv $@.new $@
45 endef
46
47 define Build/eva-image
48 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
49 mv $@.new $@
50 endef
51
52 define Build/netgear-chk
53 $(STAGING_DIR_HOST)/bin/mkchkimg \
54 -o $@.new \
55 -k $@ \
56 -b $(NETGEAR_BOARD_ID) \
57 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
58 mv $@.new $@
59 endef
60
61 define Build/netgear-dni
62 $(STAGING_DIR_HOST)/bin/mkdniimg \
63 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(REVISION) \
64 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
65 -r "$(1)" \
66 -i $@ -o $@.new
67 mv $@.new $@
68 endef
69
70 define Build/append-squashfs-fakeroot-be
71 rm -rf $@.fakefs $@.fakesquashfs
72 mkdir $@.fakefs
73 $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
74 $@.fakefs $@.fakesquashfs \
75 -noappend -root-owned -be -nopad -b 65536 \
76 $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
77 cat $@.fakesquashfs >> $@
78 endef
79
80 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
81 # for example
82 define Build/append-uImage-fakehdr
83 touch $@.fakehdr
84 $(STAGING_DIR_HOST)/bin/mkimage \
85 -A $(LINUX_KARCH) -O linux -T $(1) -C none \
86 -n '$(VERSION_DIST) fake $(1)' \
87 -d $@.fakehdr \
88 -s \
89 $@.fakehdr
90 cat $@.fakehdr >> $@
91 endef
92
93 define Build/tplink-safeloader
94 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
95 -B $(TPLINK_BOARD_ID) \
96 -V $(REVISION) \
97 -k $(IMAGE_KERNEL) \
98 -r $@ \
99 -o $@.new \
100 -j \
101 $(wordlist 2,$(words $(1)),$(1)) \
102 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
103 endef
104
105 define Build/append-dtb
106 cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
107 endef
108
109 define Build/install-dtb
110 $(foreach dts,$(DEVICE_DTS), \
111 $(CP) \
112 $(DTS_DIR)/$(dts).dtb \
113 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
114 )
115 endef
116
117 define Build/fit
118 $(TOPDIR)/scripts/mkits.sh \
119 -D $(DEVICE_NAME) -o $@.its -k $@ \
120 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
121 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
122 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
123 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
124 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
125 @mv $@.new $@
126 endef
127
128 define Build/lzma
129 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
130 endef
131
132 define Build/lzma-no-dict
133 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
134 @mv $@.new $@
135 endef
136
137 define Build/gzip
138 gzip -f -9n -c $@ $(1) > $@.new
139 @mv $@.new $@
140 endef
141
142 define Build/jffs2
143 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
144 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
145 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
146 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
147 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
148 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
149 -o $@.new \
150 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
151 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
152 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
153 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
154 @mv $@.new $@
155 endef
156
157 define Build/kernel-bin
158 rm -f $@
159 cp $< $@
160 endef
161
162 define Build/patch-cmdline
163 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
164 endef
165
166 define Build/append-kernel
167 dd if=$(IMAGE_KERNEL) >> $@
168 endef
169
170 define Build/append-rootfs
171 dd if=$(IMAGE_ROOTFS) >> $@
172 endef
173
174 define Build/append-ubi
175 sh $(TOPDIR)/scripts/ubinize-image.sh \
176 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
177 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
178 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
179 $(IMAGE_ROOTFS) \
180 $@.tmp \
181 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
182 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
183 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
184 $(UBINIZE_OPTS)
185 cat $@.tmp >> $@
186 rm $@.tmp
187 endef
188
189 define Build/append-uboot
190 dd if=$(UBOOT_PATH) >> $@
191 endef
192
193 define Build/pad-to
194 dd if=$@ of=$@.new bs=$(1) conv=sync
195 mv $@.new $@
196 endef
197
198 define Build/pad-extra
199 dd if=/dev/zero bs=$(1) count=1 >> $@
200 endef
201
202 define Build/pad-rootfs
203 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
204 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
205 endef
206
207 define Build/pad-offset
208 let \
209 size="$$(stat -c%s $@)" \
210 pad="$(subst k,* 1024,$(word 1, $(1)))" \
211 offset="$(subst k,* 1024,$(word 2, $(1)))" \
212 pad="(pad - ((size + offset) % pad)) % pad" \
213 newsize='size + pad'; \
214 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
215 mv $@.new $@
216 endef
217
218 define Build/check-size
219 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
220 echo "WARNING: Image file $@ is too big" >&2; \
221 rm -f $@; \
222 }
223 endef
224
225 define Build/combined-image
226 -sh $(TOPDIR)/scripts/combined-image.sh \
227 "$(IMAGE_KERNEL)" \
228 "$@" \
229 "$@.new"
230 @mv $@.new $@
231 endef
232
233 define Build/openmesh-image
234 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
235 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
236 "$@-fwupgrade.cfg" \
237 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
238 "$(call param_get_default,rootfs,$(1),$@)"
239 $(TOPDIR)/scripts/combined-ext-image.sh \
240 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
241 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
242 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
243 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
244 endef
245
246 define Build/sysupgrade-tar
247 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
248 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
249 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
250 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
251 $@
252 endef
253
254 define Build/tplink-v1-header
255 $(STAGING_DIR_HOST)/bin/mktplinkfw \
256 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
257 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
258 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
259 -k $@ -o $@.new $(1)
260 @mv $@.new $@
261 endef
262
263 define Build/tplink-v2-header
264 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
265 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
266 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
267 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
268 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
269 -k $@ -o $@.new $(1)
270 @mv $@.new $@
271 endef
272
273 define Build/tplink-v2-image
274 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
275 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
276 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
277 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
278 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
279 cat $@.new >> $@
280 rm -rf $@.new
281 endef
282
283 json_quote=$(subst ','\'',$(subst ",\",$(1)))
284 #")')
285 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
286 metadata_json = \
287 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
288 "supported_devices":[$(call metadata_devices,$(1))], \
289 "version": { \
290 "dist": "$(call json_quote,$(VERSION_DIST))", \
291 "version": "$(call json_quote,$(VERSION_NUMBER))", \
292 "revision": "$(call json_quote,$(REVISION))", \
293 "board": "$(call json_quote,$(BOARD))" \
294 } \
295 }'
296
297 define Build/append-metadata
298 $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
299 endef
300
301 define Build/kernel2minor
302 kernel2minor -k $@ -r $@.new $(1)
303 mv $@.new $@
304 endef