blob.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2016 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. #
  5. # Entry-type module for blobs, which are binary objects read from files
  6. #
  7. from entry import Entry
  8. import fdt_util
  9. import tools
  10. class Entry_blob(Entry):
  11. def __init__(self, section, etype, node):
  12. Entry.__init__(self, section, etype, node)
  13. self._filename = fdt_util.GetString(self._node, "filename", self.etype)
  14. def ObtainContents(self):
  15. self._filename = self.GetDefaultFilename()
  16. self._pathname = tools.GetInputFilename(self._filename)
  17. self.ReadContents()
  18. return True
  19. def ReadContents(self):
  20. with open(self._pathname) as fd:
  21. # We assume the data is small enough to fit into memory. If this
  22. # is used for large filesystem image that might not be true.
  23. # In that case, Image.BuildImage() could be adjusted to use a
  24. # new Entry method which can read in chunks. Then we could copy
  25. # the data in chunks and avoid reading it all at once. For now
  26. # this seems like an unnecessary complication.
  27. self.SetContents(fd.read())
  28. return True
  29. def GetDefaultFilename(self):
  30. return self._filename