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
8 from entry import Entry
9 from blob_dtb import Entry_blob_dtb
13 class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
14 """A U-Boot device tree file, with the microcode removed
16 Properties / Entry arguments:
17 - filename: Filename of u-boot.dtb (default 'u-boot.dtb')
19 See Entry_u_boot_ucode for full details of the three entries involved in
20 this process. This entry provides the U-Boot device-tree file, which
21 contains the microcode. If the microcode is not being collated into one
22 place then the offset and size of the microcode is recorded by this entry,
23 for use by u_boot_with_ucode_ptr. If it is being collated, then this
24 entry deletes the microcode from the device tree (to save space) and makes
25 it available to u_boot_ucode.
27 def __init__(self, section, etype, node):
28 Entry_blob_dtb.__init__(self, section, etype, node)
31 self.ucode_offset = None
32 self.ucode_size = None
36 def GetDefaultFilename(self):
39 def GetFdtEtype(self):
42 def ProcessFdt(self, fdt):
43 # So the module can be loaded without it
46 # If the section does not need microcode, there is nothing to do
47 ucode_dest_entry = self.section.FindEntryType(
48 'u-boot-spl-with-ucode-ptr')
49 if not ucode_dest_entry or not ucode_dest_entry.target_offset:
50 ucode_dest_entry = self.section.FindEntryType(
51 'u-boot-tpl-with-ucode-ptr')
52 if not ucode_dest_entry or not ucode_dest_entry.target_offset:
53 ucode_dest_entry = self.section.FindEntryType(
54 'u-boot-with-ucode-ptr')
55 if not ucode_dest_entry or not ucode_dest_entry.target_offset:
58 # Remove the microcode
59 etype = self.GetFdtEtype()
60 fdt = state.GetFdtForEtype(etype)
61 self.ucode = fdt.GetNode('/microcode')
63 raise self.Raise("No /microcode node found in '%s'" % etype)
65 # There's no need to collate it (move all microcode into one place)
66 # if we only have one chunk of microcode.
67 self.collate = len(self.ucode.subnodes) > 1
68 for node in self.ucode.subnodes:
69 data_prop = node.props.get('data')
71 self.ucode_data += data_prop.bytes
73 node.DeleteProp('data')
76 def ObtainContents(self):
77 # Call the base class just in case it does something important.
78 Entry_blob_dtb.ObtainContents(self)
79 if self.ucode and not self.collate:
80 for node in self.ucode.subnodes:
81 data_prop = node.props.get('data')
83 # Find the offset in the device tree of the ucode data
84 self.ucode_offset = data_prop.GetOffset() + 12
85 self.ucode_size = len(data_prop.bytes)