build: move elecom-wrc-gs-factory to image-commands.mk
[openwrt/staging/stintel.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/elecom-wrc-gs-factory
191 $(eval product=$(word 1,$(1)))
192 $(eval version=$(word 2,$(1)))
193 $(eval hash_opt=$(word 3,$(1)))
194 $(MKHASH) md5 $(hash_opt) $@ >> $@
195 ( \
196 echo -n "ELECOM $(product) v$(version)" | \
197 dd bs=32 count=1 conv=sync; \
198 dd if=$@; \
199 ) > $@.new
200 mv $@.new $@
201 endef
202
203 define Build/elx-header
204 $(eval hw_id=$(word 1,$(1)))
205 $(eval xor_pattern=$(word 2,$(1)))
206 ( \
207 echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
208 dd bs=42 count=1 conv=sync; \
209 hw_id="$(hw_id)"; \
210 echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
211 dd bs=20 count=1 conv=sync; \
212 echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
213 dd bs=8 count=1 conv=sync; \
214 echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
215 dd bs=58 count=1 conv=sync; \
216 ) > $(KDIR)/tmp/$(DEVICE_NAME).header
217 $(call Build/xor-image,-p $(xor_pattern) -x)
218 cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > $@.new
219 mv $@.new $@
220 rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
221 endef
222
223 define Build/eva-image
224 $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
225 mv $@.new $@
226 endef
227
228 define Build/initrd_compression
229 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
230 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
231 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
232 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
233 $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
234 endef
235
236 define Build/fit
237 $(TOPDIR)/scripts/mkits.sh \
238 -D $(DEVICE_NAME) -o $@.its -k $@ \
239 -C $(word 1,$(1)) $(if $(word 2,$(1)),\
240 $(if $(DEVICE_DTS_OVERLAY),-d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))),\
241 -d $(word 2,$(1)))) \
242 $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
243 $(if $(findstring with-initrd,$(word 3,$(1))), \
244 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
245 -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
246 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
247 $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
248 $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \
249 $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtb)) \
250 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
251 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
252 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
253 -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f $@.its $@.new
254 @mv $@.new $@
255 endef
256
257 define Build/gzip
258 gzip -f -9n -c $@ $(1) > $@.new
259 @mv $@.new $@
260 endef
261
262 define Build/install-dtb
263 $(call locked, \
264 $(foreach dts,$(DEVICE_DTS), \
265 $(CP) \
266 $(DTS_DIR)/$(dts).dtb \
267 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
268 ), \
269 install-dtb-$(IMG_PREFIX) \
270 )
271 endef
272
273 define Build/jffs2
274 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
275 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
276 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
277 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
278 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
279 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
280 -o $@.new \
281 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
282 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
283 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
284 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
285 @mv $@.new $@
286 endef
287
288 define Build/kernel2minor
289 $(eval temp_file := $(shell mktemp))
290 cp $@ $(temp_file)
291 kernel2minor -k $(temp_file) -r $(temp_file).new $(1)
292 mv $(temp_file).new $@
293 rm -f $(temp_file)
294 endef
295
296 define Build/kernel-bin
297 rm -f $@
298 cp $< $@
299 endef
300
301 define Build/linksys-image
302 $(TOPDIR)/scripts/linksys-image.sh \
303 "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
304 $@ $@.new
305 mv $@.new $@
306 endef
307
308 define Build/lzma
309 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
310 endef
311
312 define Build/lzma-no-dict
313 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
314 @mv $@.new $@
315 endef
316
317 define Build/netgear-chk
318 $(STAGING_DIR_HOST)/bin/mkchkimg \
319 -o $@.new \
320 -k $@ \
321 -b $(NETGEAR_BOARD_ID) \
322 $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
323 mv $@.new $@
324 endef
325
326 define Build/netgear-dni
327 $(STAGING_DIR_HOST)/bin/mkdniimg \
328 -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
329 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
330 -r "$(1)" \
331 -i $@ -o $@.new
332 mv $@.new $@
333 endef
334
335 define Build/openmesh-image
336 $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
337 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
338 "$@-fwupgrade.cfg" \
339 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
340 "$(call param_get_default,rootfs,$(1),$@)"
341 $(TOPDIR)/scripts/combined-ext-image.sh \
342 "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
343 "$@-fwupgrade.cfg" "fwupgrade.cfg" \
344 "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
345 "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
346 endef
347
348 define Build/pad-extra
349 dd if=/dev/zero bs=$(1) count=1 >> $@
350 endef
351
352 define Build/pad-offset
353 let \
354 size="$$(stat -c%s $@)" \
355 pad="$(subst k,* 1024,$(word 1, $(1)))" \
356 offset="$(subst k,* 1024,$(word 2, $(1)))" \
357 pad="(pad - ((size + offset) % pad)) % pad" \
358 newsize='size + pad'; \
359 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
360 mv $@.new $@
361 endef
362
363 define Build/pad-rootfs
364 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
365 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
366 endef
367
368 define Build/pad-to
369 $(call Image/pad-to,$@,$(1))
370 endef
371
372 define Build/patch-cmdline
373 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
374 endef
375
376 # Convert a raw image into a $1 type image.
377 # E.g. | qemu-image vdi
378 define Build/qemu-image
379 if command -v qemu-img; then \
380 qemu-img convert -f raw -O $1 $@ $@.new; \
381 mv $@.new $@; \
382 else \
383 echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
384 fi
385 endef
386
387 define Build/qsdk-ipq-factory-nand
388 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
389 $@.its ubi $@
390 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
391 @mv $@.new $@
392 endef
393
394 define Build/qsdk-ipq-factory-nor
395 $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
396 $@.its hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
397 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
398 @mv $@.new $@
399 endef
400
401 define Build/seama
402 $(STAGING_DIR_HOST)/bin/seama -i $@ \
403 -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
404 mv $@.seama $@
405 endef
406
407 define Build/seama-seal
408 $(STAGING_DIR_HOST)/bin/seama -i $@ -s $@.seama \
409 -m "signature=$(SEAMA_SIGNATURE)"
410 mv $@.seama $@
411 endef
412
413 define Build/senao-header
414 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
415 mv $@.new $@
416 endef
417
418 define Build/sysupgrade-tar
419 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
420 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
421 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
422 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
423 $@
424 endef
425
426 define Build/tplink-safeloader
427 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
428 -B $(TPLINK_BOARD_ID) \
429 -V $(REVISION) \
430 -k $(IMAGE_KERNEL) \
431 -r $@ \
432 -o $@.new \
433 -j \
434 $(wordlist 2,$(words $(1)),$(1)) \
435 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
436 endef
437
438 define Build/tplink-v1-header
439 $(STAGING_DIR_HOST)/bin/mktplinkfw \
440 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
441 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
442 -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
443 -k $@ -o $@.new $(1)
444 @mv $@.new $@
445 endef
446
447 # combine kernel and rootfs into one image
448 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
449 # <type> is "sysupgrade" or "factory"
450 #
451 # -a align the rootfs start on an <align> bytes boundary
452 # -j add jffs2 end-of-filesystem markers
453 # -s strip padding from end of the image
454 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
455 define Build/tplink-v1-image
456 -$(STAGING_DIR_HOST)/bin/mktplinkfw \
457 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
458 -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
459 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new -j -X 0x40000 \
460 -a $(call rootfs_align,$(FILESYSTEM)) \
461 $(wordlist 2,$(words $(1)),$(1)) \
462 $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv $@.new $@ || rm -f $@
463 endef
464
465 define Build/tplink-v2-header
466 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
467 -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
468 -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
469 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
470 -T $(TPLINK_HVERSION) -V "ver. 2.0" \
471 -k $@ -o $@.new $(1)
472 @mv $@.new $@
473 endef
474
475 define Build/tplink-v2-image
476 $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
477 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
478 -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
479 -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
480 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
481 cat $@.new >> $@
482 rm -rf $@.new
483 endef
484
485 define Build/uImage
486 mkimage \
487 -A $(LINUX_KARCH) \
488 -O linux \
489 -T kernel \
490 -C $(word 1,$(1)) \
491 -a $(KERNEL_LOADADDR) \
492 -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
493 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
494 $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
495 $(wordlist 2,$(words $(1)),$(1)) \
496 -d $@ $@.new
497 mv $@.new $@
498 endef
499
500 define Build/xor-image
501 $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o $@.xor $(1)
502 mv $@.xor $@
503 endef
504
505 define Build/zip
506 mkdir $@.tmp
507 mv $@ $@.tmp/$(1)
508
509 zip -j -X \
510 $(if $(SOURCE_DATE_EPOCH),--mtime="$(SOURCE_DATE_EPOCH)") \
511 $@ $@.tmp/$(if $(1),$(1),$@)
512 rm -rf $@.tmp
513 endef
514
515 define Build/zyxel-ras-image
516 let \
517 newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
518 $(STAGING_DIR_HOST)/bin/mkrasimage \
519 -b $(RAS_BOARD) \
520 -v $(RAS_VERSION) \
521 -r $@ \
522 -s $$newsize \
523 -o $@.new \
524 $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
525 && mv $@.new $@
526 endef