binman: Expand documentation for entries
[oweals/u-boot.git] / tools / binman / etype / u_boot_dtb_with_ucode.py
1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
4 #
5 # Entry-type module for U-Boot device tree with the microcode removed
6 #
7
8 import control
9 import fdt
10 from entry import Entry
11 from blob import Entry_blob
12 import tools
13
14 class Entry_u_boot_dtb_with_ucode(Entry_blob):
15     """A U-Boot device tree file, with the microcode removed
16
17     Properties / Entry arguments:
18         - filename: Filename of u-boot.dtb (default 'u-boot.dtb')
19
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.
27     """
28     def __init__(self, section, etype, node):
29         Entry_blob.__init__(self, section, etype, node)
30         self.ucode_data = ''
31         self.collate = False
32         self.ucode_offset = None
33         self.ucode_size = None
34         self.ucode = None
35         self.ready = False
36
37     def GetDefaultFilename(self):
38         return 'u-boot.dtb'
39
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:
48             return True
49
50         # Remove the microcode
51         fname = self.GetDefaultFilename()
52         fdt = control.GetFdt(fname)
53         self.ucode = fdt.GetNode('/microcode')
54         if not self.ucode:
55             raise self.Raise("No /microcode node found in '%s'" % fname)
56
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')
62             if data_prop:
63                 self.ucode_data += ''.join(data_prop.bytes)
64                 if self.collate:
65                     node.DeleteProp('data')
66         return True
67
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)
72         self.ReadContents()
73         if self.ucode:
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)
80         self.ready = True
81         return True