1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Entry-type module for a set of files which are placed in individual
12 from binman.etype.section import Entry_section
13 from dtoc import fdt_util
14 from patman import tools
16 # This is imported if needed
19 class Entry_files(Entry_section):
20 """A set of files arranged in a section
22 Properties / Entry arguments:
23 - pattern: Filename pattern to match the files to include
24 - files-compress: Compression algorithm to use:
26 lz4: Use lz4 compression (via 'lz4' command-line utility)
27 - files-align: Align each file to the given alignment
29 This entry reads a number of files and places each in a separate sub-entry
30 within this entry. To access these you need to enable device-tree updates
31 at run-time so you can obtain the file positions.
33 def __init__(self, section, etype, node):
34 # Put this here to allow entry-docs and help to work without libfdt
36 from binman import state
38 super().__init__(section, etype, node)
42 self._pattern = fdt_util.GetString(self._node, 'pattern')
44 self.Raise("Missing 'pattern' property")
45 self._files_compress = fdt_util.GetString(self._node, 'files-compress',
47 self._files_align = fdt_util.GetInt(self._node, 'files-align');
48 self._require_matches = fdt_util.GetBool(self._node,
51 def ExpandEntries(self):
52 files = tools.get_input_filename_glob(self._pattern)
53 if self._require_matches and not files:
54 self.Raise("Pattern '%s' matched no files" % self._pattern)
56 if not os.path.isfile(fname):
58 name = os.path.basename(fname)
59 subnode = self._node.FindNode(name)
61 subnode = state.AddSubnode(self._node, name)
62 state.AddString(subnode, 'type', 'blob')
63 state.AddString(subnode, 'filename', fname)
64 state.AddString(subnode, 'compress', self._files_compress)
66 state.AddInt(subnode, 'align', self._files_align)
68 # Read entries again, now that we have some