diff options
| -rw-r--r-- | meta/lib/oe/bootfiles.py | 57 | ||||
| -rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-partition.py | 39 |
2 files changed, 59 insertions, 37 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 | ||
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 | |||
| 16 | import os | 16 | import os |
| 17 | import re | 17 | import re |
| 18 | 18 | ||
| 19 | from glob import glob | 19 | from oe.bootfiles import get_boot_files |
| 20 | 20 | ||
| 21 | from wic import WicError | 21 | from wic import WicError |
| 22 | from wic.engine import get_custom_config | 22 | from wic.engine import get_custom_config |
| @@ -66,42 +66,7 @@ class BootimgPartitionPlugin(SourcePlugin): | |||
| 66 | 66 | ||
| 67 | logger.debug('Boot files: %s', boot_files) | 67 | logger.debug('Boot files: %s', boot_files) |
| 68 | 68 | ||
| 69 | # list of tuples (src_name, dst_name) | 69 | cls.install_task = get_boot_files(kernel_dir, boot_files) |
| 70 | deploy_files = [] | ||
| 71 | for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): | ||
| 72 | if ';' in src_entry: | ||
| 73 | dst_entry = tuple(src_entry.split(';')) | ||
| 74 | if not dst_entry[0] or not dst_entry[1]: | ||
| 75 | raise WicError('Malformed boot file entry: %s' % src_entry) | ||
| 76 | else: | ||
| 77 | dst_entry = (src_entry, src_entry) | ||
| 78 | |||
| 79 | logger.debug('Destination entry: %r', dst_entry) | ||
| 80 | deploy_files.append(dst_entry) | ||
| 81 | |||
| 82 | cls.install_task = []; | ||
| 83 | for deploy_entry in deploy_files: | ||
| 84 | src, dst = deploy_entry | ||
| 85 | if '*' in src: | ||
| 86 | # by default install files under their basename | ||
| 87 | entry_name_fn = os.path.basename | ||
| 88 | if dst != src: | ||
| 89 | # unless a target name was given, then treat name | ||
| 90 | # as a directory and append a basename | ||
| 91 | entry_name_fn = lambda name: \ | ||
| 92 | os.path.join(dst, | ||
| 93 | os.path.basename(name)) | ||
| 94 | |||
| 95 | srcs = glob(os.path.join(kernel_dir, src)) | ||
| 96 | |||
| 97 | logger.debug('Globbed sources: %s', ', '.join(srcs)) | ||
| 98 | for entry in srcs: | ||
| 99 | src = os.path.relpath(entry, kernel_dir) | ||
| 100 | entry_dst_name = entry_name_fn(entry) | ||
| 101 | cls.install_task.append((src, entry_dst_name)) | ||
| 102 | else: | ||
| 103 | cls.install_task.append((src, dst)) | ||
| 104 | |||
| 105 | if source_params.get('loader') != "u-boot": | 70 | if source_params.get('loader') != "u-boot": |
| 106 | return | 71 | return |
| 107 | 72 | ||
