Merge tag 'u-boot-rockchip-20200501' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / tools / binman / etype / files.py
1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
4 #
5 # Entry-type module for a set of files which are placed in individual
6 # sub-entries
7 #
8
9 import glob
10 import os
11
12 from binman.etype.section import Entry_section
13 from dtoc import fdt_util
14 from patman import tools
15
16
17 class Entry_files(Entry_section):
18     """Entry containing a set of files
19
20     Properties / Entry arguments:
21         - pattern: Filename pattern to match the files to include
22         - compress: Compression algorithm to use:
23             none: No compression
24             lz4: Use lz4 compression (via 'lz4' command-line utility)
25
26     This entry reads a number of files and places each in a separate sub-entry
27     within this entry. To access these you need to enable device-tree updates
28     at run-time so you can obtain the file positions.
29     """
30     def __init__(self, section, etype, node):
31         # Put this here to allow entry-docs and help to work without libfdt
32         global state
33         from binman import state
34
35         Entry_section.__init__(self, section, etype, node)
36         self._pattern = fdt_util.GetString(self._node, 'pattern')
37         if not self._pattern:
38             self.Raise("Missing 'pattern' property")
39         self._compress = fdt_util.GetString(self._node, 'compress', 'none')
40         self._require_matches = fdt_util.GetBool(self._node,
41                                                 'require-matches')
42
43     def ExpandEntries(self):
44         files = tools.GetInputFilenameGlob(self._pattern)
45         if self._require_matches and not files:
46             self.Raise("Pattern '%s' matched no files" % self._pattern)
47         for fname in files:
48             if not os.path.isfile(fname):
49                 continue
50             name = os.path.basename(fname)
51             subnode = self._node.FindNode(name)
52             if not subnode:
53                 subnode = state.AddSubnode(self._node, name)
54             state.AddString(subnode, 'type', 'blob')
55             state.AddString(subnode, 'filename', fname)
56             state.AddString(subnode, 'compress', self._compress)
57
58         # Read entries again, now that we have some
59         self._ReadEntries()