diff mbox series

[v3,1/1] fitimage: Add support for custom compatible string via optional parameter

Message ID 20250929161225.1290751-2-kavinaya@qti.qualcomm.com
State New
Headers show
Series Add support for custom compatible string via optional parameter | expand

Commit Message

Kavinaya S Sept. 29, 2025, 4:12 p.m. UTC
Currently, fitimage_emit_section_dtb() always reads the 'compatible'
property from the DTB when add_compatible=True. This patch adds an
optional 'custom_compatible' parameter that, when set, overrides the
value from the DTB. If not provided, the existing behavior remains.

The compatible property is also skipped for DTBO nodes.

Suggested-By: Alexander Kanavin <alex.kanavin@gmail.com>
Signed-off-by: Kavinaya S <kavinaya@qti.qualcomm.com>
---
 meta/classes-recipe/kernel-fit-image.bbclass | 3 ++-
 meta/conf/image-fitimage.conf                | 6 ++++++
 meta/lib/oe/fitimage.py                      | 9 ++++++---
 3 files changed, 14 insertions(+), 4 deletions(-)

Comments

Alexander Kanavin Sept. 29, 2025, 5 p.m. UTC | #1
On Mon, 29 Sept 2025 at 18:12, Kavinaya S <kavinaya@qti.qualcomm.com> wrote:
>
> Currently, fitimage_emit_section_dtb() always reads the 'compatible'
> property from the DTB when add_compatible=True. This patch adds an
> optional 'custom_compatible' parameter that, when set, overrides the
> value from the DTB. If not provided, the existing behavior remains.

At this point you should explain *why* this is necessary. Present your
use case. Explain why the string coming from dtb doesn't work. Don't
be afraid to make the commit message very detailed or very long. The
more details, the more it helps reviewers or people looking at commit
history. I think some of it was previously discussed, and you can
reuse that.

> The compatible property is also skipped for DTBO nodes.

Why?

>  meta/classes-recipe/kernel-fit-image.bbclass | 3 ++-
>  meta/conf/image-fitimage.conf                | 6 ++++++
>  meta/lib/oe/fitimage.py                      | 9 ++++++---

Tests are missing. You will find existing tests in
meta/lib/oeqa/selftest/cases/fitimage.py
Look in particular for test_get_compatible_from_dtb(), and see if you
can extend or copy and tweak that.

> +            custom_compatible_str = d.getVar(f"FIT_DTB_COMPATIBLE_OVERRIDE:{dtb_name}") or None

I suspect you need to use _ here instad of : (but I don't have time to
verify it now).

: is used for bitbake overrides, and this is not one of them.

> +# To override the DTB 'compatible' string in the FIT image, add in your
> +# machine.conf or local.conf:
> +#
> +#  FIT_DTB_COMPATIBLE_OVERRIDE:<dtb-filename.dtb> = "custom-compatible-string"

Add:
# for example,
# <insert an actual working example line>

> diff --git a/meta/lib/oe/fitimage.py b/meta/lib/oe/fitimage.py
> index f303799155..0d42bca5d7 100644
> --- a/meta/lib/oe/fitimage.py
> +++ b/meta/lib/oe/fitimage.py
> @@ -289,7 +289,7 @@ class ItsNodeRootKernel(ItsNode):
>          self._kernel = kernel_node
>
>      def fitimage_emit_section_dtb(self, dtb_id, dtb_path, dtb_loadaddress=None,
> -                                  dtbo_loadaddress=None, add_compatible=False):
> +                                  dtbo_loadaddress=None, add_compatible=False, custom_compatible=None):
>          """Emit the fitImage ITS DTB section"""
>          load=None
>          dtb_ext = os.path.splitext(dtb_path)[1]
> @@ -308,8 +308,11 @@ class ItsNodeRootKernel(ItsNode):
>
>          # Preserve the DTB's compatible string to be added to the configuration node
>          compatible = None
> -        if add_compatible:
> -            compatible = get_compatible_from_dtb(dtb_path)
> +        if add_compatible and dtb_ext != ".dtbo":
> +            if custom_compatible:
> +                compatible = str(custom_compatible).split()
> +            else:
> +                compatible = get_compatible_from_dtb(dtb_path)

get_compatible_from_dtb() is also used in
fitimage_emit_section_dtb_alias(). Does that need to be fixed
similarly?

Alex
Kavinaya S Sept. 30, 2025, 6:11 a.m. UTC | #2
Hi Alex,

Thanks for the suggestions. I will upload a new patch with the suggestions.

Thanks,
Kavinaya
diff mbox series

Patch

diff --git a/meta/classes-recipe/kernel-fit-image.bbclass b/meta/classes-recipe/kernel-fit-image.bbclass
index f04aee1807..2a266242d0 100644
--- a/meta/classes-recipe/kernel-fit-image.bbclass
+++ b/meta/classes-recipe/kernel-fit-image.bbclass
@@ -84,8 +84,9 @@  python do_compile() {
 
             # Copy the dtb or dtbo file into the FIT image assembly directory
             shutil.copyfile(os.path.join(kernel_deploydir, dtb_name), dtb_name)
+            custom_compatible_str = d.getVar(f"FIT_DTB_COMPATIBLE_OVERRIDE:{dtb_name}") or None
             root_node.fitimage_emit_section_dtb(dtb_name, dtb_name,
-                d.getVar("UBOOT_DTB_LOADADDRESS"), d.getVar("UBOOT_DTBO_LOADADDRESS"))
+                d.getVar("UBOOT_DTB_LOADADDRESS"), d.getVar("UBOOT_DTBO_LOADADDRESS"), True, custom_compatible=custom_compatible_str)
 
     if external_kernel_devicetree:
         # iterate over all .dtb and .dtbo files in the external kernel devicetree directory
diff --git a/meta/conf/image-fitimage.conf b/meta/conf/image-fitimage.conf
index 090ee148f4..62f7bcde6c 100644
--- a/meta/conf/image-fitimage.conf
+++ b/meta/conf/image-fitimage.conf
@@ -65,3 +65,9 @@  FIT_ADDRESS_CELLS ?= "1"
 # Machine configurations needing such a script file should include it in the
 # SRC_URI of the kernel recipe and set the FIT_UBOOT_ENV parameter.
 FIT_UBOOT_ENV ?= ""
+
+
+# To override the DTB 'compatible' string in the FIT image, add in your
+# machine.conf or local.conf:
+#
+#  FIT_DTB_COMPATIBLE_OVERRIDE:<dtb-filename.dtb> = "custom-compatible-string"
diff --git a/meta/lib/oe/fitimage.py b/meta/lib/oe/fitimage.py
index f303799155..0d42bca5d7 100644
--- a/meta/lib/oe/fitimage.py
+++ b/meta/lib/oe/fitimage.py
@@ -289,7 +289,7 @@  class ItsNodeRootKernel(ItsNode):
         self._kernel = kernel_node
 
     def fitimage_emit_section_dtb(self, dtb_id, dtb_path, dtb_loadaddress=None,
-                                  dtbo_loadaddress=None, add_compatible=False):
+                                  dtbo_loadaddress=None, add_compatible=False, custom_compatible=None):
         """Emit the fitImage ITS DTB section"""
         load=None
         dtb_ext = os.path.splitext(dtb_path)[1]
@@ -308,8 +308,11 @@  class ItsNodeRootKernel(ItsNode):
 
         # Preserve the DTB's compatible string to be added to the configuration node
         compatible = None
-        if add_compatible:
-            compatible = get_compatible_from_dtb(dtb_path)
+        if add_compatible and dtb_ext != ".dtbo":
+            if custom_compatible:
+                compatible = str(custom_compatible).split()
+            else:
+                compatible = get_compatible_from_dtb(dtb_path)
 
         dtb_node = self.its_add_node_dtb(
             "fdt-" + dtb_id,