Patchwork [RFC] uboot-config.bbclass: Allow choose of U-Boot config for machine

login
register
mail settings
Submitter Otavio Salvador
Date Aug. 4, 2013, 10:25 p.m.
Message ID <1375655116-10659-1-git-send-email-otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/55097/
State Accepted
Commit 5dba521611d644357cf0a98d2e30dcf41777c6ef
Headers show

Comments

Otavio Salvador - Aug. 4, 2013, 10:25 p.m.
Some machines provide several possible configurations and until now
there was no easy way for user to override the default setting.

This class provides a system similar to PACKAGECONFIG but for
U-Boot. The format is:

UBOOT_CONFIG ??= <default>
UBOOT_CONFIG[foo] = "config,images"

There are two possible parameters:

 - config: it is used to set UBOOT_MACHINE
 - images: it is used to append onto IMAGE_FSTYPES

Below there's an usage example:

,----[ i.MX6Q SABRE AUTO based example ]
| UBOOT_CONFIG ??= "sd"
| UBOOT_CONFIG[sd] = "mx6qsabreauto_config,sdcard"
| UBOOT_CONFIG[eimnor] = "mx6qsabreauto_eimnor_config"
| UBOOT_CONFIG[nand] = "mx6qsabreauto_nand_config,ubifs"
| UBOOT_CONFIG[spinor] = "mx6qsabreauto_spinor_config"
`----

User can, from local.conf or environment, use UBOOT_CONFIG=nand and
override the default setting, as:

,----[ Override example from command line ]
| MACHINE=imx6qsabreauto UBOOT_CONFIG=nand bitbake core-image-base
`----

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/classes/uboot-config.bbclass | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 meta/classes/uboot-config.bbclass
Otavio Salvador - Aug. 4, 2013, 10:32 p.m.
On Sun, Aug 4, 2013 at 7:25 PM, Otavio Salvador <otavio@ossystems.com.br> wrote:
> Some machines provide several possible configurations and until now
> there was no easy way for user to override the default setting.
>
> This class provides a system similar to PACKAGECONFIG but for
> U-Boot. The format is:
>
> UBOOT_CONFIG ??= <default>
> UBOOT_CONFIG[foo] = "config,images"
>
> There are two possible parameters:
>
>  - config: it is used to set UBOOT_MACHINE
>  - images: it is used to append onto IMAGE_FSTYPES
>
> Below there's an usage example:
>
> ,----[ i.MX6Q SABRE AUTO based example ]
> | UBOOT_CONFIG ??= "sd"
> | UBOOT_CONFIG[sd] = "mx6qsabreauto_config,sdcard"
> | UBOOT_CONFIG[eimnor] = "mx6qsabreauto_eimnor_config"
> | UBOOT_CONFIG[nand] = "mx6qsabreauto_nand_config,ubifs"
> | UBOOT_CONFIG[spinor] = "mx6qsabreauto_spinor_config"
> `----
>
> User can, from local.conf or environment, use UBOOT_CONFIG=nand and
> override the default setting, as:
>
> ,----[ Override example from command line ]
> | MACHINE=imx6qsabreauto UBOOT_CONFIG=nand bitbake core-image-base
> `----
>
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>

This patch is to bring the discussion about the problem I am trying to
solve. Currently we'd need several duplicated machines to allow this
kind of setup.

Do people agree with this approach?

Patch

diff --git a/meta/classes/uboot-config.bbclass b/meta/classes/uboot-config.bbclass
new file mode 100644
index 0000000..fc37620
--- /dev/null
+++ b/meta/classes/uboot-config.bbclass
@@ -0,0 +1,39 @@ 
+# Allow easy override of U-Boot config for a machine
+#
+# The format to specify it, in the machine, is:
+#
+# UBOOT_CONFIG ??= <default>
+# UBOOT_CONFIG[foo] = "config,images"
+#
+# Copyright 2013 (C) O.S. Systems Software LTDA.
+
+addhandler uboot_config_eventhandler
+uboot_config_eventhandler[eventmask] = "bb.event.ConfigParsed"
+python uboot_config_eventhandler() {
+    ubootconfigflags = e.data.getVarFlags('UBOOT_CONFIG')
+    if not ubootconfigflags:
+        return
+
+    ubootconfig = (e.data.getVar('UBOOT_CONFIG', True) or "").split()
+    if len(ubootconfig) > 1:
+        raise bb.parse.SkipPackage('You can only have a single default for UBOOT_CONFIG.')
+    elif len(ubootconfig) == 0:
+        raise bb.parse.SkipPackage('You must set a default in UBOOT_CONFIG.')
+    ubootconfig = ubootconfig[0]
+
+    for f, v in ubootconfigflags.items():
+        if f == 'defaultval':
+            continue
+
+        items = v.split(',')
+        if items[0] and len(items) > 2:
+            raise bb.parse.SkipPackage('Only config,images can be specified!')
+
+        if ubootconfig == f:
+            bb.debug(1, "Setting UBOOT_MACHINE to %s." % items[0])
+            e.data.setVar('UBOOT_MACHINE', items[0])
+
+            if items[1]:
+                bb.debug(1, "Appending '%s' to IMAGE_FSTYPES." % items[1])
+                e.data.appendVar('IMAGE_FSTYPES', ' ' + items[1])
+}