|
| 1 | +From c3767e8d7d659e099bb6c23076793ac2cde72663 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Paul Spooren < [email protected]> |
| 3 | +Date: Sun, 18 Aug 2019 09:56:45 -1000 |
| 4 | +Subject: [PATCH] build: create JSON files containing image info |
| 5 | + |
| 6 | +The JSON info files contain details about the created firmware images |
| 7 | +per device and are stored next to the created images. |
| 8 | + |
| 9 | +The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some |
| 10 | +device/image meta data as well as a list of created firmware images. |
| 11 | + |
| 12 | +An example of openwrt-ramips-rt305x-aztech_hw550-3g.json |
| 13 | + |
| 14 | + { |
| 15 | + "id": "aztech_hw550-3g", |
| 16 | + "image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g", |
| 17 | + "images": [ |
| 18 | + { |
| 19 | + "name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin", |
| 20 | + "sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20", |
| 21 | + "type": "sysupgrade" |
| 22 | + } |
| 23 | + ], |
| 24 | + "metadata_version": 1, |
| 25 | + "supported_devices": [ |
| 26 | + "aztech,hw550-3g", |
| 27 | + "hw550-3g" |
| 28 | + ], |
| 29 | + "target": "ramips/rt305x", |
| 30 | + "titles": [ |
| 31 | + { |
| 32 | + "model": "HW550-3G", |
| 33 | + "vendor": "Aztech" |
| 34 | + }, |
| 35 | + { |
| 36 | + "model": "ALL0239-3G", |
| 37 | + "vendor": "Allnet" |
| 38 | + } |
| 39 | + ], |
| 40 | + "version_commit": "r10920+123-0cc87b3bac", |
| 41 | + "version_number": "SNAPSHOT" |
| 42 | + } |
| 43 | + |
| 44 | +Signed-off-by: Paul Spooren < [email protected]> |
| 45 | +--- |
| 46 | + include/image.mk | 30 ++++++++++++++++++- |
| 47 | + scripts/json_add_image_info.py | 55 ++++++++++++++++++++++++++++++++++ |
| 48 | + 3 files changed, 91 insertions(+), 1 deletion(-) |
| 49 | + create mode 100755 scripts/json_add_image_info.py |
| 50 | + |
| 51 | +diff --git a/include/image.mk b/include/image.mk |
| 52 | +index 5d54bc7947..7608b86adc 100644 |
| 53 | +--- a/include/image.mk |
| 54 | ++++ b/include/image.mk |
| 55 | +@@ -571,7 +571,33 @@ define Device/Build/image |
| 56 | + |
| 57 | + $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)) |
| 58 | + cp $$^ $$@ |
| 59 | +- |
| 60 | ++ $(if $(CONFIG_JSON_ADD_IMAGE_INFO), \ |
| 61 | ++ DEVICE_ID="$(DEVICE_NAME)" \ |
| 62 | ++ TOPDIR="$(TOPDIR)" \ |
| 63 | ++ BIN_DIR="$(BIN_DIR)" \ |
| 64 | ++ IMAGE_NAME="$(IMAGE_NAME)" \ |
| 65 | ++ IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \ |
| 66 | ++ IMAGE_PREFIX="$(IMAGE_PREFIX)" \ |
| 67 | ++ DEVICE_VENDOR="$(DEVICE_VENDOR)" \ |
| 68 | ++ DEVICE_MODEL="$(DEVICE_MODEL)" \ |
| 69 | ++ DEVICE_VARIANT="$(DEVICE_VARIANT)" \ |
| 70 | ++ DEVICE_ALT0_VENDOR="$(DEVICE_ALT0_VENDOR)" \ |
| 71 | ++ DEVICE_ALT0_MODEL="$(DEVICE_ALT0_MODEL)" \ |
| 72 | ++ DEVICE_ALT0_VARIANT="$(DEVICE_ALT0_VARIANT)" \ |
| 73 | ++ DEVICE_ALT1_VENDOR="$(DEVICE_ALT1_VENDOR)" \ |
| 74 | ++ DEVICE_ALT1_MODEL="$(DEVICE_ALT1_MODEL)" \ |
| 75 | ++ DEVICE_ALT1_VARIANT="$(DEVICE_ALT1_VARIANT)" \ |
| 76 | ++ DEVICE_ALT2_VENDOR="$(DEVICE_ALT2_VENDOR)" \ |
| 77 | ++ DEVICE_ALT2_MODEL="$(DEVICE_ALT2_MODEL)" \ |
| 78 | ++ DEVICE_ALT2_VARIANT="$(DEVICE_ALT2_VARIANT)" \ |
| 79 | ++ DEVICE_TITLE="$(DEVICE_TITLE)" \ |
| 80 | ++ TARGET="$(BOARD)" \ |
| 81 | ++ SUBTARGET="$(SUBTARGET)" \ |
| 82 | ++ VERSION_NUMBER="$(VERSION_NUMBER)" \ |
| 83 | ++ VERSION_CODE="$(VERSION_CODE)" \ |
| 84 | ++ SUPPORTED_DEVICES="$(SUPPORTED_DEVICES)" \ |
| 85 | ++ $(TOPDIR)/scripts/json_add_image_info.py \ |
| 86 | ++ ) |
| 87 | + endef |
| 88 | + |
| 89 | + define Device/Build/artifact |
| 90 | +@@ -589,6 +615,8 @@ define Device/Build/artifact |
| 91 | + endef |
| 92 | + |
| 93 | + define Device/Build |
| 94 | ++ $(shell rm -f $(BIN_DIR)/$(IMG_PREFIX)-$(1).json) |
| 95 | ++ |
| 96 | + $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1))) |
| 97 | + $(call Device/Build/kernel,$(1)) |
| 98 | + |
| 99 | +diff --git a/scripts/json_add_image_info.py b/scripts/json_add_image_info.py |
| 100 | +new file mode 100755 |
| 101 | +index 0000000000..44b4031f85 |
| 102 | +--- /dev/null |
| 103 | ++++ b/scripts/json_add_image_info.py |
| 104 | +@@ -0,0 +1,55 @@ |
| 105 | ++#!/usr/bin/env python3 |
| 106 | ++ |
| 107 | ++import json |
| 108 | ++import os |
| 109 | ++import hashlib |
| 110 | ++ |
| 111 | ++ |
| 112 | ++def e(variable, default=None): |
| 113 | ++ return os.environ.get(variable, default) |
| 114 | ++ |
| 115 | ++ |
| 116 | ++json_path = "{}{}{}.json".format(e("BIN_DIR"), os.sep, e("IMAGE_PREFIX")) |
| 117 | ++ |
| 118 | ++with open(os.path.join(e("BIN_DIR"), e("IMAGE_NAME")), "rb") as image_file: |
| 119 | ++ image_hash = hashlib.sha256(image_file.read()).hexdigest() |
| 120 | ++ |
| 121 | ++ |
| 122 | ++def get_titles(): |
| 123 | ++ titles = [] |
| 124 | ++ for prefix in ["", "ALT0_", "ALT1_", "ALT2_"]: |
| 125 | ++ title = {} |
| 126 | ++ for var in ["vendor", "model", "variant"]: |
| 127 | ++ if e("DEVICE_{}{}".format(prefix, var.upper())): |
| 128 | ++ title[var] = e("DEVICE_{}{}".format(prefix, var.upper())) |
| 129 | ++ |
| 130 | ++ if title: |
| 131 | ++ titles.append(title) |
| 132 | ++ |
| 133 | ++ if not titles: |
| 134 | ++ titles.append({"title": e("DEVICE_TITLE")}) |
| 135 | ++ |
| 136 | ++ return titles |
| 137 | ++ |
| 138 | ++ |
| 139 | ++if not os.path.exists(json_path): |
| 140 | ++ device_info = { |
| 141 | ++ "id": e("DEVICE_ID"), |
| 142 | ++ "image_prefix": e("IMAGE_PREFIX"), |
| 143 | ++ "images": [], |
| 144 | ++ "metadata_version": 1, |
| 145 | ++ "supported_devices": e("SUPPORTED_DEVICES").split(), |
| 146 | ++ "target": "{}/{}".format(e("TARGET"), e("SUBTARGET", "generic")), |
| 147 | ++ "titles": get_titles(), |
| 148 | ++ "version_commit": e("VERSION_CODE"), |
| 149 | ++ "version_number": e("VERSION_NUMBER"), |
| 150 | ++ } |
| 151 | ++else: |
| 152 | ++ with open(json_path, "r") as json_file: |
| 153 | ++ device_info = json.load(json_file) |
| 154 | ++ |
| 155 | ++image_info = {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash} |
| 156 | ++device_info["images"].append(image_info) |
| 157 | ++ |
| 158 | ++with open(json_path, "w") as json_file: |
| 159 | ++ json.dump(device_info, json_file, sort_keys=True, indent=" ") |
| 160 | +-- |
| 161 | +2.23.0 |
| 162 | + |
0 commit comments