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

Paul Spooren mail at aparcar.org
Wed Jul 8 15:34:02 EDT 2020


TL;DR: I think the issue is solved for devices using DT, the problem are 
the other targets with custom solutions.

I think there is a policy for new DT devices to use the compatible 
string as profile.

Multiple targets contain the following line in the target Makefile, 
which automatically adds the profile name as supported device:

SUPPORTED_DEVICES := $(subst _,$(comma),$(1))

So ideally for all devices using DT, the profile and compatible string 
are the same except for '_' replaced by ','.

For instance, the "Linksys WRT3200ACM" has the profile ID 
`linksys_wrt3200acm` and the automatically added compatible string 
`linksys,wrt3200acm`. So if that device wanted to search the 
`mvebu/cortexa9/profiles.json` for available sysupgrades, it takes the 
first entry from /proc/device-tree/compatible, replaces ',' with '_' 
find images in profiles.json['profiles']['linksys_wrt3200acm']['images'].

For cases where DT compatible and OpenWrt profile ID/name where 
different either one was patched[0].

I think the question is therefore more on how to deal with devices that 
do not use DT? If we use a per device rootfs a line could be added to 
/etc/os-release containing something like 
OPENWRT_PROFILE="SpEcIaL-CaSEv100", which is then shown via `ubus call 
system borad`.

Another hack could be to add it to /proc/cmdline?

[0]: 
https://github.com/openwrt/openwrt/commit/df6f3090c48e3bafa0ace7450488b0a20a8074fb

On 08.07.20 05:09, Rafał Miłecki wrote:
> 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=(",", ":")))



More information about the openwrt-devel mailing list