All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] classes/uboot-extlinux-config: Add class
@ 2016-10-04 13:54 Fabio Berton
  2016-10-04 13:54 ` [PATCH v3 2/2] u-boot: Add support to use uboot-extlinux-config class Fabio Berton
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio Berton @ 2016-10-04 13:54 UTC (permalink / raw)
  To: openembedded-core; +Cc: Otavio Salvador

This class allow the extlinux.conf generation for U-Boot use.
The U-Boot support for it is given to allow the Generic Distribution
Configuration specification use by OpenEmbedded-based products.

This class can be inherited by u-boot recipes to create extlinux.conf
and boot using menu options.

U-boot with extlinux support is machine dependent, so to use this class
you need to set UBOOT_EXTLINUX to 1 in machine configuration file and
also set root= kernel cmdline UBOOT_EXTLINUX_ROOT. This variable is used
to pass root kernel cmdline, e.g:

UBOOT_EXTLINUX_ROOT = "root=/dev/mmcblk2p2"

Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/classes/uboot-extlinux-config.bbclass | 126 +++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100644 meta/classes/uboot-extlinux-config.bbclass

diff --git a/meta/classes/uboot-extlinux-config.bbclass b/meta/classes/uboot-extlinux-config.bbclass
new file mode 100644
index 0000000..df91386
--- /dev/null
+++ b/meta/classes/uboot-extlinux-config.bbclass
@@ -0,0 +1,126 @@
+# uboot-extlinux-config.bbclass
+#
+# This class allow the extlinux.conf generation for U-Boot use. The
+# U-Boot support for it is given to allow the Generic Distribution
+# Configuration specification use by OpenEmbedded-based products.
+#
+# External variables:
+#
+# UBOOT_EXTLINUX_CONSOLE           - Set to "console=ttyX" to change kernel boot
+#                                    default console.
+# UBOOT_EXTLINUX_LABELS            - A list of targets for the automatic config.
+# UBOOT_EXTLINUX_KERNEL_ARGS       - Add additional kernel arguments.
+# UBOOT_EXTLINUX_KERNEL_IMAGE      - Kernel image name.
+# UBOOT_EXTLINUX_FDTDIR            - Device tree directory.
+# UBOOT_EXTLINUX_INITRD            - Indicates a list of filesystem images to
+#                                    concatenate and use as an initrd (optional).
+# UBOOT_EXTLINUX_MENU_DESCRIPTION  - Name to use as description.
+# UBOOT_EXTLINUX_ROOT              - Root kernel cmdline.
+#
+# If there's only one label system will boot automatically and menu won't be
+# created. If you want to use more than one labels, e.g linux and alternate,
+# use overrides to set menu description, console and others variables.
+#
+# Ex:
+#
+# UBOOT_EXTLINUX_LABELS ??= "default fallback"
+#
+# UBOOT_EXTLINUX_KERNEL_IMAGE_default ??= "../zImage"
+# UBOOT_EXTLINUX_MENU_DESCRIPTION_default ??= "Linux Default"
+#
+# UBOOT_EXTLINUX_KERNEL_IMAGE_fallback ??= "../zImage-fallback"
+# UBOOT_EXTLINUX_MENU_DESCRIPTION_fallback ??= "Linux Fallback"
+#
+# Results:
+#
+# menu title Select the boot mode
+# LABEL Linux Default
+#   KERNEL ../zImage
+#   FDTDIR ../
+#   APPEND root=/dev/mmcblk2p2 rootwait rw console=${console}
+# LABEL Linux Fallback
+#   KERNEL ../zImage-fallback
+#   FDTDIR ../
+#   APPEND root=/dev/mmcblk2p2 rootwait rw console=${console}
+#
+# Copyright (C) 2016, O.S. Systems Software LTDA.  All Rights Reserved
+# Released under the MIT license (see packages/COPYING)
+#
+# The kernel has an internal default console, which you can override with
+# a console=...some_tty...
+UBOOT_EXTLINUX_CONSOLE ??= "console=${console}"
+UBOOT_EXTLINUX_LABELS ??= "linux"
+UBOOT_EXTLINUX_FDTDIR ??= "../"
+UBOOT_EXTLINUX_KERNEL_IMAGE ??= "../${KERNEL_IMAGETYPE}"
+UBOOT_EXTLINUX_KERNEL_ARGS ??= "rootwait rw"
+UBOOT_EXTLINUX_MENU_DESCRIPTION_linux ??= "${DISTRO_NAME}"
+
+UBOOT_EXTLINUX_CONFIG = "${B}/extlinux.conf"
+
+python create_extlinux_config() {
+    if d.getVar("UBOOT_EXTLINUX", True) != "1":
+      return
+
+    if not d.getVar('WORKDIR', True):
+        bb.error("WORKDIR not defined, unable to package")
+
+    labels = d.getVar('UBOOT_EXTLINUX_LABELS', True)
+    if not labels:
+        bb.fatal("UBOOT_EXTLINUX_LABELS not defined, nothing to do")
+
+    if not labels.strip():
+        bb.fatal("No labels, nothing to do")
+
+    cfile = d.getVar('UBOOT_EXTLINUX_CONFIG', True)
+    if not cfile:
+        bb.fatal('Unable to read UBOOT_EXTLINUX_CONFIG')
+
+    try:
+        with open(cfile, 'w') as cfgfile:
+            cfgfile.write('# Generic Distro Configuration file generated by OpenEmbedded\n')
+
+            if len(labels.split()) > 1:
+                cfgfile.write('menu title Select the boot mode\n')
+
+            for label in labels.split():
+                localdata = bb.data.createCopy(d)
+
+                overrides = localdata.getVar('OVERRIDES', True)
+                if not overrides:
+                    bb.fatal('OVERRIDES not defined')
+
+                localdata.setVar('OVERRIDES', label + ':' + overrides)
+                bb.data.update_data(localdata)
+
+                extlinux_console = localdata.getVar('UBOOT_EXTLINUX_CONSOLE', True)
+
+                menu_description = localdata.getVar('UBOOT_EXTLINUX_MENU_DESCRIPTION', True)
+                if not menu_description:
+                    menu_description = label
+
+                root = localdata.getVar('UBOOT_EXTLINUX_ROOT', True)
+                if not root:
+                    bb.fatal('UBOOT_EXTLINUX_ROOT not defined')
+
+                kernel_image = localdata.getVar('UBOOT_EXTLINUX_KERNEL_IMAGE', True)
+                fdtdir = localdata.getVar('UBOOT_EXTLINUX_FDTDIR', True)
+                if fdtdir:
+                    cfgfile.write('LABEL %s\n\tKERNEL %s\n\tFDTDIR %s\n' %
+                                 (menu_description, kernel_image, fdtdir))
+                else:
+                    cfgfile.write('LABEL %s\n\tKERNEL %s\n' % (menu_description, kernel_image))
+
+                kernel_args = localdata.getVar('UBOOT_EXTLINUX_KERNEL_ARGS', True)
+
+                initrd = localdata.getVar('UBOOT_EXTLINUX_INITRD', True)
+                if initrd:
+                    cfgfile.write('\tINITRD %s\n'% initrd)
+
+                kernel_args = root + " " + kernel_args
+                cfgfile.write('\tAPPEND %s %s\n' % (kernel_args, extlinux_console))
+
+    except OSError:
+        bb.fatal('Unable to open %s' % (cfile))
+}
+
+do_install[prefuncs] += "create_extlinux_config"
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v3 2/2] u-boot: Add support to use uboot-extlinux-config class
  2016-10-04 13:54 [PATCH v3 1/2] classes/uboot-extlinux-config: Add class Fabio Berton
@ 2016-10-04 13:54 ` Fabio Berton
  0 siblings, 0 replies; 2+ messages in thread
From: Fabio Berton @ 2016-10-04 13:54 UTC (permalink / raw)
  To: openembedded-core; +Cc: Otavio Salvador

Use uboot-extlinux-config class to create extlinux.conf file and then
install inside /boot/extlinux directory and also put file to deploy
dir. This file will be only create if UBOOT_EXTLINUX is set to 1.

You can use DEPLOYDIR/extlinux.conf file to install into final image
using wic setting:

IMAGE_BOOT_FILES_append = " extlinux.conf;extlinux/extlinux.conf"

Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/recipes-bsp/u-boot/u-boot.inc | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/meta/recipes-bsp/u-boot/u-boot.inc b/meta/recipes-bsp/u-boot/u-boot.inc
index 2a94d26..252aae9 100644
--- a/meta/recipes-bsp/u-boot/u-boot.inc
+++ b/meta/recipes-bsp/u-boot/u-boot.inc
@@ -13,7 +13,7 @@ B = "${WORKDIR}/build"
 
 PACKAGE_ARCH = "${MACHINE_ARCH}"
 
-inherit uboot-config uboot-sign deploy
+inherit uboot-config uboot-extlinux-config uboot-sign deploy
 
 EXTRA_OEMAKE = 'CROSS_COMPILE=${TARGET_PREFIX} CC="${TARGET_PREFIX}gcc ${TOOLCHAIN_OPTIONS}" V=1'
 EXTRA_OEMAKE += 'HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}"'
@@ -65,6 +65,12 @@ UBOOT_ENV_BINARY ?= "${UBOOT_ENV}.${UBOOT_ENV_SUFFIX}"
 UBOOT_ENV_IMAGE ?= "${UBOOT_ENV}-${MACHINE}-${PV}-${PR}.${UBOOT_ENV_SUFFIX}"
 UBOOT_ENV_SYMLINK ?= "${UBOOT_ENV}-${MACHINE}.${UBOOT_ENV_SUFFIX}"
 
+# U-Boot EXTLINUX variables. U-Boot searches for /boot/extlinux/extlinux.conf
+# to find EXTLINUX conf file.
+UBOOT_EXTLINUX_INSTALL_DIR ?= "/boot/extlinux"
+UBOOT_EXTLINUX_CONF_NAME ?= "extlinux.conf"
+UBOOT_EXTLINUX_SYMLINK ?= "${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}-${PR}"
+
 do_compile () {
 	if [ "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', 'ld-is-gold', '', d)}" = "ld-is-gold" ] ; then
 		sed -i 's/$(CROSS_COMPILE)ld$/$(CROSS_COMPILE)ld.bfd/g' ${S}/config.mk
@@ -192,6 +198,12 @@ do_install () {
         install -m 644 ${WORKDIR}/${UBOOT_ENV_BINARY} ${D}/boot/${UBOOT_ENV_IMAGE}
         ln -sf ${UBOOT_ENV_IMAGE} ${D}/boot/${UBOOT_ENV_BINARY}
     fi
+
+    if [ "${UBOOT_EXTLINUX}" = "1" ]
+    then
+        install -Dm 0644 ${UBOOT_EXTLINUX_CONFIG} ${D}/${UBOOT_EXTLINUX_INSTALL_DIR}/${UBOOT_EXTLINUX_CONF_NAME}
+    fi
+
 }
 
 FILES_${PN} = "/boot ${sysconfdir}"
@@ -291,6 +303,13 @@ do_deploy () {
         ln -sf ${UBOOT_ENV_IMAGE} ${DEPLOYDIR}/${UBOOT_ENV_BINARY}
         ln -sf ${UBOOT_ENV_IMAGE} ${DEPLOYDIR}/${UBOOT_ENV_SYMLINK}
     fi
+
+    if [ "${UBOOT_EXTLINUX}" = "1" ]
+    then
+        install -m 644 ${UBOOT_EXTLINUX_CONFIG} ${DEPLOYDIR}/${UBOOT_EXTLINUX_SYMLINK}
+        ln -sf ${UBOOT_EXTLINUX_SYMLINK} ${DEPLOYDIR}/${UBOOT_EXTLINUX_CONF_NAME}-${MACHINE}
+        ln -sf ${UBOOT_EXTLINUX_SYMLINK} ${DEPLOYDIR}/${UBOOT_EXTLINUX_CONF_NAME}
+    fi
 }
 
 addtask deploy before do_build after do_compile
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-04 13:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-04 13:54 [PATCH v3 1/2] classes/uboot-extlinux-config: Add class Fabio Berton
2016-10-04 13:54 ` [PATCH v3 2/2] u-boot: Add support to use uboot-extlinux-config class Fabio Berton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.