Skip to content

Commit 881ed09

Browse files
aparcardangowrt
authored andcommitted
build: create JSON files containing image info
The JSON info files contain details about the created firmware images per device and are stored next to the created images. The JSON files are stored as "$(IMAGE_PREFIX).json" and contain some device/image meta data as well as a list of created firmware images. An example of openwrt-ramips-rt305x-aztech_hw550-3g.json { "id": "aztech_hw550-3g", "image_prefix": "openwrt-ramips-rt305x-aztech_hw550-3g", "images": [ { "name": "openwrt-ramips-rt305x-aztech_hw550-3g-squashfs-sysupgrade.bin", "sha256": "db2b34b0ec4a83d9bf612cf66fab0dc3722b191cb9bedf111e5627a4298baf20", "type": "sysupgrade" } ], "metadata_version": 1, "supported_devices": [ "aztech,hw550-3g", "hw550-3g" ], "target": "ramips/rt305x", "titles": [ { "model": "HW550-3G", "vendor": "Aztech" }, { "model": "ALL0239-3G", "vendor": "Allnet" } ], "version_commit": "r10920+123-0cc87b3bac", "version_number": "SNAPSHOT" } Signed-off-by: Paul Spooren <[email protected]>
1 parent eba0db9 commit 881ed09

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

config/Config-build.in

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
menu "Global build settings"
99

10+
config JSON_ADD_IMAGE_INFO
11+
bool "Create JSON info files per build image"
12+
default BUILDBOT
13+
help
14+
The JSON info files contain information about the device and
15+
build images, stored next to the firmware images.
16+
1017
config ALL_NONSHARED
1118
bool "Select all target specific packages by default"
1219
select ALL_KMODS

include/image.mk

+28-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,32 @@ define Device/Build/image
571571

572572
$(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
573573
cp $$^ $$@
574-
574+
$(if $(CONFIG_JSON_ADD_IMAGE_INFO), \
575+
DEVICE_ID="$(DEVICE_NAME)" \
576+
BIN_DIR="$(BIN_DIR)" \
577+
IMAGE_NAME="$(IMAGE_NAME)" \
578+
IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
579+
IMAGE_PREFIX="$(IMAGE_PREFIX)" \
580+
DEVICE_VENDOR="$(DEVICE_VENDOR)" \
581+
DEVICE_MODEL="$(DEVICE_MODEL)" \
582+
DEVICE_VARIANT="$(DEVICE_VARIANT)" \
583+
DEVICE_ALT0_VENDOR="$(DEVICE_ALT0_VENDOR)" \
584+
DEVICE_ALT0_MODEL="$(DEVICE_ALT0_MODEL)" \
585+
DEVICE_ALT0_VARIANT="$(DEVICE_ALT0_VARIANT)" \
586+
DEVICE_ALT1_VENDOR="$(DEVICE_ALT1_VENDOR)" \
587+
DEVICE_ALT1_MODEL="$(DEVICE_ALT1_MODEL)" \
588+
DEVICE_ALT1_VARIANT="$(DEVICE_ALT1_VARIANT)" \
589+
DEVICE_ALT2_VENDOR="$(DEVICE_ALT2_VENDOR)" \
590+
DEVICE_ALT2_MODEL="$(DEVICE_ALT2_MODEL)" \
591+
DEVICE_ALT2_VARIANT="$(DEVICE_ALT2_VARIANT)" \
592+
DEVICE_TITLE="$(DEVICE_TITLE)" \
593+
TARGET="$(BOARD)" \
594+
SUBTARGET="$(SUBTARGET)" \
595+
VERSION_NUMBER="$(VERSION_NUMBER)" \
596+
VERSION_CODE="$(VERSION_CODE)" \
597+
SUPPORTED_DEVICES="$(SUPPORTED_DEVICES)" \
598+
$(TOPDIR)/scripts/json_add_image_info.py \
599+
)
575600
endef
576601

577602
define Device/Build/artifact
@@ -589,6 +614,8 @@ define Device/Build/artifact
589614
endef
590615

591616
define Device/Build
617+
$(shell rm -f $(BIN_DIR)/$(IMG_PREFIX)-$(1).json)
618+
592619
$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
593620
$(call Device/Build/kernel,$(1))
594621

scripts/json_add_image_info.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import os
5+
import hashlib
6+
7+
8+
def e(variable, default=None):
9+
return os.environ.get(variable, default)
10+
11+
12+
json_path = "{}{}{}.json".format(e("BIN_DIR"), os.sep, e("IMAGE_PREFIX"))
13+
14+
with open(os.path.join(e("BIN_DIR"), e("IMAGE_NAME")), "rb") as image_file:
15+
image_hash = hashlib.sha256(image_file.read()).hexdigest()
16+
17+
18+
def get_titles():
19+
titles = []
20+
for prefix in ["", "ALT0_", "ALT1_", "ALT2_"]:
21+
title = {}
22+
for var in ["vendor", "model", "variant"]:
23+
if e("DEVICE_{}{}".format(prefix, var.upper())):
24+
title[var] = e("DEVICE_{}{}".format(prefix, var.upper()))
25+
26+
if title:
27+
titles.append(title)
28+
29+
if not titles:
30+
titles.append({"title": e("DEVICE_TITLE")})
31+
32+
return titles
33+
34+
35+
if not os.path.exists(json_path):
36+
device_info = {
37+
"id": e("DEVICE_ID"),
38+
"image_prefix": e("IMAGE_PREFIX"),
39+
"images": [],
40+
"metadata_version": 1,
41+
"supported_devices": e("SUPPORTED_DEVICES").split(),
42+
"target": "{}/{}".format(e("TARGET"), e("SUBTARGET", "generic")),
43+
"titles": get_titles(),
44+
"version_commit": e("VERSION_CODE"),
45+
"version_number": e("VERSION_NUMBER"),
46+
}
47+
else:
48+
with open(json_path, "r") as json_file:
49+
device_info = json.load(json_file)
50+
51+
image_info = {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash}
52+
device_info["images"].append(image_info)
53+
54+
with open(json_path, "w") as json_file:
55+
json.dump(device_info, json_file, sort_keys=True, indent=" ")

0 commit comments

Comments
 (0)