files.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. import glob
  9. import os
  10. from section import Entry_section
  11. import fdt_util
  12. import state
  13. import tools
  14. import bsection
  15. class Entry_files(Entry_section):
  16. """Entry containing a set of files
  17. Properties / Entry arguments:
  18. - pattern: Filename pattern to match the files to include
  19. - compress: Compression algorithm to use:
  20. none: No compression
  21. lz4: Use lz4 compression (via 'lz4' command-line utility)
  22. This entry reads a number of files and places each in a separate sub-entry
  23. within this entry. To access these you need to enable device-tree updates
  24. at run-time so you can obtain the file positions.
  25. """
  26. def __init__(self, section, etype, node):
  27. Entry_section.__init__(self, section, etype, node)
  28. self._pattern = fdt_util.GetString(self._node, 'pattern')
  29. if not self._pattern:
  30. self.Raise("Missing 'pattern' property")
  31. self._compress = fdt_util.GetString(self._node, 'compress', 'none')
  32. self._require_matches = fdt_util.GetBool(self._node,
  33. 'require-matches')
  34. def ExpandEntries(self):
  35. files = tools.GetInputFilenameGlob(self._pattern)
  36. if self._require_matches and not files:
  37. self.Raise("Pattern '%s' matched no files" % self._pattern)
  38. for fname in files:
  39. if not os.path.isfile(fname):
  40. continue
  41. name = os.path.basename(fname)
  42. subnode = self._node.FindNode(name)
  43. if not subnode:
  44. subnode = state.AddSubnode(self._node, name)
  45. state.AddString(subnode, 'type', 'blob')
  46. state.AddString(subnode, 'filename', fname)
  47. state.AddString(subnode, 'compress', self._compress)
  48. # Read entries again, now that we have some
  49. self._section._ReadEntries()