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
17 class Entry_files(Entry_section):
18 """A set of files arranged in a section
20 Properties / Entry arguments:
21 - pattern: Filename pattern to match the files to include
22 - files-compress: Compression algorithm to use:
24 lz4: Use lz4 compression (via 'lz4' command-line utility)
25 - files-align: Align each file to the given alignment
27 This entry reads a number of files and places each in a separate sub-entry
28 within this entry. To access these you need to enable device-tree updates
29 at run-time so you can obtain the file positions.
31 def __init__(self, section, etype, node):
32 # Put this here to allow entry-docs and help to work without libfdt
34 from binman import state
36 super().__init__(section, etype, node)
37 self._pattern = fdt_util.GetString(self._node, 'pattern')
39 self.Raise("Missing 'pattern' property")
40 self._files_compress = fdt_util.GetString(self._node, 'files-compress',
42 self._files_align = fdt_util.GetInt(self._node, 'files-align');
43 self._require_matches = fdt_util.GetBool(self._node,
46 def ExpandEntries(self):
47 files = tools.GetInputFilenameGlob(self._pattern)
48 if self._require_matches and not files:
49 self.Raise("Pattern '%s' matched no files" % self._pattern)
51 if not os.path.isfile(fname):
53 name = os.path.basename(fname)
54 subnode = self._node.FindNode(name)
56 subnode = state.AddSubnode(self._node, name)
57 state.AddString(subnode, 'type', 'blob')
58 state.AddString(subnode, 'filename', fname)
59 state.AddString(subnode, 'compress', self._files_compress)
61 state.AddInt(subnode, 'align', self._files_align)
63 # Read entries again, now that we have some