1 # Copyright (c) 2016 Google, Inc
2 ## Written by Simon Glass <sjg@chromium.org>
4 # SPDX-License-Identifier: GPL-2.0+
6 # 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, image, etype, node):
21 Entry_blob.__init__(self, image, etype, node)
24 self.ucode_offset = None
25 self.ucode_size = None
27 def GetDefaultFilename(self):
30 def ObtainContents(self):
31 Entry_blob.ObtainContents(self)
33 # If the image does not need microcode, there is nothing to do
34 ucode_dest_entry = self.image.FindEntryType('u-boot-spl-with-ucode-ptr')
35 if not ucode_dest_entry or not ucode_dest_entry.target_pos:
36 ucode_dest_entry = self.image.FindEntryType('u-boot-with-ucode-ptr')
37 if not ucode_dest_entry or not ucode_dest_entry.target_pos:
40 # Create a new file to hold the copied device tree
41 dtb_name = 'u-boot-dtb-with-ucode.dtb'
42 fname = tools.GetOutputFilename(dtb_name)
43 with open(fname, 'wb') as fd:
46 # Remove the microcode
47 dtb = fdt.FdtScan(fname)
48 ucode = dtb.GetNode('/microcode')
50 raise self.Raise("No /microcode node found in '%s'" % fname)
52 # There's no need to collate it (move all microcode into one place)
53 # if we only have one chunk of microcode.
54 self.collate = len(ucode.subnodes) > 1
55 for node in ucode.subnodes:
56 data_prop = node.props.get('data')
58 self.ucode_data += ''.join(data_prop.bytes)
60 prop = node.DeleteProp('data')
62 # Find the offset in the device tree of the ucode data
63 self.ucode_offset = data_prop.GetOffset() + 12
64 self.ucode_size = len(data_prop.bytes)
69 # Make this file the contents of this entry
70 self._pathname = fname