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

Commit eeb3086

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 eeb3086

File tree

5 files changed

+409
-2
lines changed

5 files changed

+409
-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: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
From c3ee249db446c05e8b427c7691e8a85f4b91622b 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+
"images": [
18+
{
19+
"name": "openwrt-ath79-generic-tplink_tl-wdr3600-v1-squashfs-sysupgrade.bin",
20+
"sha256": "60ef977447d57ffe406f1f6170860be8043654d961933b73645850b25c6a1990",
21+
"type": "sysupgrade"
22+
},
23+
{
24+
"name": "openwrt-ath79-generic-tplink_tl-wdr3600-v1-squashfs-factory.bin",
25+
"sha256": "c6fae436b13f512e65ef05c0ae94308dd1cc9e20fd929dd3e0422574fe58d2b5",
26+
"type": "factory"
27+
}
28+
],
29+
"metadata_version": 1,
30+
"model": "TL-WDR3600",
31+
"supported_devices": [
32+
"tplink,tl-wdr3600-v1",
33+
"tl-wdr4300"
34+
],
35+
"target": "ath79/generic",
36+
"title": [
37+
"TP-Link TL-WDR3600 v1"
38+
],
39+
"variant": "v1",
40+
"vendor": "TP-Link",
41+
"version_commit": "r10764-84c103509a",
42+
"version_number": "SNAPSHOT"
43+
}
44+
45+
Signed-off-by: Paul Spooren <[email protected]>
46+
---
47+
config/Config-build.in | 7 +++++
48+
include/image.mk | 24 +++++++++++++++-
49+
scripts/json_add_image_info.py | 50 ++++++++++++++++++++++++++++++++++
50+
3 files changed, 80 insertions(+), 1 deletion(-)
51+
create mode 100755 scripts/json_add_image_info.py
52+
53+
diff --git a/config/Config-build.in b/config/Config-build.in
54+
index 35341833e3..ecd68a6ec3 100644
55+
--- a/config/Config-build.in
56+
+++ b/config/Config-build.in
57+
@@ -7,6 +7,13 @@
58+
59+
menu "Global build settings"
60+
61+
+ config JSON_ADD_IMAGE_INFO
62+
+ bool "Create JSON info files per build image"
63+
+ default y
64+
+ help
65+
+ The JSON info files contain information about the device and
66+
+ build images, stored next to the firmware images.
67+
+
68+
config ALL_NONSHARED
69+
bool "Select all target specific packages by default"
70+
select ALL_KMODS
71+
diff --git a/include/image.mk b/include/image.mk
72+
index 599adfaa10..b4385290bb 100644
73+
--- a/include/image.mk
74+
+++ b/include/image.mk
75+
@@ -571,7 +571,27 @@ define Device/Build/image
76+
77+
$(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
78+
cp $$^ $$@
79+
-
80+
+ $(if $(CONFIG_JSON_ADD_IMAGE_INFO), \
81+
+ DEVICE_ID="$(DEVICE_NAME)" \
82+
+ TOPDIR="$(TOPDIR)" \
83+
+ BIN_DIR="$(BIN_DIR)" \
84+
+ IMAGE_NAME="$(IMAGE_NAME)" \
85+
+ IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
86+
+ IMAGE_PREFIX="$(IMAGE_PREFIX)" \
87+
+ DEVICE_TITLE="$(DEVICE_TITLE)" \
88+
+ DEVICE_VENDOR="$(DEVICE_VENDOR)" \
89+
+ DEVICE_MODEL="$(DEVICE_MODEL)" \
90+
+ DEVICE_VARIANT="$(DEVICE_VARIANT)" \
91+
+ DEVICE_ALT0_TITLE="$(DEVICE_ALT0_TITLE)" \
92+
+ DEVICE_ALT1_TITLE="$(DEVICE_ALT1_TITLE)" \
93+
+ DEVICE_ALT2_TITLE="$(DEVICE_ALT2_TITLE)" \
94+
+ TARGET="$(BOARD)" \
95+
+ SUBTARGET="$(SUBTARGET)" \
96+
+ VERSION_NUMBER="$(VERSION_NUMBER)" \
97+
+ VERSION_CODE="$(VERSION_CODE)" \
98+
+ SUPPORTED_DEVICES="$(SUPPORTED_DEVICES)" \
99+
+ $(TOPDIR)/scripts/json_add_image_info.py \
100+
+ )
101+
endef
102+
103+
define Device/Build/artifact
104+
@@ -589,6 +609,8 @@ define Device/Build/artifact
105+
endef
106+
107+
define Device/Build
108+
+ $(shell rm -f $(BIN_DIR)/$(IMG_PREFIX)-$(1).json)
109+
+
110+
$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
111+
$(call Device/Build/kernel,$(1))
112+
113+
diff --git a/scripts/json_add_image_info.py b/scripts/json_add_image_info.py
114+
new file mode 100755
115+
index 0000000000..a868880942
116+
--- /dev/null
117+
+++ b/scripts/json_add_image_info.py
118+
@@ -0,0 +1,50 @@
119+
+#!/usr/bin/env python3
120+
+
121+
+import json
122+
+import os
123+
+import hashlib
124+
+
125+
+
126+
+def e(variable):
127+
+ return os.environ.get(variable)
128+
+
129+
+
130+
+json_path = "{}{}{}.json".format(e("BIN_DIR"), os.sep, e("IMAGE_PREFIX"))
131+
+
132+
+with open(os.path.join(e("BIN_DIR"), e("IMAGE_NAME")), "rb") as image_file:
133+
+ image_hash = hashlib.sha256(image_file.read()).hexdigest()
134+
+
135+
+if not os.path.exists(json_path):
136+
+ device_info = {
137+
+ "id": e("DEVICE_ID"),
138+
+ "image_prefix": e("IMAGE_PREFIX"),
139+
+ "images": [],
140+
+ "metadata_version": 1,
141+
+ "model": e("DEVICE_MODEL"),
142+
+ "supported_devices": e("SUPPORTED_DEVICES").split(),
143+
+ "target": "{}/{}".format(e("TARGET"), e("SUBTARGET")),
144+
+ "title": list(
145+
+ filter(
146+
+ None,
147+
+ [
148+
+ e("DEVICE_TITLE"),
149+
+ e("DEVICE_ALT0_TITLE"),
150+
+ e("DEVICE_ALT1_TITLE"),
151+
+ e("DEVICE_ALT2_TITLE"),
152+
+ ],
153+
+ )
154+
+ ),
155+
+ "variant": e("DEVICE_VARIANT"),
156+
+ "vendor": e("DEVICE_VENDOR"),
157+
+ "version_commit": e("VERSION_CODE"),
158+
+ "version_number": e("VERSION_NUMBER"),
159+
+ }
160+
+else:
161+
+ with open(json_path, "r") as json_file:
162+
+ device_info = json.load(json_file)
163+
+
164+
+image_info = {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash}
165+
+device_info["images"].append(image_info)
166+
+
167+
+with open(json_path, "w") as json_file:
168+
+ json.dump(device_info, json_file, sort_keys=True, indent=" ")
169+
--
170+
2.23.0.rc1
171+

0 commit comments

Comments
 (0)