Skip to contentSkip to conversation

kernel-fit-image: optional addresses for kernel_noload, OS override

PATCH New Nora Schiffer 1 participant 4 messages Jul 21

lore
Share & tools
lore
#0 lore raw

v2 cover kernel-fit-image: optional addresses for kernel_noload, OS override

These patches are preparation for giving Yocto the ability to create FIT images containing an EFI application as kernel (so U-Boot can give the OS access to its EFI services while preserving other benefits of FIT image boot).

Support for actually replacing the kernel with a different file from the image deploy dir will be submitted as a separate series, but I'd like to get some less controversial changes out of the way first.

Changes in v2:

- Avoid shadowing os import (new patch 2/3, changes in patch 3/3)
- Updated U-Boot git repository URL in commit message 1/3

Nora Schiffer (3):
kernel-fit-image: make kernel entry point and load address optional
kernel-fit-image: avoid shadowing os stdlib import
kernel-fit-image: introduce FIT_OS variable to override 'os' field

 meta/classes-recipe/kernel-fit-image.bbclass |  3 +-
 meta/conf/image-fitimage.conf                |  4 +++
 meta/lib/oe/fitimage.py                      | 29 ++++++++++++--------
 meta/lib/oeqa/selftest/cases/fitimage.py     | 13 +++++++--
 4 files changed, 34 insertions(+), 15 deletions(-)
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#1 lore raw

PATCH v2 1/3 kernel-fit-image: make kernel entry point and load address optional

With image type kernel_noload, these are not used, and with [1] and [2], U-Boot will not require them anymore for this image type. Allow omitting them from image generation.

[1] https://git.u-boot-project.org/u-boot/u-boot/-/commit/c2abc606653e7eb1e8dbdbaaf1eac392689875ea
[2] https://git.u-boot-project.org/u-boot/u-boot/-/commit/c63051237f2bc79838a27473709948408acdf38b

---
 meta/lib/oe/fitimage.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
meta/lib/oe/fitimage.py +11 -7
index 79ac88966f..81d18f6c91 100644
@@ -276,18 +276,22 @@ class ItsNodeRootKernel(ItsNode):
                 if len(parts) == 3 and parts[2] == entrysymbol:
                     entrypoint = "<0x%s>" % parts[0]
                     break
+        opt_props = {
+            "data": '/incbin/("' + kernel_path + '")',
+            "arch": self._arch,
+            "os": "linux",
+        }
+        if load:
+            opt_props["load"] = f"<{load}>"
+        if entrypoint:
+            opt_props["entry"] = f"<{entrypoint}>"
+
         kernel_node = self.its_add_node_image(
             kernel_id,
             "Linux kernel",
             mkimage_kernel_type,
             compression,
-            {
-                "data": '/incbin/("' + kernel_path + '")',
-                "arch": self._arch,
-                "os": "linux",
-                "load": f"<{load}>",
-                "entry": f"<{entrypoint}>"
-            }
+            opt_props,
         )
         self._kernel = kernel_node
 
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#2 lore raw

PATCH v2 2/3 kernel-fit-image: avoid shadowing os stdlib import

In reply to Nora Schiffer

Avoid using os as an argument name, as shadowing the import of the os stdlib module may be confusing.

---
 meta/lib/oe/fitimage.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/oe/fitimage.py +2 -2
index 81d18f6c91..9cde6cedc4 100644
@@ -401,12 +401,12 @@ class ItsNodeRootKernel(ItsNode):
         )
         self._ramdisk = ramdisk_node
 
-    def fitimage_emit_section_loadable(self, name, filepath, type=None, description=None, compression=None, arch=None, os=None, load=None, entry=None):
+    def fitimage_emit_section_loadable(self, name, filepath, type=None, description=None, compression=None, arch=None, fit_os=None, load=None, entry=None):
         """Emit one fitImage ITS loadable section"""
         opt_props = {
             "data": '/incbin/("' + filepath + '")',
             "arch": arch if arch is not None else self._arch,
-            "os": os if os is not None else "linux",
+            "os": fit_os if fit_os is not None else "linux",
         }
 
         if load:
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/
#3 lore raw

PATCH v2 3/3 kernel-fit-image: introduce FIT_OS variable to override 'os' field

In reply to Nora Schiffer

U-Boot can load an EFI application from a FIT image; this requires setting the OS to "efi" (usually in combination with type "kernel_noload"). Doing so is a convenient approach for giving the OS access to EFI services while preserving other benefits of FIT image boot.

---
 meta/classes-recipe/kernel-fit-image.bbclass |  3 ++-
 meta/conf/image-fitimage.conf                |  4 ++++
 meta/lib/oe/fitimage.py                      | 11 ++++++-----
 meta/lib/oeqa/selftest/cases/fitimage.py     | 13 +++++++++++--
 4 files changed, 23 insertions(+), 8 deletions(-)
meta/classes-recipe/kernel-fit-image.bbclass +2 -1
index cfe43a5a30..3ace09ef5c 100644
@@ -76,7 +76,8 @@ python do_compile() {
     # Collect all the its nodes before the its file is generated and mkimage gets executed
     root_node = oe.fitimage.ItsNodeRootKernel(
         d.getVar("FIT_DESC"), d.getVar("FIT_ADDRESS_CELLS"),
-        d.getVar('HOST_PREFIX'), d.getVar('UBOOT_ARCH'),  d.getVar("FIT_CONF_PREFIX"),
+        d.getVar('HOST_PREFIX'), d.getVar('UBOOT_ARCH'), d.getVar('FIT_OS'),
+        d.getVar("FIT_CONF_PREFIX"),
         oe.types.boolean(d.getVar('FIT_KERNEL_SIGN_ENABLE')), d.getVar("FIT_KERNEL_SIGN_KEYDIR"),
         d.getVar("UBOOT_MKIMAGE"), d.getVar("UBOOT_MKIMAGE_DTCOPTS"),
         d.getVar('FIT_MKIMAGE_EXTRA_OPTS'),
meta/conf/image-fitimage.conf +4 -0
index 2fdb816d55..a06d30e494 100644
@@ -37,6 +37,10 @@ FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration node name"
 
 FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst cpio.gz ext2.gz cpio"
 
+# os field of the kernel and various other images in the FIT image. Set to "efi"
+# to load a kernel with EFI stub as an EFI application.
+FIT_OS ?= "linux"
+
 # Allow user to support special use cases where the kernel binary is
 # not included in the FIT image itself.
 # This is particularly useful for UKI-based setups, where the kernel
meta/lib/oe/fitimage.py +6 -5
index 9cde6cedc4..d4dacdd508 100644
@@ -153,7 +153,7 @@ class ItsNodeRootKernel(ItsNode):
     If a device tree included in the FIT image, the default configuration is the
     firt DTB. If there is no dtb present than the default configuation the kernel.
     """
-    def __init__(self, description, address_cells, host_prefix, arch, conf_prefix,
+    def __init__(self, description, address_cells, host_prefix, arch, fit_os, conf_prefix,
                  sign_enable=False, sign_keydir=None,
                  mkimage=None, mkimage_dtcopts=None,
                  mkimage_extra_opts=None,
@@ -171,6 +171,7 @@ class ItsNodeRootKernel(ItsNode):
 
         self._host_prefix = host_prefix
         self._arch = arch
+        self._os = fit_os
         self._conf_prefix = conf_prefix
 
         # Signature related properties
@@ -279,7 +280,7 @@ class ItsNodeRootKernel(ItsNode):
         opt_props = {
             "data": '/incbin/("' + kernel_path + '")',
             "arch": self._arch,
-            "os": "linux",
+            "os": self._os,
         }
         if load:
             opt_props["load"] = f"<{load}>"
@@ -370,7 +371,7 @@ class ItsNodeRootKernel(ItsNode):
             {
                 "data": '/incbin/("' + setup_path + '")',
                 "arch": self._arch,
-                "os": "linux",
+                "os": self._os,
                 "load": load,
                 "entry": entry
             }
@@ -385,7 +386,7 @@ class ItsNodeRootKernel(ItsNode):
             "data": '/incbin/("' + ramdisk_path + '")',
             "type": "ramdisk",
             "arch": self._arch,
-            "os": "linux"
+            "os": self._os,
         }
         if load:
             opt_props["load"] = f"<{load}>"
@@ -406,7 +407,7 @@ class ItsNodeRootKernel(ItsNode):
         opt_props = {
             "data": '/incbin/("' + filepath + '")',
             "arch": arch if arch is not None else self._arch,
-            "os": fit_os if fit_os is not None else "linux",
+            "os": fit_os if fit_os is not None else self._os,
         }
 
         if load:
meta/lib/oeqa/selftest/cases/fitimage.py +11 -2
index 9abe1d0c93..b3c54cebed 100644
@@ -680,6 +680,7 @@ class KernelFitImageBase(FitImageTestCase):
             'FIT_LOADABLES',
             'FIT_LOADABLE_ENTRYPOINT',
             'FIT_LOADABLE_LOADADDRESS',
+            'FIT_OS',
             'FIT_SIGN_ALG',
             'FIT_SIGN_INDIVIDUAL',
             'FIT_UBOOT_ENV',
@@ -915,7 +916,7 @@ class KernelFitImageBase(FitImageTestCase):
             # 'compression = "' + str(bb_vars['FIT_KERNEL_COMP_ALG']) + '";', defined based on files in TMPDIR, not ideal...
             'data = /incbin/("linux.bin");',
             'arch = "' + str(bb_vars['UBOOT_ARCH']) + '";',
-            'os = "linux";',
+            'os = "%s";' % bb_vars['FIT_OS'],
             'load = <' + str(bb_vars['UBOOT_LOADADDRESS']) + '>;',
             'entry = <' + str(bb_vars['UBOOT_ENTRYPOINT']) + '>;',
         ]
@@ -1510,6 +1511,7 @@ class FitImagePyTests(KernelFitImageBase):
             'FIT_KEY_SIGN_PKCS': "-x509",
             'FIT_LOADABLES': "",
             'FIT_LINUX_BIN': "linux.bin",
+            'FIT_OS': "linux",
             'FIT_PAD_ALG': "pkcs-1.5",
             'FIT_SIGN_ALG': "rsa2048",
             'FIT_SIGN_INDIVIDUAL': "0",
@@ -1550,7 +1552,8 @@ class FitImagePyTests(KernelFitImageBase):
 
         root_node = oe.fitimage.ItsNodeRootKernel(
             bb_vars["FIT_DESC"], bb_vars["FIT_ADDRESS_CELLS"],
-            bb_vars['HOST_PREFIX'], bb_vars['UBOOT_ARCH'],  bb_vars["FIT_CONF_PREFIX"],
+            bb_vars['HOST_PREFIX'], bb_vars['UBOOT_ARCH'], bb_vars['FIT_OS'],
+            bb_vars["FIT_CONF_PREFIX"],
             oe.types.boolean(bb_vars['UBOOT_SIGN_ENABLE']), bb_vars["UBOOT_SIGN_KEYDIR"],
             bb_vars["UBOOT_MKIMAGE"], bb_vars["UBOOT_MKIMAGE_DTCOPTS"],
             bb_vars["UBOOT_MKIMAGE_SIGN"], bb_vars["UBOOT_MKIMAGE_SIGN_ARGS"],
@@ -1656,6 +1659,12 @@ class FitImagePyTests(KernelFitImageBase):
         }
         self._test_fitimage_py(bb_vars_overrides)
 
+    def test_fitimage_py_conf_os(self):
+        """Test FIT_OS functionality"""
+        bb_vars_overrides = {
+            'FIT_OS': "efi",
+        }
+        self._test_fitimage_py(bb_vars_overrides)
 
 class UBootFitImageTests(FitImageTestCase):
     """Test cases for the uboot-sign bbclass"""
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/