From: Adrian Freihofer Date: Thu, 18 Dec 2025 20:14:03 +0000 (+0100) Subject: kernel-fitimage: Add FIT_CONF_MAPPINGS for flexible DTB configuration X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e30f809a50c2151e525424879383c02325a7ec9a;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git kernel-fitimage: Add FIT_CONF_MAPPINGS for flexible DTB configuration 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 Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- diff --git a/meta/classes-recipe/kernel-fit-image.bbclass b/meta/classes-recipe/kernel-fit-image.bbclass index 66c766e90bd..4880027b210 100644 --- a/meta/classes-recipe/kernel-fit-image.bbclass +++ b/meta/classes-recipe/kernel-fit-image.bbclass @@ -140,7 +140,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 ae1e79ecde2..4e7ea2750ed 100644 --- a/meta/conf/image-fitimage.conf +++ b/meta/conf/image-fitimage.conf @@ -50,6 +50,18 @@ FIT_MKIMAGE_EXTRA_OPTS ?= "" # 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 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 bb19d92c8ed..8bf83c0a578 100644 --- a/meta/lib/oe/fitimage.py +++ b/meta/lib/oe/fitimage.py @@ -333,7 +333,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""" @@ -464,15 +463,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")