1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2018 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
5 """# Entry-type module for a full map of the firmware image
7 This handles putting an FDT into the image with just the information about the
13 from entry import Entry
18 FDTMAP_MAGIC = b'_FDTMAP_'
20 class Entry_fdtmap(Entry):
21 """An entry which contains an FDT map
23 Properties / Entry arguments:
26 An FDT map is just a header followed by an FDT containing a list of all the
29 The header is the string _FDTMAP_ followed by 8 unused bytes.
31 When used, this entry will be populated with an FDT map which reflects the
32 entries in the current image. Hierarchy is preserved, and all offsets and
35 Note that the -u option must be provided to ensure that binman updates the
36 FDT with the position of each entry.
38 Example output for a simple image with U-Boot and an FDT map:
42 image-pos = <0x00000000>;
43 offset = <0x00000000>;
46 image-pos = <0x00000000>;
47 offset = <0x00000000>;
51 image-pos = <0x00000004>;
52 offset = <0x00000004>;
56 def __init__(self, section, etype, node):
57 Entry.__init__(self, section, etype, node)
60 """Build an FDT map from the entries in the current image
66 """Add a node to the FDT map"""
67 for pname, prop in node.props.items():
68 fsw.property(pname, prop.bytes)
69 for subnode in node.subnodes:
70 with fsw.add_node(subnode.name):
73 # Get the FDT data into an Fdt object
74 data = state.GetFdtContents()[1]
75 infdt = Fdt.FromData(data)
78 # Find the node for the image containing the Fdt-map entry
79 path = self.section.GetPath()
80 node = infdt.GetNode(path)
82 self.Raise("Internal error: Cannot locate node for path '%s'" %
85 # Build a new tree with all nodes and properties starting from that node
87 fsw.finish_reservemap()
88 with fsw.add_node(''):
92 # Pack this new FDT and return its contents
94 outfdt = Fdt.FromData(fdt.as_bytearray())
95 data = FDTMAP_MAGIC + tools.GetBytes(0, 8) + outfdt.GetContents()
98 def ObtainContents(self):
99 """Obtain a placeholder for the fdt-map contents"""
100 self.SetContents(self._GetFdtmap())
103 def ProcessContents(self):
104 """Write an updated version of the FDT map to this entry
106 This is necessary since new data may have been written back to it during
107 processing, e.g. the image-pos properties.
109 return self.ProcessContentsUpdate(self._GetFdtmap())