Hi Marcus,
On 5/28/24 11:08 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 <[email protected]>
---
Notes:
v3:
- Skip the intermediate bootfiles() function
- Rename variable names to be consistent
- Various python optimizations
meta/classes/image-bootfiles.bbclass | 38 ++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 meta/classes/image-bootfiles.bbclass
diff --git a/meta/classes/image-bootfiles.bbclass
b/meta/classes/image-bootfiles.bbclass
new file mode 100644
index 0000000000..79c58f414a
--- /dev/null
+++ b/meta/classes/image-bootfiles.bbclass
@@ -0,0 +1,38 @@
+#
+# SPDX-License-Identifier: MIT
+#
+# Copyright (C) 2024 Marcus Folkesson
+# Author: Marcus Folkesson <[email protected]>
+#
+# Writes IMAGE_BOOT_FILES to the IMAGE_BOOT_FILES_DIR directory
+#
+#
+# Usage: add inherit += "image-bootfiles" to your image
+#
Simply
inherit image-bootfiles
c.f.
https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-metadata.html#inherit-directive
since you put this class into meta/classes/ and not
meta/classes-recipes/, it could be included both with
INHERIT += "image-bootfiles"
and
inherit image-bootfiles
The former is to be included from configuration files (e.g. a distro,
local.conf, machine conf file, etc.). The latter inside the image recipe
directly.
I am wondering if we shouldn't make this a recipes-only bbclass? so
moving it to meta/classes-recipes/? This means that we won't be able to
use the INHERIT += "image-bootfiles" anymore but.... should we? On one
side, we have something that only applies to images, on the other hand,
it's probably something close to a policy, so rather part of a distro.
So just wondering, not asking for a change :)
Cheers,
Quentin
+
+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)
+ shutil.copyfile(image_src, image_dst)
This won't work if the parent directory of image_dst doesn't exist yet.
"""
>>> import shutil
>>> shutil.copyfile('plep', 'thisisatest/alsothis/test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.12/shutil.py", line 262, in copyfile
with open(dst, 'wb') as fdst:
^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory:
'thisisatest/alsothis/test'
"""
So I think we need to run:
os.makedirs(os.path.dirname(image_dst), exist_ok=True)
before calling shutil.copyfile?
In the bootimg-partition wic plugin, the following is done to install files:
install -m 0644 -D <src> <dst>
which creates all directories leading to <dst>. Additionally it makes it
rw for owner, r for group and others. It seems that shutil.copyfile does
this automatically (doesn't seem documented but it did this on a test in
the python interpreter).
Cheers,
Quentin
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#199969):
https://lists.openembedded.org/g/openembedded-core/message/199969
Mute This Topic: https://lists.openembedded.org/mt/106345350/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-