build: add support code for appending metadata to images
[openwrt/openwrt.git] / include / image-commands.mk
index 7ff4c217a345e10a2a399e56fa45bc4ff3644209..083a3890316c633e9a1ffaab6bd7790ebb29ea34 100644 (file)
@@ -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
@@ -172,3 +172,21 @@ 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