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 Flash map, as used by the flashrom SPI flash tool
8 from entry import Entry
12 class Entry_fmap(Entry):
13 """An entry which contains an Fmap section
15 Properties / Entry arguments:
18 FMAP is a simple format used by flashrom, an open-source utility for
19 reading and writing the SPI flash, typically on x86 CPUs. The format
20 provides flashrom with a list of areas, so it knows what it in the flash.
21 It can then read or write just a single area, instead of the whole flash.
23 The format is defined by the flashrom project, in the file lib/fmap.h -
24 see www.flashrom.org/Flashrom for more information.
26 When used, this entry will be populated with an FMAP which reflects the
27 entries in the current image. Note that any hierarchy is squashed, since
28 FMAP does not support this.
30 def __init__(self, section, etype, node):
31 Entry.__init__(self, section, etype, node)
34 """Build an FMAP from the entries in the current image
39 def _AddEntries(areas, entry):
40 entries = entry.GetEntries()
42 for subentry in entries.values():
43 _AddEntries(areas, subentry)
45 areas.append(fmap_util.FmapArea(entry.image_pos or 0,
46 entry.size or 0, entry.name, 0))
48 entries = self.section.GetEntries()
50 for entry in entries.values():
51 _AddEntries(areas, entry)
52 return fmap_util.EncodeFmap(self.section.GetSize() or 0, self.name,
55 def ObtainContents(self):
56 """Obtain a placeholder for the fmap contents"""
57 self.SetContents(self._GetFmap())
60 def ProcessContents(self):
61 self.SetContents(self._GetFmap())