Merge tag 'u-boot-imx-20190719' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
[oweals/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 section import Entry_section
13 import fdt_util
14 import state
15 import tools
16
17
18 class Entry_files(Entry_section):
19     """Entry containing a set of files
20
21     Properties / Entry arguments:
22         - pattern: Filename pattern to match the files to include
23         - compress: Compression algorithm to use:
24             none: No compression
25             lz4: Use lz4 compression (via 'lz4' command-line utility)
26
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.
30     """
31     def __init__(self, section, etype, node):
32         Entry_section.__init__(self, section, etype, node)
33         self._pattern = fdt_util.GetString(self._node, 'pattern')
34         if not self._pattern:
35             self.Raise("Missing 'pattern' property")
36         self._compress = fdt_util.GetString(self._node, 'compress', 'none')
37         self._require_matches = fdt_util.GetBool(self._node,
38                                                 'require-matches')
39
40     def ExpandEntries(self):
41         files = tools.GetInputFilenameGlob(self._pattern)
42         if self._require_matches and not files:
43             self.Raise("Pattern '%s' matched no files" % self._pattern)
44         for fname in files:
45             if not os.path.isfile(fname):
46                 continue
47             name = os.path.basename(fname)
48             subnode = self._node.FindNode(name)
49             if not subnode:
50                 subnode = state.AddSubnode(self._node, name)
51             state.AddString(subnode, 'type', 'blob')
52             state.AddString(subnode, 'filename', fname)
53             state.AddString(subnode, 'compress', self._compress)
54
55         # Read entries again, now that we have some
56         self._ReadEntries()