1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 # Entry-type module for U-Boot device tree with the microcode removed
10 from entry import Entry
11 from blob import Entry_blob
14 class Entry_u_boot_dtb_with_ucode(Entry_blob):
15 """A U-Boot device tree file, with the microcode removed
17 See Entry_u_boot_ucode for full details of the 3 entries involved in this
20 def __init__(self, section, etype, node):
21 Entry_blob.__init__(self, section, etype, node)
24 self.ucode_offset = None
25 self.ucode_size = None
29 def GetDefaultFilename(self):
32 def ProcessFdt(self, fdt):
33 # If the section does not need microcode, there is nothing to do
34 ucode_dest_entry = self.section.FindEntryType(
35 'u-boot-spl-with-ucode-ptr')
36 if not ucode_dest_entry or not ucode_dest_entry.target_pos:
37 ucode_dest_entry = self.section.FindEntryType(
38 'u-boot-with-ucode-ptr')
39 if not ucode_dest_entry or not ucode_dest_entry.target_pos:
42 # Remove the microcode
43 fname = self.GetDefaultFilename()
44 fdt = control.GetFdt(fname)
45 self.ucode = fdt.GetNode('/microcode')
47 raise self.Raise("No /microcode node found in '%s'" % fname)
49 # There's no need to collate it (move all microcode into one place)
50 # if we only have one chunk of microcode.
51 self.collate = len(self.ucode.subnodes) > 1
52 for node in self.ucode.subnodes:
53 data_prop = node.props.get('data')
55 self.ucode_data += ''.join(data_prop.bytes)
57 node.DeleteProp('data')
60 def ObtainContents(self):
61 # Call the base class just in case it does something important.
62 Entry_blob.ObtainContents(self)
63 self._pathname = control.GetFdtPath(self._filename)
66 for node in self.ucode.subnodes:
67 data_prop = node.props.get('data')
68 if data_prop and not self.collate:
69 # Find the offset in the device tree of the ucode data
70 self.ucode_offset = data_prop.GetOffset() + 12
71 self.ucode_size = len(data_prop.bytes)