Message ID | 20250929144721.1001156-2-kavinaya@qti.qualcomm.com |
---|---|
State | New |
Headers | show |
Series | Add support for custom compatible string via optional parameter | expand |
On Mon, 29 Sept 2025 at 16:47, Kavinaya S via lists.openembedded.org <kavinaya=qti.qualcomm.com@lists.openembedded.org> wrote: > > Currently, fitimage_emit_section_dtb() always derives the 'compatible' > property from the DTB using fdtget when add_compatible=True. In some > cases, it is desirable to override this with a custom compatible string > defined in the build metadata. > > This patch introduces an optional 'custom_compatible' parameter to > fitimage_emit_section_dtb(). When provided, this value is used instead > of extracting from the DTB. The parameter accepts either a space- > separated string or a list of strings, which are split into the > compatible array for the ITS node. This looks much better, thanks! But it still needs a bit of work. > # 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"COMPATIBLE:{dtb_name}") COMPATIBLE is really not an appropriate name. It should be much more specific, e.g. DTB_CUSTOM_COMPATIBLE, or something even more detailed. > - dtbo_loadaddress=None, add_compatible=False): > + dtbo_loadaddress=None, add_compatible=False, custom_compatible=False): custom_compatible is not a boolean parameter, it's a string. If it isn't supplied, set the default to None. > if add_compatible: > - compatible = get_compatible_from_dtb(dtb_path) > + if custom_compatible: > + # Accept either a string (space-separated) or an iterable of strings > + if isinstance(custom_compatible, (list, tuple)): > + compatible = list(custom_compatible) > + else: > + compatible = str(custom_compatible).split() I don't understand. d.getVar() returns a string. At which point custom_compatible turns into a list or a tuple? That's why I had asked you to also make tests for this feature. Alex
On Mon, Sep 29, 2025 at 08:26 PM, Alexander Kanavin wrote: > > COMPATIBLE is really not an appropriate name. It should be much more > specific, e.g. DTB_CUSTOM_COMPATIBLE, or something even more detailed. > Hi Alex, Sure. I will update COMPATIBLE to DTB_CUSTOM_COMPATIBLE > > > > - dtbo_loadaddress=None, add_compatible=False): > > + dtbo_loadaddress=None, add_compatible=False, custom_compatible=False): > > custom_compatible is not a boolean parameter, it's a string. If it > isn't supplied, set the default to None. > Sure > > > > if add_compatible: > > - compatible = get_compatible_from_dtb(dtb_path) > > + if custom_compatible: > > + # Accept either a string (space-separated) or an iterable of strings > > + if isinstance(custom_compatible, (list, tuple)): > > + compatible = list(custom_compatible) > > + else: > > + compatible = str(custom_compatible).split() > > I don't understand. d.getVar() returns a string. At which point > custom_compatible turns into a list or a tuple? > I will update this logic as well. > That's why I had asked you to also make tests for this feature. > I will add tests as well. Thanks Alex
diff --git a/meta/classes-recipe/kernel-fit-image.bbclass b/meta/classes-recipe/kernel-fit-image.bbclass index f04aee1807..08b05f7aed 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"COMPATIBLE:{dtb_name}") 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..16fa0de9fa 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: +# +# COMPATIBLE:<dtb-filename.dtb> = "custom-compatible-string" diff --git a/meta/lib/oe/fitimage.py b/meta/lib/oe/fitimage.py index f303799155..2ff39e9e62 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=False): """Emit the fitImage ITS DTB section""" load=None dtb_ext = os.path.splitext(dtb_path)[1] @@ -309,7 +309,15 @@ 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 custom_compatible: + # Accept either a string (space-separated) or an iterable of strings + if isinstance(custom_compatible, (list, tuple)): + compatible = list(custom_compatible) + else: + compatible = str(custom_compatible).split() + else: + compatible = get_compatible_from_dtb(dtb_path) + dtb_node = self.its_add_node_dtb( "fdt-" + dtb_id,
Currently, fitimage_emit_section_dtb() always derives the 'compatible' property from the DTB using fdtget when add_compatible=True. In some cases, it is desirable to override this with a custom compatible string defined in the build metadata. This patch introduces an optional 'custom_compatible' parameter to fitimage_emit_section_dtb(). When provided, this value is used instead of extracting from the DTB. The parameter accepts either a space- separated string or a list of strings, which are split into the compatible array for the ITS node. 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 | 12 ++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)