From: Marcus Folkesson <marcus.folkesson@gmail.com>
To: openembedded-core@lists.openembedded.org,
Quentin Schulz <quentin.schulz@cherry.de>
Cc: Marcus Folkesson <marcus.folkesson@gmail.com>
Subject: [PATCH v4 1/2] bootimg-partition: break out code to a common library.
Date: Thu, 30 May 2024 11:53:13 +0200 [thread overview]
Message-ID: <20240530095314.407638-2-marcus.folkesson@gmail.com> (raw)
In-Reply-To: <20240530095314.407638-1-marcus.folkesson@gmail.com>
Break out the code that parse IMAGE_BOOT_FILES to a common library.
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
---
meta/lib/oe/bootfiles.py | 57 +++++++++++++++++++
.../wic/plugins/source/bootimg-partition.py | 39 +------------
2 files changed, 59 insertions(+), 37 deletions(-)
create mode 100644 meta/lib/oe/bootfiles.py
diff --git a/meta/lib/oe/bootfiles.py b/meta/lib/oe/bootfiles.py
new file mode 100644
index 0000000000..155fe742db
--- /dev/null
+++ b/meta/lib/oe/bootfiles.py
@@ -0,0 +1,57 @@
+#
+# SPDX-License-Identifier: MIT
+#
+# Copyright (C) 2024 Marcus Folkesson
+# Author: Marcus Folkesson <marcus.folkesson@gmail.com>
+#
+# Utility functions handling boot files
+#
+# Look into deploy_dir and search for boot_files.
+# Returns a list of tuples with (original filepath relative to
+# deploy_dir, desired filepath renaming)
+#
+# Heavily inspired of bootimg-partition.py
+#
+def get_boot_files(deploy_dir, boot_files):
+ import re
+ import os
+ from glob import glob
+
+ if boot_files is None:
+ return None
+
+ # list of tuples (src_name, dst_name)
+ deploy_files = []
+ for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files):
+ if ';' in src_entry:
+ dst_entry = tuple(src_entry.split(';'))
+ if not dst_entry[0] or not dst_entry[1]:
+ raise ValueError('Malformed boot file entry: %s' % src_entry)
+ else:
+ dst_entry = (src_entry, src_entry)
+
+ deploy_files.append(dst_entry)
+
+ install_files = []
+ for deploy_entry in deploy_files:
+ src, dst = deploy_entry
+ if '*' in src:
+ # by default install files under their basename
+ entry_name_fn = os.path.basename
+ if dst != src:
+ # unless a target name was given, then treat name
+ # as a directory and append a basename
+ entry_name_fn = lambda name: \
+ os.path.join(dst,
+ os.path.basename(name))
+
+ srcs = glob(os.path.join(deploy_dir, src))
+
+ for entry in srcs:
+ src = os.path.relpath(entry, deploy_dir)
+ entry_dst_name = entry_name_fn(entry)
+ install_files.append((src, entry_dst_name))
+ else:
+ install_files.append((src, dst))
+
+ return install_files
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
index 1071d1af3f..589853a439 100644
--- a/scripts/lib/wic/plugins/source/bootimg-partition.py
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -16,7 +16,7 @@ import logging
import os
import re
-from glob import glob
+from oe.bootfiles import get_boot_files
from wic import WicError
from wic.engine import get_custom_config
@@ -66,42 +66,7 @@ class BootimgPartitionPlugin(SourcePlugin):
logger.debug('Boot files: %s', boot_files)
- # list of tuples (src_name, dst_name)
- deploy_files = []
- for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files):
- if ';' in src_entry:
- dst_entry = tuple(src_entry.split(';'))
- if not dst_entry[0] or not dst_entry[1]:
- raise WicError('Malformed boot file entry: %s' % src_entry)
- else:
- dst_entry = (src_entry, src_entry)
-
- logger.debug('Destination entry: %r', dst_entry)
- deploy_files.append(dst_entry)
-
- cls.install_task = [];
- for deploy_entry in deploy_files:
- src, dst = deploy_entry
- if '*' in src:
- # by default install files under their basename
- entry_name_fn = os.path.basename
- if dst != src:
- # unless a target name was given, then treat name
- # as a directory and append a basename
- entry_name_fn = lambda name: \
- os.path.join(dst,
- os.path.basename(name))
-
- srcs = glob(os.path.join(kernel_dir, src))
-
- logger.debug('Globbed sources: %s', ', '.join(srcs))
- for entry in srcs:
- src = os.path.relpath(entry, kernel_dir)
- entry_dst_name = entry_name_fn(entry)
- cls.install_task.append((src, entry_dst_name))
- else:
- cls.install_task.append((src, dst))
-
+ cls.install_task = get_boot_files(kernel_dir, boot_files)
if source_params.get('loader') != "u-boot":
return
--
2.45.1
next prev parent reply other threads:[~2024-05-30 9:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-30 9:53 [PATCH v4 0/2] image-bootfiles: new class Marcus Folkesson
2024-05-30 9:53 ` Marcus Folkesson [this message]
2024-05-30 9:53 ` [PATCH v4 2/2] image-bootfiles.bbclass: new class, copy boot files to root filesystem Marcus Folkesson
2024-05-31 12:09 ` Quentin Schulz
2024-06-16 4:26 ` Konrad Weihmann
2024-06-17 6:23 ` [OE-core] " Marcus Folkesson
2024-06-11 10:37 ` [OE-core] [PATCH v4 0/2] image-bootfiles: new class Ross Burton
2024-06-11 13:22 ` Marcus Folkesson
2024-06-11 14:44 ` Martin Hundebøll
2024-06-11 15:04 ` Marcus Folkesson
2024-07-16 11:28 ` Ross Burton
2024-07-22 7:36 ` Marcus Folkesson
2024-06-14 20:25 ` Marcus Folkesson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240530095314.407638-2-marcus.folkesson@gmail.com \
--to=marcus.folkesson@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=quentin.schulz@cherry.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox