build: kernel2minor: work around path length limit
[openwrt/openwrt.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 ModelNameLimit16
7 $(shell expr substr "$(word 2, $(subst _, ,$(1)))" 1 16)
8 endef
9
10 define rootfs_align
11 $(patsubst %-256k,0x40000,$(patsubst %-128k,0x20000,$(patsubst %-64k,0x10000,$(patsubst squashfs%,0x4,$(patsubst root.%,%,$(1))))))
12 endef
13
14
15 define Build/append-dtb
16 cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
17 endef
18
19 define Build/append-dtb-elf
20 $(TARGET_CROSS)objcopy \
21 --set-section-flags=.appended_dtb=alloc,contents \
22 --update-section \
23 .appended_dtb=$(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb $@
24 endef
25
26 define Build/append-kernel
27 dd if=$(IMAGE_KERNEL) >> $@
28 endef
29
30 define Build/append-image
31 dd if=$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1) >> $@
32 endef
33
34 ifdef IB
35 define Build/append-image-stage
36 dd if=$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))-$(DEVICE_NAME)-$(1) >> $@
37 endef
38 else
39 define Build/append-image-stage
40 dd if=$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1) of=$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))-$(DEVICE_NAME)-$(1)
41 dd if=$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1) >> $@
42 endef
43 endif
44
45
46 compat_version=$(if $(DEVICE_COMPAT_VERSION),$(DEVICE_COMPAT_VERSION),1.0)
47 json_quote=$(subst ','\'',$(subst ",\",$(1)))
48 #")')
49
50 legacy_supported_message=$(SUPPORTED_DEVICES) - Image version mismatch: image $(compat_version), \
51 device 1.0. Please wipe config during upgrade (force required) or reinstall. \
52 $(if $(DEVICE_COMPAT_MESSAGE),Reason: $(DEVICE_COMPAT_MESSAGE),Please check documentation ...)
53
54 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
55 metadata_json = \
56 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
57 "metadata_version": "1.1", \
58 "compat_version": "$(call json_quote,$(compat_version))", \
59 $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
60 $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
61 [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
62 "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
63 $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
64 "version": { \
65 "dist": "$(call json_quote,$(VERSION_DIST))", \
66 "version": "$(call json_quote,$(VERSION_NUMBER))", \
67 "revision": "$(call json_quote,$(REVISION))", \
68 "target": "$(call json_quote,$(TARGETID))", \
69 "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
70 } \
71 }'
72
73 define Build/append-metadata
74 $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json) | fwtool -I - $@)
75 [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
76 cp "$(BUILD_KEY).ucert" "$@.ucert" ;\
77 usign -S -m "$@" -s "$(BUILD_KEY)" -x "$@.sig" ;\
78 ucert -A -c "$@.ucert" -x "$@.sig" ;\
79 fwtool -S "$@.ucert" "$@" ;\
80 }
81 endef
82
83 define Build/append-rootfs
84 dd if=$(IMAGE_ROOTFS) >> $@
85 endef
86
87 define Build/append-squashfs-fakeroot-be
88 rm -rf $@.fakefs $@.fakesquashfs
89 mkdir $@.fakefs
90 $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
91 $@.fakefs $@.fakesquashfs \
92 -noappend -root-owned -be -nopad -b 65536 \
93 $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
94 cat $@.fakesquashfs >> $@
95 endef
96
97 define Build/append-string
98 echo -n $(1) >> $@
99 endef
100
101 define Build/append-ubi
102 sh $(TOPDIR)/scripts/ubinize-image.sh \
103 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
104 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
105 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
106 $(IMAGE_ROOTFS) \
107 $@.tmp \
108 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
109 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
110 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
111 $(UBINIZE_OPTS)
112 cat $@.tmp >> $@
113 rm $@.tmp
114 endef
115
116 define Build/append-uboot
117 dd if=$(UBOOT_PATH) >> $@
118 endef
119
120 # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
121 # for example
122 define Build/append-uImage-fakehdr
123 $(eval type=$(word 1,$(1)))
124 $(eval magic=$(word 2,$(1)))
125 touch $@.fakehdr
126 $(STAGING_DIR_HOST)/bin/mkimage \
127 -A $(LINUX_KARCH) -O linux -T $(type) -C none \
128 -n '$(VERSION_DIST) fake $(type)' \
129 $(if $(magic),-M $(magic)) \
130 -d $@.fakehdr \
131 -s \
132 $@.fakehdr
133 cat $@.fakehdr >> $@
134 endef
135
136 define Build/buffalo-dhp-image
137 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
138 mv $@.new $@
139 endef
140
141 define Build/buffalo-enc
142 $(eval product=$(word 1,$(1)))
143 $(eval version=$(word 2,$(1)))
144 $(eval args=$(wordlist 3,$(words $(1)),$(1)))
145 $(STAGING_DIR_HOST)/bin/buffalo-enc \
146 -p $(product) -v $(version) $(args) \
147 -i $@ -o $@.new
148 mv $@.new $@
149 endef
150
151 define Build/buffalo-enc-tag
152 $(call Build/buffalo-enc,'' '' -S 152 $(1))
153 endef
154
155 define Build/buffalo-tag-dhp
156 $(eval product=$(word 1,$(1)))
157 $(eval region=$(word 2,$(1)))
158 $(eval language=$(word 3,$(1)))
159 $(STAGING_DIR_HOST)/bin/buffalo-tag \
160 -d 0x01000000 -w 1 \
161 -a $(BUFFALO_TAG_PLATFORM) \
162 -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
163 -b $(product) -p $(product) \
164 -r $(region) -r $(region) -l $(language) \
165 -I $@ -o $@.new
166 mv $@.new $@
167 endef
168
169 define Build/check-size
170 @imagesize="$$(stat -c%s $@)"; \
171 limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
172 [ $$limitsize -ge $$imagesize ] || { \
173 echo "WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
174 rm -f $@; \
175 }
176 endef
177
178 define Build/elecom-product-header
179 $(eval product=$(word 1,$(1)))
180 $(eval fw=$(if $(word 2,$(1)),$(word 2,$(1)),$@))
181
182 ( \
183 echo -n -e "ELECOM\x00\x00$(product)" | dd bs=40 count=1 conv=sync; \
184 echo -n "0.00" | dd bs=16 count=1 conv=sync; \
185 dd if=$(fw); \
186 ) > $(fw).new
187 mv $(fw).new $(fw)
188 endef
189
190 define Build/elx-header
191 $(eval hw_id=$(word 1,$(1)))
192 $(eval xor_pattern=$(word 2,$(1)))
193 ( \
194 echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
195 dd bs=42 count=1 conv=sync; \
196 hw_id="$(hw_id)"; \
197 echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
198 dd bs=20 count=1 conv=sync; \
199 echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
200 dd bs=8 count=1 conv=sync; \
201 echo -ne "$$($(STAGING_DIR_HOST)/bin/mkhash md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
202 dd bs=58 count=1 conv=sync; \
203 ) > $(KDIR)/tmp/$(DEVICE_NAME).header
204 $(call Build/xor-image,-p $(xor_pattern) -x)
205 cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > $@.new
206 mv $@.new $@
207 rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
208 endef
209
210 define Build/eva-image
211 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
212 mv $@.new $@
213 endef
214
215 define Build/initrd_compression
216 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
217 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
218 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
219 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
220 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
221 endef
222
223 define Build/fit
224 $(TOPDIR)/scripts/mkits.sh \
225 -D $(DEVICE_NAME) -o $@.its -k $@ \
226 -C $(word 1,$(1)) $(if $(word 2,$(1)),\
227 $(if $(DEVICE_DTS_OVERLAY),-d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))),\
228 -d $(word 2,$(1)))) \
229 $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
230 $(if $(findstring with-initrd,$(word 3,$(1))), \
231 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
232 -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
233 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
234 $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
235 $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtb)) \
236 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
237 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
238 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
239 -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f $@.its $@.new
240 @mv $@.new $@
241 endef
242
243 define Build/gzip
244 gzip -f -9n -c $@ $(1) > $@.new
245 @mv $@.new $@
246 endef
247
248 define Build/install-dtb
249 $(call locked, \
250 $(foreach dts,$(DEVICE_DTS), \
251 $(CP) \
252 $(DTS_DIR)/$(dts).dtb \
253 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
254 ), \
255 install-dtb-$(IMG_PREFIX) \
256 )
257 endef
258
259 define Build/jffs2
260 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
261 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
262 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
263 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
264 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
265 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
266 -o $@.new \
267 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
268 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
269 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
270 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
271 @mv $@.new $@
272 endef
273
274 define Build/kernel2minor
275 $(eval temp_file := $(shell mktemp))
276 cp $@ $(temp_file)
277 kernel2minor -k $(temp_file) -r $(temp_file).new $(1)
278 mv $(temp_file).new $@
279 rm -f $(temp_file)
280 endef
281
282 define Build/kernel-bin
283 rm -f $@
284 cp $< $@
285 endef
286
287 define Build/linksys-image
288 $(TOPDIR)/scripts/linksys-image.sh \
289 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
290 $@ $@.new
291 mv $@.new $@
292 endef
293
294 define Build/lzma
295 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
296 endef
297
298 define Build/lzma-no-dict
299 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
300 @mv $@.new $@
301 endef
302
303 define Build/netgear-chk
304 $(STAGING_DIR_HOST)/bin/mkchkimg \
305 -o $@.new \
306 -k $@ \
307 -b $(NETGEAR_BOARD_ID) \
308 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
309 mv $@.new $@
310 endef
311
312 define Build/netgear-dni
313 $(STAGING_DIR_HOST)/bin/mkdniimg \
314 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
315 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
316 -r "$(1)" \
317 -i $@ -o $@.new
318 mv $@.new $@
319 endef
320
321 define Build/openmesh-image
322 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
323 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
324 "$@-fwupgrade.cfg" \
325 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
326 "$(call param_get_default,rootfs,$(1),$@)"
327 $(TOPDIR)/scripts/combined-ext-image.sh \
328 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
329 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
330 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
331 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
332 endef
333
334 define Build/pad-extra
335 dd if=/dev/zero bs=$(1) count=1 >> $@
336 endef
337
338 define Build/pad-offset
339 let \
340 size="$$(stat -c%s $@)" \
341 pad="$(subst k,* 1024,$(word 1, $(1)))" \
342 offset="$(subst k,* 1024,$(word 2, $(1)))" \
343 pad="(pad - ((size + offset) % pad)) % pad" \
344 newsize='size + pad'; \
345 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
346 mv $@.new $@
347 endef
348
349 define Build/pad-rootfs
350 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
351 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
352 endef
353
354 define Build/pad-to
355 $(call Image/pad-to,$@,$(1))
356 endef
357
358 define Build/patch-cmdline
359 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
360 endef
361
362 # Convert a raw image into a $1 type image.
363 # E.g. | qemu-image vdi
364 define Build/qemu-image
365 if command -v qemu-img; then \
366 qemu-img convert -f raw -O $1 $@ $@.new; \
367 mv $@.new $@; \
368 else \
369 echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
370 fi
371 endef
372
373 define Build/qsdk-ipq-factory-nand
374 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
375 $@.its ubi $@
376 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
377 @mv $@.new $@
378 endef
379
380 define Build/qsdk-ipq-factory-nor
381 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
382 $@.its hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
383 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
384 @mv $@.new $@
385 endef
386
387 define Build/seama
388 $(STAGING_DIR_HOST)/bin/seama -i $@ \
389 -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
390 mv $@.seama $@
391 endef
392
393 define Build/seama-seal
394 $(STAGING_DIR_HOST)/bin/seama -i $@ -s $@.seama \
395 -m "signature=$(SEAMA_SIGNATURE)"
396 mv $@.seama $@
397 endef
398
399 define Build/senao-header
400 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
401 mv $@.new $@
402 endef
403
404 define Build/sysupgrade-tar
405 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
406 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
407 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
408 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
409 $@
410 endef
411
412 define Build/tplink-safeloader
413 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
414 -B $(TPLINK_BOARD_ID) \
415 -V $(REVISION) \
416 -k $(IMAGE_KERNEL) \
417 -r $@ \
418 -o $@.new \
419 -j \
420 $(wordlist 2,$(words $(1)),$(1)) \
421 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
422 endef
423
424 define Build/tplink-v1-header
425 $(STAGING_DIR_HOST)/bin/mktplinkfw \
426 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
427 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
428 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
429 -k $@ -o $@.new $(1)
430 @mv $@.new $@
431 endef
432
433 # combine kernel and rootfs into one image
434 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
435 # <type> is "sysupgrade" or "factory"
436 #
437 # -a align the rootfs start on an <align> bytes boundary
438 # -j add jffs2 end-of-filesystem markers
439 # -s strip padding from end of the image
440 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
441 define Build/tplink-v1-image
442 -$(STAGING_DIR_HOST)/bin/mktplinkfw \
443 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
444 -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
445 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new -j -X 0x40000 \
446 -a $(call rootfs_align,$(FILESYSTEM)) \
447 $(wordlist 2,$(words $(1)),$(1)) \
448 $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv $@.new $@ || rm -f $@
449 endef
450
451 define Build/tplink-v2-header
452 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
453 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
454 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
455 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
456 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
457 -k $@ -o $@.new $(1)
458 @mv $@.new $@
459 endef
460
461 define Build/tplink-v2-image
462 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
463 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
464 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
465 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
466 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
467 cat $@.new >> $@
468 rm -rf $@.new
469 endef
470
471 define Build/uImage
472 mkimage \
473 -A $(LINUX_KARCH) \
474 -O linux \
475 -T kernel \
476 -C $(word 1,$(1)) \
477 -a $(KERNEL_LOADADDR) \
478 -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
479 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
480 $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
481 $(wordlist 2,$(words $(1)),$(1)) \
482 -d $@ $@.new
483 mv $@.new $@
484 endef
485
486 define Build/xor-image
487 $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o $@.xor $(1)
488 mv $@.xor $@
489 endef
490
491 define Build/zip
492 mkdir $@.tmp
493 mv $@ $@.tmp/$(1)
494
495 zip -j -X \
496 $(if $(SOURCE_DATE_EPOCH),--mtime="$(SOURCE_DATE_EPOCH)") \
497 $@ $@.tmp/$(if $(1),$(1),$@)
498 rm -rf $@.tmp
499 endef
500
501 define Build/zyxel-ras-image
502 let \
503 newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
504 $(STAGING_DIR_HOST)/bin/mkrasimage \
505 -b $(RAS_BOARD) \
506 -v $(RAS_VERSION) \
507 -r $@ \
508 -s $$newsize \
509 -o $@.new \
510 $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
511 && mv $@.new $@
512 endef