Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 60b2fd0

Browse files
committed
Backport JSON info files patch
While unmerged, patch it here openwrt/openwrt#2192 Signed-off-by: Paul Spooren <[email protected]>
1 parent 20e9145 commit 60b2fd0

File tree

5 files changed

+395
-2
lines changed

5 files changed

+395
-2
lines changed

example-snapshot.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export VERSION="snapshot"
33
export TARGET="ath79/generic"
44
export PROFILE="etactica_eg200"
55
export PACKAGES="tmux htop"
6-
7-
./meta image
6+
./meta info
7+
#./meta image

meta

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,7 @@ make "$1" \
205205
EXTRA_IMAGE_NAME="$EXTRA_IMAGE_NAME" \
206206
FILES="$FILES"
207207
)
208+
209+
#[ "$1" = "image" ] && (cd "$IB_DIR" &&
210+
#make "jsonmergeimageinfo" OUTPUT_DIR="$ROOT_DIR/bin/$DISTRO/$VERSION_PATH"
211+
#)
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
From f9777b0434a1854e723026347b3e06b19d8a456b 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 1/2] 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-ath79-generic-tplink_tl-wdr3600-v1.json
13+
14+
{
15+
"id": "tplink_tl-wdr3600-v1",
16+
"image_prefix": "openwrt-ath79-generic-tplink_tl-wdr3600-v1",
17+
"image_size": "7936k",
18+
"images": [
19+
{
20+
"name": "openwrt-ath79-generic-tplink_tl-wdr3600-v1-squashfs-sysupgrade.bin",
21+
"sha256": "60ef977447d57ffe406f1f6170860be8043654d961933b73645850b25c6a1990",
22+
"type": "sysupgrade"
23+
},
24+
{
25+
"name": "openwrt-ath79-generic-tplink_tl-wdr3600-v1-squashfs-factory.bin",
26+
"sha256": "c6fae436b13f512e65ef05c0ae94308dd1cc9e20fd929dd3e0422574fe58d2b5",
27+
"type": "factory"
28+
}
29+
],
30+
"metadata_version": 1,
31+
"model": "TL-WDR3600",
32+
"supported_devices": [
33+
"tplink,tl-wdr3600-v1",
34+
"tl-wdr4300"
35+
],
36+
"target": "ath79/generic",
37+
"title": [
38+
"TP-Link TL-WDR3600 v1"
39+
],
40+
"variant": "v1",
41+
"vendor": "TP-Link",
42+
"version_commit": "r10764-84c103509a",
43+
"version_number": "SNAPSHOT"
44+
}
45+
46+
Signed-off-by: Paul Spooren <[email protected]>
47+
---
48+
config/Config-build.in | 7 +++++
49+
include/image.mk | 25 ++++++++++++++++-
50+
scripts/json_add_image_info.py | 51 ++++++++++++++++++++++++++++++++++
51+
3 files changed, 82 insertions(+), 1 deletion(-)
52+
create mode 100755 scripts/json_add_image_info.py
53+
54+
diff --git a/include/image.mk b/include/image.mk
55+
index c6a6ab7993..cfb2e2a90a 100644
56+
--- a/include/image.mk
57+
+++ b/include/image.mk
58+
@@ -554,7 +554,28 @@ define Device/Build/image
59+
60+
$(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
61+
cp $$^ $$@
62+
-
63+
+ $(if $(CONFIG_JSON_ADD_IMAGE_INFO), \
64+
+ DEVICE_ID="$(DEVICE_NAME)" \
65+
+ TOPDIR="$(TOPDIR)" \
66+
+ BIN_DIR="$(BIN_DIR)" \
67+
+ IMAGE_NAME="$(IMAGE_NAME)" \
68+
+ IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
69+
+ IMAGE_SIZE="$(IMAGE_SIZE)" \
70+
+ IMAGE_PREFIX="$(IMAGE_PREFIX)" \
71+
+ DEVICE_TITLE="$(DEVICE_TITLE)" \
72+
+ DEVICE_VENDOR="$(DEVICE_VENDOR)" \
73+
+ DEVICE_MODEL="$(DEVICE_MODEL)" \
74+
+ DEVICE_VARIANT="$(DEVICE_VARIANT)" \
75+
+ DEVICE_ALT0_TITLE="$(DEVICE_ALT0_TITLE)" \
76+
+ DEVICE_ALT1_TITLE="$(DEVICE_ALT1_TITLE)" \
77+
+ DEVICE_ALT2_TITLE="$(DEVICE_ALT2_TITLE)" \
78+
+ TARGET="$(BOARD)" \
79+
+ SUBTARGET="$(SUBTARGET)" \
80+
+ VERSION_NUMBER="$(VERSION_NUMBER)" \
81+
+ VERSION_CODE="$(VERSION_CODE)" \
82+
+ SUPPORTED_DEVICES="$(SUPPORTED_DEVICES)" \
83+
+ $(TOPDIR)/scripts/json_add_image_info.py \
84+
+ )
85+
endef
86+
87+
define Device/Build/artifact
88+
@@ -572,6 +593,8 @@ define Device/Build/artifact
89+
endef
90+
91+
define Device/Build
92+
+ $(if $(CONFIG_JSON_ADD_IMAGE_INFO), $(shell rm -f $(BIN_DIR)/$(IMG_PREFIX)-$(1).json))
93+
+
94+
$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
95+
$(call Device/Build/kernel,$(1))
96+
97+
diff --git a/scripts/json_add_image_info.py b/scripts/json_add_image_info.py
98+
new file mode 100755
99+
index 0000000000..31b8d1c123
100+
--- /dev/null
101+
+++ b/scripts/json_add_image_info.py
102+
@@ -0,0 +1,51 @@
103+
+#!/usr/bin/env python3
104+
+
105+
+import json
106+
+import os
107+
+import hashlib
108+
+
109+
+
110+
+def e(variable):
111+
+ return os.environ.get(variable)
112+
+
113+
+
114+
+json_path = "{}{}{}.json".format(e("BIN_DIR"), os.sep, e("IMAGE_PREFIX"))
115+
+
116+
+with open(os.path.join(e("BIN_DIR"), e("IMAGE_NAME")), "rb") as image_file:
117+
+ image_hash = hashlib.sha256(image_file.read()).hexdigest()
118+
+
119+
+if not os.path.exists(json_path):
120+
+ device_info = {
121+
+ "id": e("DEVICE_ID"),
122+
+ "image_prefix": e("IMAGE_PREFIX"),
123+
+ "image_size": e("IMAGE_SIZE"),
124+
+ "images": [],
125+
+ "metadata_version": 1,
126+
+ "model": e("DEVICE_MODEL"),
127+
+ "supported_devices": e("SUPPORTED_DEVICES").split(),
128+
+ "target": "{}/{}".format(e("TARGET"), e("SUBTARGET")),
129+
+ "title": list(
130+
+ filter(
131+
+ None,
132+
+ [
133+
+ e("DEVICE_TITLE"),
134+
+ e("DEVICE_ALT0_TITLE"),
135+
+ e("DEVICE_ALT1_TITLE"),
136+
+ e("DEVICE_ALT2_TITLE"),
137+
+ ],
138+
+ )
139+
+ ),
140+
+ "variant": e("DEVICE_VARIANT"),
141+
+ "vendor": e("DEVICE_VENDOR"),
142+
+ "version_commit": e("VERSION_CODE"),
143+
+ "version_number": e("VERSION_NUMBER"),
144+
+ }
145+
+else:
146+
+ with open(json_path, "r") as json_file:
147+
+ device_info = json.load(json_file)
148+
+
149+
+image_info = {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash}
150+
+device_info["images"].append(image_info)
151+
+
152+
+with open(json_path, "w") as json_file:
153+
+ json.dump(device_info, json_file, sort_keys=True, indent=" ")
154+
--
155+
2.20.1
156+

0 commit comments

Comments
 (0)