1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Entry-type module for U-Boot device tree files
8 from binman.entry import Entry
9 from binman.etype.blob import Entry_blob
11 class Entry_blob_dtb(Entry_blob):
12 """A blob that holds a device tree
14 This is a blob containing a device tree. The contents of the blob are
15 obtained from the list of available device-tree files, managed by the
18 def __init__(self, section, etype, node):
19 # Put this here to allow entry-docs and help to work without libfdt
21 from binman import state
23 Entry_blob.__init__(self, section, etype, node)
25 def ObtainContents(self):
26 """Get the device-tree from the list held by the 'state' module"""
27 self._filename = self.GetDefaultFilename()
28 self._pathname, _ = state.GetFdtContents(self.GetFdtEtype())
29 return Entry_blob.ReadBlobContents(self)
31 def ProcessContents(self):
32 """Re-read the DTB contents so that we get any calculated properties"""
33 _, indata = state.GetFdtContents(self.GetFdtEtype())
34 data = self.CompressData(indata)
35 return self.ProcessContentsUpdate(data)
37 def GetFdtEtype(self):
38 """Get the entry type of this device tree
40 This can be 'u-boot-dtb', 'u-boot-spl-dtb' or 'u-boot-tpl-dtb'
42 Entry type if any, e.g. 'u-boot-dtb'
47 """Get the device trees used by this entry
51 key: Filename from this entry (without the path)
53 Fdt object for this dtb, or None if not available
54 Filename of file containing this dtb
56 fname = self.GetDefaultFilename()
57 return {self.GetFdtEtype(): [self, fname]}
59 def WriteData(self, data, decomp=True):
60 ok = Entry_blob.WriteData(self, data, decomp)
62 # Update the state module, since it has the authoritative record of the
63 # device trees used. If we don't do this, then state.GetFdtContents()
64 # will still return the old contents
65 state.UpdateFdtContents(self.GetFdtEtype(), data)