diff mbox series

[meta-ti,master/scarthgap,RFC,1/2] classes: Create uboot-fragments.bbclass

Message ID 20240815124846.29535-1-reatmon@ti.com
State RFC
Delegated to: Ryan Eatmon
Headers show
Series [meta-ti,master/scarthgap,RFC,1/2] classes: Create uboot-fragments.bbclass | expand

Commit Message

Ryan Eatmon Aug. 15, 2024, 12:48 p.m. UTC
Update our custom config fragment handling code to work with the new
UBOOT_CONFIG changes.  To better align with naming, change the name of
UBOOT_CONFIG_FRAGMENTS to just UBOOT_FRAGMENTS.  Also create a
UBOOT_FRAGMENTS_CONFIG that goes hand in hand with UBOOT_CONFIG so that
you can specify different fragments for each of the config types.

For example:

  UBOOT_CONFIG = "a b"
  UBOOT_CONFIG[a] = "config_a"
  UBOOT_CONFIG[b] = "config_b"

  UBOOT_FRAGMENTS_CONFIG[a] = ""
  UBOOT_FRAGMENTS_CONFIG[b] = "fragment1"

The logic in the class will automatically populate UBOOT_FRAGMENTS from
UBDOOT_FRAGMENTS_CONFIG.

Additionally, change the value that UBOOT_FRAGMENTS can take to be a
comma separated list of fragments to apply.

Signed-off-by: Ryan Eatmon <reatmon@ti.com>
---
 meta-ti-bsp/classes/uboot-fragments.bbclass   | 77 +++++++++++++++++++
 .../recipes-bsp/u-boot/u-boot-mergeconfig.inc |  7 --
 meta-ti-bsp/recipes-bsp/u-boot/u-boot-ti.inc  |  4 +-
 3 files changed, 80 insertions(+), 8 deletions(-)
 create mode 100644 meta-ti-bsp/classes/uboot-fragments.bbclass
 delete mode 100644 meta-ti-bsp/recipes-bsp/u-boot/u-boot-mergeconfig.inc
diff mbox series

Patch

diff --git a/meta-ti-bsp/classes/uboot-fragments.bbclass b/meta-ti-bsp/classes/uboot-fragments.bbclass
new file mode 100644
index 00000000..8db052fa
--- /dev/null
+++ b/meta-ti-bsp/classes/uboot-fragments.bbclass
@@ -0,0 +1,77 @@ 
+# Handle U-Boot config fragments for a machine
+#
+# This interacts with the UBOOT_CONFIG flow
+#
+# The format to specify it, in the machine, is:
+#
+# UBOOT_FRAGMENTS_CONFIG[foo] = "fragment[,fragment...]"
+#
+# or
+#
+# UBOOT_FRAGMENTS = "fragment[,fragment...]"
+#
+# Copyright 2024 (C) Texas Instruments, Inc.
+#
+# SPDX-License-Identifier: MIT
+
+python () {
+    loUbootConfig = (d.getVar('UBOOT_CONFIG') or "").split()
+    loUbootFragments = d.getVar('UBOOT_FRAGMENTS')
+    loUbootFragmentsConfigFlags = d.getVarFlags('UBOOT_FRAGMENTS_CONFIG')
+        
+    if loUbootFragmentsConfigFlags and loUbootFragments:
+        raise bb.parse.SkipRecipe("You cannot use UBOOT_FRAGMENTS and UBOOT_FRAGMENTS_CONFIG at the same time.")
+
+    if loUbootFragmentsConfigFlags is not None and len(loUbootConfig) > 0:
+        for lpConfig in loUbootConfig:
+            loFound = False
+            for lpFlag, lpValue in loUbootFragmentsConfigFlags.items():
+                if lpConfig == lpFlag: 
+                    loFound = True
+                    if lpValue == "":
+                        d.appendVar('UBOOT_FRAGMENTS', ' none')
+                    else:
+                        d.appendVar('UBOOT_FRAGMENTS', ' ' + lpValue)
+
+            if not loFound:
+                raise bb.parse.SkipRecipe("The selected UBOOT_CONFIG key %s has no match in %s." % (loUbootConfig, loUbootFragmentsConfigFlags.keys()))
+}
+
+uboot_configure_config:append () {
+   if [ -n "${UBOOT_FRAGMENTS}" ]
+   then
+        unset loTypeIdx
+        for lpType in ${UBOOT_CONFIG}; do
+            loTypeIdx=$(expr $loTypeIdx + 1)
+
+            if [ "${lpType}" == "${type}" ]; then
+                break
+            fi
+        done
+        
+        loApplyFragments=""
+        
+        for lpFragment in ${UBOOT_FRAGMENTS}; do
+            lpFragmentIdx=$(expr $lpFragmentIdx + 1)
+            if [ $y -eq $x ]; then
+                if [ "${lpFragment}" != "none" ]; then
+                    loApplyFragments=`echo ${lpFragment} | tr "," " "`
+                fi
+                break
+            fi
+        done
+
+        if [ -n "${loApplyFragments}" ]; then
+            oe_runmake -C ${S} O=${B}/${config} ${config} ${loApplyFragments}
+            oe_runmake -C ${S} O=${B}/${config} oldconfig
+        fi
+    fi
+}
+
+uboot_configure:append () {
+   if [ -n "${UBOOT_FRAGMENTS}" ] && [ -n "${UBOOT_MACHINE}" ]
+   then
+       oe_runmake -C ${S} O=${B} ${UBOOT_MACHINE} `echo ${UBOOT_FRAGMENTS} | tr "," " "`
+       oe_runmake -C ${S} O=${B} oldconfig
+   fi
+}
diff --git a/meta-ti-bsp/recipes-bsp/u-boot/u-boot-mergeconfig.inc b/meta-ti-bsp/recipes-bsp/u-boot/u-boot-mergeconfig.inc
deleted file mode 100644
index c7ce5047..00000000
--- a/meta-ti-bsp/recipes-bsp/u-boot/u-boot-mergeconfig.inc
+++ /dev/null
@@ -1,7 +0,0 @@ 
-do_configure:append () {
-   if [ -n "${UBOOT_CONFIG_FRAGMENTS}" ] && [ -n "${UBOOT_MACHINE}" ]
-   then
-       oe_runmake -C ${S} O=${B} ${UBOOT_MACHINE} ${UBOOT_CONFIG_FRAGMENTS}
-       oe_runmake -C ${S} O=${B} olddefconfig
-   fi
-}
diff --git a/meta-ti-bsp/recipes-bsp/u-boot/u-boot-ti.inc b/meta-ti-bsp/recipes-bsp/u-boot/u-boot-ti.inc
index bb50e1e9..5521ecee 100644
--- a/meta-ti-bsp/recipes-bsp/u-boot/u-boot-ti.inc
+++ b/meta-ti-bsp/recipes-bsp/u-boot/u-boot-ti.inc
@@ -1,3 +1,4 @@ 
+
 do_compile:prepend () {
     scm_version=$(printf '%s%s' -ti-g $(git -C ${S} rev-parse --verify HEAD 2>/dev/null | cut -c1-12))
 
@@ -10,7 +11,8 @@  SPL_BINARY ?= "MLO"
 
 require ${COREBASE}/meta/recipes-bsp/u-boot/u-boot-common.inc
 require ${COREBASE}/meta/recipes-bsp/u-boot/u-boot.inc
-require u-boot-mergeconfig.inc
+
+inherit uboot-fragments
 
 FILESEXTRAPATHS:prepend := "${THISDIR}/u-boot:"