blob_dtb.py 1.9 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 U-Boot device tree files
  6. #
  7. from binman.entry import Entry
  8. from binman.etype.blob import Entry_blob
  9. class Entry_blob_dtb(Entry_blob):
  10. """A blob that holds a device tree
  11. This is a blob containing a device tree. The contents of the blob are
  12. obtained from the list of available device-tree files, managed by the
  13. 'state' module.
  14. """
  15. def __init__(self, section, etype, node):
  16. # Put this here to allow entry-docs and help to work without libfdt
  17. global state
  18. from binman import state
  19. super().__init__(section, etype, node)
  20. def ObtainContents(self):
  21. """Get the device-tree from the list held by the 'state' module"""
  22. self._filename = self.GetDefaultFilename()
  23. self._pathname, _ = state.GetFdtContents(self.GetFdtEtype())
  24. return super().ReadBlobContents()
  25. def ProcessContents(self):
  26. """Re-read the DTB contents so that we get any calculated properties"""
  27. _, indata = state.GetFdtContents(self.GetFdtEtype())
  28. data = self.CompressData(indata)
  29. return self.ProcessContentsUpdate(data)
  30. def GetFdtEtype(self):
  31. """Get the entry type of this device tree
  32. This can be 'u-boot-dtb', 'u-boot-spl-dtb' or 'u-boot-tpl-dtb'
  33. Returns:
  34. Entry type if any, e.g. 'u-boot-dtb'
  35. """
  36. return None
  37. def GetFdts(self):
  38. fname = self.GetDefaultFilename()
  39. return {self.GetFdtEtype(): [self, fname]}
  40. def WriteData(self, data, decomp=True):
  41. ok = super().WriteData(data, decomp)
  42. # Update the state module, since it has the authoritative record of the
  43. # device trees used. If we don't do this, then state.GetFdtContents()
  44. # will still return the old contents
  45. state.UpdateFdtContents(self.GetFdtEtype(), data)
  46. return ok