summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/bootfiles.py
blob: 155fe742db51097ca6a900fcafbea4f1e5e8a9ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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