Skip to contentSkip to conversation

wic: bootimg-partition: Add support to specify a custom extlinux.conf

PATCH In review Kevin Hao 2 participants 3 messages Aug 20, 2018

lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

PATCH 1/2 wic: bootimg-partition: Add support to specify a custom extlinux.conf

Add support to specify a custom extlinux.conf via something like:

    bootloader --configfile="extlinux.conf"
---
 .../lib/wic/plugins/source/bootimg-partition.py    | 79 +++++++++++++---------
 1 file changed, 47 insertions(+), 32 deletions(-)
scripts/lib/wic/plugins/source/bootimg-partition.py +47 -32
index 7d61595d0414..2e9b9f5ed657 100644
@@ -30,6 +30,7 @@ import re
 from glob import glob
 
 from wic import WicError
+from wic.engine import get_custom_config
 from wic.pluginbase import SourcePlugin
 from wic.misc import exec_cmd, get_bitbake_var
 
@@ -114,38 +115,52 @@ class BootimgPartitionPlugin(SourcePlugin):
         if source_params.get('loader') != "u-boot":
             return
 
-        # The kernel types supported by the sysboot of u-boot
-        kernel_types = ["uImage", "zImage", "Image", "vmlinux", "fitImage"]
-        has_dtb = False
-        fdt_dir = '/'
-        kernel_name = None
-        for task in cls.install_task:
-            src, dst = task
-            # Find the kernel image name
-            for image in kernel_types:
-                if re.match(image, src):
-                    if not kernel_name:
-                        kernel_name = os.path.join('/', dst)
-                    else:
-                        raise WicError('Multi kernel file founded')
-
-            # We suppose that all the dtb are in the same directory
-            if re.search(r'\.dtb', src) and fdt_dir == '/':
-                has_dtb = True
-                fdt_dir = os.path.join(fdt_dir, os.path.dirname(dst))
-
-        if not kernel_name:
-            raise WicError('No kernel file founded')
-
-        # Compose the extlinux.conf
-        extlinux_conf = "default Yocto\n"
-        extlinux_conf += "label Yocto\n"
-        extlinux_conf += "   kernel %s\n" % kernel_name
-        if has_dtb:
-            extlinux_conf += "   fdtdir %s\n" % fdt_dir
-        bootloader = cr.ks.bootloader
-        extlinux_conf += "append root=%s rootwait %s\n" \
-                         % (cr.rootdev, bootloader.append if bootloader.append else '')
+        configfile = cr.ks.bootloader.configfile
+        custom_cfg = None
+        if configfile:
+            custom_cfg = get_custom_config(configfile)
+            if custom_cfg:
+                # Use a custom configuration for extlinux.conf
+                extlinux_conf = custom_cfg
+                logger.debug("Using custom configuration file "
+                             "%s for extlinux.cfg", configfile)
+            else:
+                raise WicError("configfile is specified but failed to "
+                               "get it from %s." % configfile)
+
+        if not custom_cfg:
+            # The kernel types supported by the sysboot of u-boot
+            kernel_types = ["uImage", "zImage", "Image", "vmlinux", "fitImage"]
+            has_dtb = False
+            fdt_dir = '/'
+            kernel_name = None
+            for task in cls.install_task:
+                src, dst = task
+                # Find the kernel image name
+                for image in kernel_types:
+                    if re.match(image, src):
+                        if not kernel_name:
+                            kernel_name = os.path.join('/', dst)
+                        else:
+                            raise WicError('Multi kernel file founded')
+
+                # We suppose that all the dtb are in the same directory
+                if re.search(r'\.dtb', src) and fdt_dir == '/':
+                    has_dtb = True
+                    fdt_dir = os.path.join(fdt_dir, os.path.dirname(dst))
+
+            if not kernel_name:
+                raise WicError('No kernel file founded')
+
+            # Compose the extlinux.conf
+            extlinux_conf = "default Yocto\n"
+            extlinux_conf += "label Yocto\n"
+            extlinux_conf += "   kernel %s\n" % kernel_name
+            if has_dtb:
+                extlinux_conf += "   fdtdir %s\n" % fdt_dir
+            bootloader = cr.ks.bootloader
+            extlinux_conf += "append root=%s rootwait %s\n" \
+                             % (cr.rootdev, bootloader.append if bootloader.append else '')
 
         install_cmd = "install -d %s/extlinux/" % hdddir
         exec_cmd(install_cmd)
Signature · 1 line
2.14.4
author
#1 lore raw

PATCH 2/2 wic: bootimg-partition: Select a preferred type if multi kernel images are installed

Automatically select one kernel type image based on a predefined precedence list if there are multi kernel images installed.

---
 .../lib/wic/plugins/source/bootimg-partition.py    | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
scripts/lib/wic/plugins/source/bootimg-partition.py +13 -9
index 2e9b9f5ed657..ddc880be366f 100644
@@ -130,24 +130,28 @@ class BootimgPartitionPlugin(SourcePlugin):
 
         if not custom_cfg:
             # The kernel types supported by the sysboot of u-boot
-            kernel_types = ["uImage", "zImage", "Image", "vmlinux", "fitImage"]
+            kernel_types = ["zImage", "Image", "fitImage", "uImage", "vmlinux"]
             has_dtb = False
             fdt_dir = '/'
             kernel_name = None
-            for task in cls.install_task:
-                src, dst = task
-                # Find the kernel image name
-                for image in kernel_types:
+
+            # Find the kernel image name, from the highest precedence to lowest
+            for image in kernel_types:
+                for task in cls.install_task:
+                    src, dst = task
                     if re.match(image, src):
-                        if not kernel_name:
-                            kernel_name = os.path.join('/', dst)
-                        else:
-                            raise WicError('Multi kernel file founded')
+                        kernel_name = os.path.join('/', dst)
+                        break
+                if kernel_name:
+                    break
 
+            for task in cls.install_task:
+                src, dst = task
                 # We suppose that all the dtb are in the same directory
                 if re.search(r'\.dtb', src) and fdt_dir == '/':
                     has_dtb = True
                     fdt_dir = os.path.join(fdt_dir, os.path.dirname(dst))
+                    break
 
             if not kernel_name:
                 raise WicError('No kernel file founded')
Signature · 1 line
2.14.4
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] wic: bootimg-partition: Select a preferred type if multi kernel images are installed

Quoted 4 lines · Kevin Hao

Automatically select one kernel type image based on a predefined precedence list if there are multi kernel images installed.

Signature · 1 line
Tom