diff options
| author | Marcus Folkesson <marcus.folkesson@gmail.com> | 2024-07-10 10:53:09 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-07-23 11:17:11 +0100 |
| commit | d045fed31acd3f31fbe99815204e8540dc5f6846 (patch) | |
| tree | e1a9bc7b27c386a65c6d35cd06086cd1fe2feb85 /meta | |
| parent | 28fd497a26bdcc12d952f81436a6d873d81cd462 (diff) | |
| download | poky-d045fed31acd3f31fbe99815204e8540dc5f6846.tar.gz | |
bootimg-partition: break out code to a common library.
Break out the code that parse IMAGE_BOOT_FILES to a common library.
(From OE-Core rev: 1e07fe51bdb24070308c85e83df0b80ab9f83cea)
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Reviewed-by: Konrad Weihmann <kweihmann@outlook.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
| -rw-r--r-- | meta/lib/oe/bootfiles.py | 57 |
1 files changed, 57 insertions, 0 deletions
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 @@ | |||
| 1 | # | ||
| 2 | # SPDX-License-Identifier: MIT | ||
| 3 | # | ||
| 4 | # Copyright (C) 2024 Marcus Folkesson | ||
| 5 | # Author: Marcus Folkesson <marcus.folkesson@gmail.com> | ||
| 6 | # | ||
| 7 | # Utility functions handling boot files | ||
| 8 | # | ||
| 9 | # Look into deploy_dir and search for boot_files. | ||
| 10 | # Returns a list of tuples with (original filepath relative to | ||
| 11 | # deploy_dir, desired filepath renaming) | ||
| 12 | # | ||
| 13 | # Heavily inspired of bootimg-partition.py | ||
| 14 | # | ||
| 15 | def get_boot_files(deploy_dir, boot_files): | ||
| 16 | import re | ||
| 17 | import os | ||
| 18 | from glob import glob | ||
| 19 | |||
| 20 | if boot_files is None: | ||
| 21 | return None | ||
| 22 | |||
| 23 | # list of tuples (src_name, dst_name) | ||
| 24 | deploy_files = [] | ||
| 25 | for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): | ||
| 26 | if ';' in src_entry: | ||
| 27 | dst_entry = tuple(src_entry.split(';')) | ||
| 28 | if not dst_entry[0] or not dst_entry[1]: | ||
| 29 | raise ValueError('Malformed boot file entry: %s' % src_entry) | ||
| 30 | else: | ||
| 31 | dst_entry = (src_entry, src_entry) | ||
| 32 | |||
| 33 | deploy_files.append(dst_entry) | ||
| 34 | |||
| 35 | install_files = [] | ||
| 36 | for deploy_entry in deploy_files: | ||
| 37 | src, dst = deploy_entry | ||
| 38 | if '*' in src: | ||
| 39 | # by default install files under their basename | ||
| 40 | entry_name_fn = os.path.basename | ||
| 41 | if dst != src: | ||
| 42 | # unless a target name was given, then treat name | ||
| 43 | # as a directory and append a basename | ||
| 44 | entry_name_fn = lambda name: \ | ||
| 45 | os.path.join(dst, | ||
| 46 | os.path.basename(name)) | ||
| 47 | |||
| 48 | srcs = glob(os.path.join(deploy_dir, src)) | ||
| 49 | |||
| 50 | for entry in srcs: | ||
| 51 | src = os.path.relpath(entry, deploy_dir) | ||
| 52 | entry_dst_name = entry_name_fn(entry) | ||
| 53 | install_files.append((src, entry_dst_name)) | ||
| 54 | else: | ||
| 55 | install_files.append((src, dst)) | ||
| 56 | |||
| 57 | return install_files | ||
