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 super().__init__(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 super().ReadBlobContents()
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 fname = self.GetDefaultFilename()
48 return {self.GetFdtEtype(): [self, fname]}
50 def WriteData(self, data, decomp=True):
51 ok = super().WriteData(data, decomp)
53 # Update the state module, since it has the authoritative record of the
54 # device trees used. If we don't do this, then state.GetFdtContents()
55 # will still return the old contents
56 state.UpdateFdtContents(self.GetFdtEtype(), data)