files.py 2.1 KB

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