> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org]
> On Behalf Of Rafal Milecki
> Sent: Mittwoch, 8. Juli 2020 17:10
> To: openwrt-devel@lists.openwrt.org
> Cc: Rafał Miłecki <ra...@milecki.pl>; Adrian Schmutzler
> <freif...@adrianschmutzler.de>; Petr Štetiar <yn...@true.cz>; Moritz
> Warning <moritzwarn...@web.de>; Paul Spooren <m...@aparcar.org>
> Subject: [PATCH] build: put DT "compatible" value as "board_name" in
> profiles.json
> 
> From: Rafał Miłecki <ra...@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 <ra...@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@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Attachment: openpgp-digital-signature.asc
Description: PGP signature

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to