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

mail at adrianschmutzler.de mail at adrianschmutzler.de
Fri Jul 10 10:23:58 EDT 2020


> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of Rafal Milecki
> Sent: Mittwoch, 8. Juli 2020 17:10
> To: openwrt-devel at lists.openwrt.org
> Cc: Rafał Miłecki <rafal at milecki.pl>; Adrian Schmutzler
> <freifunk at adrianschmutzler.de>; Petr Štetiar <ynezz at true.cz>; Moritz
> Warning <moritzwarning at web.de>; Paul Spooren <mail at aparcar.org>
> Subject: [PATCH] build: put DT "compatible" value as "board_name" in
> profiles.json
> 
> 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

Hi,

coming back to the initial subject of your patch:

As stated earlier in the discussion (I think), we have "SUPPORTED_DEVICES" on many devices that will essentially give us the board name.
So, one could say, the first entry of SUPPORTED_DEVICES just happens to be the board name (as that one is designed to match the current compatible ...).

So, instead of establishing another mechanism to retrieve the board name in this patch (which might have several special cases etc.), I'd vote for just providing SUPPORTED_DEVICES for the remaining devices, even if it's not required for the upgrade mechanism itself.
This would allow us to benefit from what's set up already, and would allow to make target-specific solutions for the remaining cases (in some cases it might be just a one-liner in Device/Default).

Best

Adrian

> 
>  json_path.write_text(json.dumps(image_info, separators=(",", ":")))
> --
> 2.26.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20200710/ccb80e17/attachment-0001.sig>


More information about the openwrt-devel mailing list