aboutsummaryrefslogtreecommitdiff
path: root/tools/binman/etype/files.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-09-14 04:57:28 -0600
committerSimon Glass <sjg@chromium.org>2018-09-29 11:49:35 -0600
commit0a98b28b06800da48f006069fe14e47dd399d2ff (patch)
tree1646d2600d0b6e8ba7459695db082bc7f345d9b6 /tools/binman/etype/files.py
parentb4e1a38c294f56708d1a82717c850da359401d7e (diff)
binman: Support adding files
In some cases it is useful to add a group of files to the image and be able to access them at run-time. Of course it is possible to generate the binman config file with a set of blobs each with a filename. But for convenience, add an entry type which can do this. Add required support (for adding nodes and string properties) into the state module. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/etype/files.py')
-rw-r--r--tools/binman/etype/files.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/binman/etype/files.py b/tools/binman/etype/files.py
new file mode 100644
index 0000000000..99f2f2f67f
--- /dev/null
+++ b/tools/binman/etype/files.py
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass <sjg@chromium.org>
+#
+# Entry-type module for a set of files which are placed in individual
+# sub-entries
+#
+
+import glob
+import os
+
+from section import Entry_section
+import fdt_util
+import state
+import tools
+
+import bsection
+
+class Entry_files(Entry_section):
+ """Entry containing a set of files
+
+ Properties / Entry arguments:
+ - pattern: Filename pattern to match the files to include
+ - compress: Compression algorithm to use:
+ none: No compression
+ lz4: Use lz4 compression (via 'lz4' command-line utility)
+
+ This entry reads a number of files and places each in a separate sub-entry
+ within this entry. To access these you need to enable device-tree updates
+ at run-time so you can obtain the file positions.
+ """
+ def __init__(self, section, etype, node):
+ Entry_section.__init__(self, section, etype, node)
+ self._pattern = fdt_util.GetString(self._node, 'pattern')
+ if not self._pattern:
+ self.Raise("Missing 'pattern' property")
+ self._compress = fdt_util.GetString(self._node, 'compress', 'none')
+ self._require_matches = fdt_util.GetBool(self._node,
+ 'require-matches')
+
+ def ExpandEntries(self):
+ files = tools.GetInputFilenameGlob(self._pattern)
+ if self._require_matches and not files:
+ self.Raise("Pattern '%s' matched no files" % self._pattern)
+ for fname in files:
+ if not os.path.isfile(fname):
+ continue
+ name = os.path.basename(fname)
+ subnode = self._node.FindNode(name)
+ if not subnode:
+ subnode = state.AddSubnode(self._node, name)
+ state.AddString(subnode, 'type', 'blob')
+ state.AddString(subnode, 'filename', fname)
+ state.AddString(subnode, 'compress', self._compress)
+
+ # Read entries again, now that we have some
+ self._section._ReadEntries()