diff mbox series

[v4,2/2] image-bootfiles.bbclass: new class, copy boot files to root filesystem

Message ID 20240530095314.407638-3-marcus.folkesson@gmail.com
State New
Headers show
Series image-bootfiles: new class | expand

Commit Message

Marcus Folkesson May 30, 2024, 9:53 a.m. UTC
image-bootfiles class copy files listed in IMAGE_BOOT_FILES
to the IMAGE_BOOT_FILES_DIR directory of the root filesystem.

This is useful when there is no explicit boot partition but all boot
files should instead reside inside the root filesystem.

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
 meta/classes/image-bootfiles.bbclass | 38 ++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 meta/classes/image-bootfiles.bbclass

Comments

Quentin Schulz May 31, 2024, 12:09 p.m. UTC | #1
Hi Marcus,

On 5/30/24 11:53 AM, Marcus Folkesson wrote:
> image-bootfiles class copy files listed in IMAGE_BOOT_FILES
> to the IMAGE_BOOT_FILES_DIR directory of the root filesystem.
> 
> This is useful when there is no explicit boot partition but all boot
> files should instead reside inside the root filesystem.
> 
> Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>

Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>

Thanks!
Quentin
Konrad Weihmann June 16, 2024, 4:26 a.m. UTC | #2
Looking at the combination of the patches and the following

+ boot_files = d.getVar("IMAGE_BOOT_FILES")
+ if boot_files is None:
+ return
+
+ install_files = get_boot_files(deploy_image_dir, boot_files)
+ if install_files is None:
+ bb.warn("Could not find any boot files to install even though IMAGE_BOOT_FILES is not empty")
+ return

get_boot_files only returns None if boot_files is None, which is caught already earlier on here, so the bb.warn clause likely will not be reached

Personally a check like `if install_files:` would make more sense

IMAGE_PREPROCESS_COMMAND += "bootfiles_populate;"

I'm not sure if that wouldn't raise issues if any of the packages would install a file by the same path/name as also set here.

In my opinion moving it to a POSTPROCESS function with some checks that it won't overwrite any files/folders might be the better option
Marcus Folkesson June 17, 2024, 6:23 a.m. UTC | #3
Hi Konrad,

Thanks for your comments!

On Sat, Jun 15, 2024 at 09:26:49PM -0700, Konrad Weihmann via lists.openembedded.org wrote:
> Looking at the combination of the patches and the following
> 
> + boot_files = d.getVar("IMAGE_BOOT_FILES")
> + if boot_files is None:
> + return
> +
> + install_files = get_boot_files(deploy_image_dir, boot_files)
> + if install_files is None:
> + bb.warn("Could not find any boot files to install even though IMAGE_BOOT_FILES is not empty")
> + return
> 
> get_boot_files only returns None if boot_files is None, which is caught already earlier on here, so the bb.warn clause likely will not be reached

You are right. The case i wanted to cover was if install_files was an
empty list.
This could occour if using asterix, e.g. IMAGE_BOOT_FILES = "bootfile.*" and there is
no "bootfile.*" in the DEPLOY_DIR.

> 
> Personally a check like `if install_files:` would make more sense

I think I will keep the check but change it to
if not install_files:

Does that make sense?
> 
> IMAGE_PREPROCESS_COMMAND += "bootfiles_populate;"
> 
> I'm not sure if that wouldn't raise issues if any of the packages would install a file by the same path/name as also set here.
> 
> In my opinion moving it to a POSTPROCESS function with some checks that it won't overwrite any files/folders might be the better option


Looking through the documentation, I think ROOTFS_POSTPROCESS_COMMAND
could be a candidate.
I'm not sure which one I prefer though.

Check that it won't overwrite any files/folder could be a good thing. I
will implement that and raise an error if the file/folder already
exists.

Best regards,
Marcus Folkesson
diff mbox series

Patch

diff --git a/meta/classes/image-bootfiles.bbclass b/meta/classes/image-bootfiles.bbclass
new file mode 100644
index 0000000000..0b95d47e06
--- /dev/null
+++ b/meta/classes/image-bootfiles.bbclass
@@ -0,0 +1,38 @@ 
+#
+# SPDX-License-Identifier: MIT
+#
+# Copyright (C) 2024 Marcus Folkesson
+# Author: Marcus Folkesson <marcus.folkesson@gmail.com>
+#
+# Writes IMAGE_BOOT_FILES to the IMAGE_BOOT_FILES_DIR directory.
+#
+# Usage: add "inherit image-bootfiles" to your image.
+#
+
+IMAGE_BOOT_FILES_DIR ?= "boot"
+
+python bootfiles_populate() {
+    import shutil
+    from oe.bootfiles import get_boot_files
+
+    deploy_image_dir = d.getVar("DEPLOY_DIR_IMAGE")
+    boot_dir = os.path.join(d.getVar("IMAGE_ROOTFS"), d.getVar("IMAGE_BOOT_FILES_DIR"))
+
+    boot_files = d.getVar("IMAGE_BOOT_FILES")
+    if boot_files is None:
+        return
+
+    install_files = get_boot_files(deploy_image_dir, boot_files)
+    if install_files is None:
+        bb.warn("Could not find any boot files to install even though IMAGE_BOOT_FILES is not empty")
+        return
+
+    os.makedirs(boot_dir, exist_ok=True)
+    for src, dst  in install_files:
+        image_src = os.path.join(deploy_image_dir, src)
+        image_dst = os.path.join(boot_dir, dst)
+        os.makedirs(os.path.dirname(image_dst), exist_ok=True)
+        shutil.copyfile(image_src, image_dst)
+}
+
+IMAGE_PREPROCESS_COMMAND += "bootfiles_populate;"