[PATCH] build: put DT "compatible" value as "board_name" in profiles.json

Rafał Miłecki zajec5 at gmail.com
Wed Jul 8 11:09:34 EDT 2020


From: Rafał Miłecki <rafal at milecki.pl>

The purpose of "board_name" in JSON is matchine OpenWrt running device
with JSON profile entry. Right now it gets filled for devices using DT.
Other targets will require custom solutions or just speciyfing that
value manually.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 include/image.mk               |  3 +++
 scripts/json_add_image_info.py | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/image.mk b/include/image.mk
index 15f4fe9d3b..b33c1032f8 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -532,10 +532,13 @@ define Device/Build/image
 	@mkdir -p $$(shell dirname $$@)
 	DEVICE_ID="$(DEVICE_NAME)" \
 	BIN_DIR="$(BIN_DIR)" \
+	LINUX_DIR="$(LINUX_DIR)" \
+	KDIR="$(KDIR)" \
 	IMAGE_NAME="$(IMAGE_NAME)" \
 	IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
 	IMAGE_PREFIX="$(IMAGE_PREFIX)" \
 	DEVICE_TITLE="$(DEVICE_TITLE)" \
+	DEVICE_DTS="$(DEVICE_DTS)" \
 	TARGET="$(BOARD)" \
 	SUBTARGET="$(if $(SUBTARGET),$(SUBTARGET),generic)" \
 	VERSION_NUMBER="$(VERSION_NUMBER)" \
diff --git a/scripts/json_add_image_info.py b/scripts/json_add_image_info.py
index b4d2dd8d71..5df4bf2a2a 100755
--- a/scripts/json_add_image_info.py
+++ b/scripts/json_add_image_info.py
@@ -5,6 +5,8 @@ from pathlib import Path
 from sys import argv
 import hashlib
 import json
+import re
+import subprocess
 
 if len(argv) != 2:
     print("ERROR: JSON info script requires output arg")
@@ -22,6 +24,20 @@ if not image_file.is_file():
 def get_titles():
     return [{"title": getenv("DEVICE_TITLE")}]
 
+def get_board_name():
+    device_dts = getenv("DEVICE_DTS")
+    if device_dts is not None:
+        dtc = getenv("LINUX_DIR") + "/scripts/dtc/dtc"
+        dtb_file = getenv("KDIR") + "/image-" + device_dts + ".dtb"
+        dts = subprocess.run([dtc, "-q", "-I", "dtb", "-O", "dts", "-o", "-", dtb_file], capture_output=True, text=True)
+        if dts.returncode != 0:
+            return None
+        match = re.search("compatible = \"([^\"]*)", dts.stdout)
+        if match is None:
+            return None
+        return match[1]
+    return None
+
 
 device_id = getenv("DEVICE_ID")
 image_hash = hashlib.sha256(image_file.read_bytes()).hexdigest()
@@ -46,5 +62,8 @@ image_info = {
         }
     },
 }
+board_name = get_board_name()
+if board_name is not None:
+    image_info["profiles"][device_id]["board_name"] = board_name
 
 json_path.write_text(json.dumps(image_info, separators=(",", ":")))
-- 
2.26.1




More information about the openwrt-devel mailing list