image.mk: use LINUX_KARCH rather than ARCH for mkits
[openwrt/openwrt.git] / include / image-commands.mk
index 40a9619c31c4d3015d9d001b140081d27f5aea24..04fa853fbbd99936c547d5eb0862137cba22809d 100644 (file)
@@ -59,7 +59,7 @@ define Build/fit
                -D $(DEVICE_NAME) -o $@.its -k $@ \
                $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
                -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-               -A $(ARCH) -v $(LINUX_VERSION)
+               -A $(LINUX_KARCH) -v $(LINUX_VERSION)
        PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
        @mv $@.new $@
 endef
@@ -103,11 +103,11 @@ define Build/patch-cmdline
 endef
 
 define Build/append-kernel
-       dd if=$(IMAGE_KERNEL) $(if $(1),bs=$(1) conv=sync) >> $@
+       dd if=$(IMAGE_KERNEL) >> $@
 endef
 
 define Build/append-rootfs
-       dd if=$(IMAGE_ROOTFS) $(if $(1),bs=$(1) conv=sync) >> $@
+       dd if=$(IMAGE_ROOTFS) >> $@
 endef
 
 define Build/append-ubi
@@ -117,7 +117,7 @@ define Build/append-ubi
                $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
                $(IMAGE_ROOTFS) \
                $@.tmp \
-               -p $(BLOCKSIZE) -m $(PAGESIZE) \
+               -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
                $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
                $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
                $(UBINIZE_OPTS)
@@ -130,15 +130,20 @@ define Build/pad-to
        mv $@.new $@
 endef
 
+define Build/pad-extra
+       dd if=/dev/zero bs=$(1) count=1 >> $@
+endef
+
 define Build/pad-rootfs
-       $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) 4 8 16 64 128 256
+       $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
+               $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
 endef
 
 define Build/pad-offset
        let \
                size="$$(stat -c%s $@)" \
-               pad="$(word 1, $(1))" \
-               offset="$(word 2, $(1))" \
+               pad="$(subst k,* 1024,$(word 1, $(1)))" \
+               offset="$(subst k,* 1024,$(word 2, $(1)))" \
                pad="(pad - ((size + offset) % pad)) % pad" \
                newsize='size + pad'; \
                dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
@@ -167,3 +172,26 @@ define Build/sysupgrade-tar
                --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
                $@
 endef
+
+json_quote=$(subst ','\'',$(subst ",\",$(1)))
+#")')
+metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
+metadata_json = \
+       '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
+               "supported_devices":[$(call metadata_devices,$(1))], \
+               "version": { \
+                       "dist": "$(call json_quote,$(VERSION_DIST))", \
+                       "version": "$(call json_quote,$(VERSION_NUMBER))", \
+                       "revision": "$(call json_quote,$(REVISION))", \
+                       "board": "$(call json_quote,$(BOARD))" \
+               } \
+       }'
+
+define Build/append-metadata
+       $(if $(SUPPORTED_DEVICES),echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
+endef
+
+define Build/kernel2minor
+       kernel2minor -k $@ -r $@.new $(1)
+       mv $@.new $@
+endef