public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: AdrianF <adrian.freihofer@siemens.com>
To: openembedded-core@lists.openembedded.org
Cc: Adrian Freihofer <adrian.freihofer@siemens.com>
Subject: [PATCH 1/2] kernel-fitimage: Add FIT_CONF_MAPPINGS for flexible DTB configuration
Date: Thu, 18 Dec 2025 21:14:03 +0100	[thread overview]
Message-ID: <20251218201432.1608259-2-adrian.freihofer@siemens.com> (raw)
In-Reply-To: <20251218201432.1608259-1-adrian.freihofer@siemens.com>

From: Adrian Freihofer <adrian.freihofer@siemens.com>

Having a 1-1 mapping between DTB names and configuration nodes names in
FIT images does not always work. Make this a bit more flexible by
allowing users to specify mappings to rename configuration nodes or add
extra configuration nodes for existing DTBs.

The new FIT_CONF_MAPPINGS variable accepts a space-separated list of
mapping commands:

- dtb-conf:DTB_NAME:NEW_NAME
    Renames the configuration node for a specific DTB.

- dtb-extra-conf:DTB_NAME:EXTRA_NAME
    Creates an additional configuration node for an existing DTB.

Example usage:
    FIT_CONF_MAPPINGS = "\
        dtb-extra-conf:am335x-bonegreen:bonegreen \
        dtb-conf:am335x-boneblack:bbblack"

This generates three configuration nodes from two DTBs:
am335x-bonegreen, bonegreen (extra), and bbblack (renamed).

The implementation validates all mappings and ensures they match
existing DTBs, failing with clear error messages for invalid or unused
mappings.

Also removes leftover debug warning that was printing DTB configuration
details during FIT image generation.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/classes-recipe/kernel-fit-image.bbclass |  2 +-
 meta/conf/image-fitimage.conf                | 12 +++++
 meta/lib/oe/fitimage.py                      | 57 ++++++++++++++++++--
 3 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/meta/classes-recipe/kernel-fit-image.bbclass b/meta/classes-recipe/kernel-fit-image.bbclass
index fd0d21ceee..ec8e861d7f 100644
--- a/meta/classes-recipe/kernel-fit-image.bbclass
+++ b/meta/classes-recipe/kernel-fit-image.bbclass
@@ -139,7 +139,7 @@ python do_compile() {
             bb.fatal("Could not find a valid initramfs type for %s, the supported types are: %s" % (d.getVar('INITRAMFS_IMAGE_NAME'), d.getVar('FIT_SUPPORTED_INITRAMFS_FSTYPES')))
 
     # Generate the configuration section
-    root_node.fitimage_emit_section_config(d.getVar("FIT_CONF_DEFAULT_DTB"))
+    root_node.fitimage_emit_section_config(d.getVar("FIT_CONF_DEFAULT_DTB"), d.getVar("FIT_CONF_MAPPINGS"))
 
     # Write the its file
     root_node.write_its_file(itsfile)
diff --git a/meta/conf/image-fitimage.conf b/meta/conf/image-fitimage.conf
index 090ee148f4..b183e64319 100644
--- a/meta/conf/image-fitimage.conf
+++ b/meta/conf/image-fitimage.conf
@@ -47,6 +47,18 @@ FIT_LINUX_BIN ?= "linux.bin"
 # Allow user to select the default DTB for FIT image when multiple dtb's exists.
 FIT_CONF_DEFAULT_DTB ?= ""
 
+# Allow user to specify DTB configuration node mappings.
+# The format is a space-separated list of mappings. Supported mapping types are:
+# dtb-conf:DTB_NAME:NEW_NAME         - Rename the configuration node for a DTB
+# dtb-extra-conf:DTB_NAME:EXTRA_NAME - Add an additional configuration node for a DTB
+# Example:
+#   FIT_CONF_MAPPINGS = "\
+#     dtb-extra-conf:am335x-bonegreen:bonegreen \
+#     dtb-conf:am335x-boneblack:bbblack"
+# Two DTBs (am335x-bonegreen and am335x-boneblack) result in three
+# configuration nodes: am335x-bonegreen, bonegreen, bbblack
+FIT_CONF_MAPPINGS ?= ""
+
 # length of address in number of <u32> cells
 # ex: 1 32bits address, 2 64bits address
 FIT_ADDRESS_CELLS ?= "1"
diff --git a/meta/lib/oe/fitimage.py b/meta/lib/oe/fitimage.py
index f303799155..4798088259 100644
--- a/meta/lib/oe/fitimage.py
+++ b/meta/lib/oe/fitimage.py
@@ -331,7 +331,6 @@ class ItsNodeRootKernel(ItsNode):
         dtb_id = os.path.basename(dtb_path)
         dtb_alias_node = ItsNodeDtbAlias("fdt-" + dtb_id, dtb_alias_id, compatible)
         self._dtb_alias.append(dtb_alias_node)
-        bb.warn(f"compatible: {compatible}, dtb_alias_id: {dtb_alias_id}, dtb_id: {dtb_id}, dtb_path: {dtb_path}")
 
     def fitimage_emit_section_boot_script(self, bootscr_id, bootscr_path):
         """Emit the fitImage ITS u-boot script section"""
@@ -462,15 +461,63 @@ class ItsNodeRootKernel(ItsNode):
                 }
             )
 
-    def fitimage_emit_section_config(self, default_dtb_image=None):
+    def fitimage_emit_section_config(self, default_dtb_image=None, mappings=None):
         if self._dtbs:
+            dtb_extra_confs = []
+            dtb_confs = {}
+            if mappings:
+                for mapping in mappings.split():
+                    try:
+                        mapping_type, dtb_name, alt_name = mapping.split(':')
+                    except ValueError:
+                        bb.fatal("FIT configuration mapping '%s' is invalid. Expected format: 'mapping_type:dtb_name:alternative_name'" % mapping)
+                    if mapping_type == "dtb-conf":
+                        if dtb_name in dtb_confs:
+                            bb.fatal("FIT configuration mapping 'dtb-conf:%s' specified multiple times" % dtb_name)
+                        dtb_confs[dtb_name] = alt_name
+                    elif mapping_type == "dtb-extra-conf":
+                        dtb_extra_confs.append((dtb_name, alt_name))
+                    else:
+                        bb.fatal("FIT configuration mapping-type '%s' is invalid" % mapping_type)
+
+            # Process regular DTBs
             for dtb in self._dtbs:
                 dtb_name = dtb.name
                 if dtb.name.startswith("fdt-"):
                     dtb_name = dtb.name[len("fdt-"):]
-                self._fitimage_emit_one_section_config(self._conf_prefix + dtb_name, dtb)
-            for dtb in self._dtb_alias:
-                self._fitimage_emit_one_section_config(self._conf_prefix + dtb.alias_name, dtb)
+
+                dtb_renamed = dtb_name
+                if dtb_name in dtb_confs:
+                    dtb_renamed = dtb_confs.pop(dtb_name)
+                self._fitimage_emit_one_section_config(self._conf_prefix + dtb_renamed, dtb)
+
+                # Process extra configurations for this DTB
+                for dtb_extra_name, dtb_extra_alias in dtb_extra_confs[:]:
+                    if dtb_name == dtb_extra_name:
+                        dtb_extra_confs.remove((dtb_extra_name, dtb_extra_alias))
+                        self._fitimage_emit_one_section_config(self._conf_prefix + dtb_extra_alias, dtb)
+
+            # Process external DTB sym-link aliases
+            for dtb_alias in self._dtb_alias:
+                alias_name = dtb_alias.alias_name
+                dtb_renamed = alias_name
+                if alias_name in dtb_confs:
+                    dtb_renamed = dtb_confs.pop(alias_name)
+                self._fitimage_emit_one_section_config(self._conf_prefix + dtb_renamed, dtb_alias)
+
+                # Process extra configurations for this DTB alias
+                for dtb_extra_name, dtb_extra_alias in dtb_extra_confs[:]:
+                    if alias_name == dtb_extra_name:
+                        dtb_extra_confs.remove((dtb_extra_name, dtb_extra_alias))
+                        self._fitimage_emit_one_section_config(self._conf_prefix + dtb_extra_alias, dtb_alias)
+
+            # Verify all mappings were used
+            if dtb_confs or dtb_extra_confs:
+                unused_conf = (
+                    ["dtb-conf:%s:%s" % (name, alt) for name, alt in dtb_confs.items()] +
+                    ["dtb-extra-conf:%s:%s" % (name, alias) for name, alias in dtb_extra_confs]
+                )
+                bb.fatal("FIT configuration mapping(s) not matched with any DTB: %s" % ', '.join(unused_conf))
         else:
             # Currently exactly one kernel is supported.
             self._fitimage_emit_one_section_config(self._conf_prefix + "1")
-- 
2.52.0



  reply	other threads:[~2025-12-18 20:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18 20:14 [PATCH 0/2] kernel-fitimage: Add FIT_CONF_MAPPINGS for flexible DTB configuration AdrianF
2025-12-18 20:14 ` AdrianF [this message]
2026-01-08 14:29   ` [OE-core] [PATCH 1/2] " Quentin Schulz
2025-12-18 20:14 ` [PATCH 2/2] oe-selftest: fitimage: support FIT_CONF_MAPPINGS AdrianF

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251218201432.1608259-2-adrian.freihofer@siemens.com \
    --to=adrian.freihofer@siemens.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox