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 Properties / Entry arguments:
18 - filename: Filename of u-boot.dtb (default 'u-boot.dtb')
20 See Entry_u_boot_ucode for full details of the three entries involved in
21 this process. This entry provides the U-Boot device-tree file, which
22 contains the microcode. If the microcode is not being collated into one
23 place then the offset and size of the microcode is recorded by this entry,
24 for use by u_boot_with_ucode_ptr. If it is being collated, then this
25 entry deletes the microcode from the device tree (to save space) and makes
26 it available to u_boot_ucode.
28 def __init__(self, section, etype, node):
29 Entry_blob.__init__(self, section, etype, node)
32 self.ucode_offset = None
33 self.ucode_size = None
37 def GetDefaultFilename(self):
40 def ProcessFdt(self, fdt):
41 # If the section does not need microcode, there is nothing to do
42 ucode_dest_entry = self.section.FindEntryType(
43 'u-boot-spl-with-ucode-ptr')
44 if not ucode_dest_entry or not ucode_dest_entry.target_offset:
45 ucode_dest_entry = self.section.FindEntryType(
46 'u-boot-with-ucode-ptr')
47 if not ucode_dest_entry or not ucode_dest_entry.target_offset:
50 # Remove the microcode
51 fname = self.GetDefaultFilename()
52 fdt = control.GetFdt(fname)
53 self.ucode = fdt.GetNode('/microcode')
55 raise self.Raise("No /microcode node found in '%s'" % fname)
57 # There's no need to collate it (move all microcode into one place)
58 # if we only have one chunk of microcode.
59 self.collate = len(self.ucode.subnodes) > 1
60 for node in self.ucode.subnodes:
61 data_prop = node.props.get('data')
63 self.ucode_data += ''.join(data_prop.bytes)
65 node.DeleteProp('data')
68 def ObtainContents(self):
69 # Call the base class just in case it does something important.
70 Entry_blob.ObtainContents(self)
71 self._pathname = control.GetFdtPath(self._filename)
74 for node in self.ucode.subnodes:
75 data_prop = node.props.get('data')
76 if data_prop and not self.collate:
77 # Find the offset in the device tree of the ucode data
78 self.ucode_offset = data_prop.GetOffset() + 12
79 self.ucode_size = len(data_prop.bytes)