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
13 class Entry_fmap(Entry):
14 """An entry which contains an Fmap section
16 Properties / Entry arguments:
19 FMAP is a simple format used by flashrom, an open-source utility for
20 reading and writing the SPI flash, typically on x86 CPUs. The format
21 provides flashrom with a list of areas, so it knows what it in the flash.
22 It can then read or write just a single area, instead of the whole flash.
24 The format is defined by the flashrom project, in the file lib/fmap.h -
25 see www.flashrom.org/Flashrom for more information.
27 When used, this entry will be populated with an FMAP which reflects the
28 entries in the current image. Note that any hierarchy is squashed, since
29 FMAP does not support this.
31 def __init__(self, section, etype, node):
32 Entry.__init__(self, section, etype, node)
35 """Build an FMAP from the entries in the current image
40 def _AddEntries(areas, entry):
41 entries = entry.GetEntries()
43 for subentry in entries.values():
44 _AddEntries(areas, subentry)
48 pos -= entry.section.GetRootSkipAtStart()
49 areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0,
50 tools.FromUnicode(entry.name), 0))
52 entries = self.GetImage().GetEntries()
54 for entry in entries.values():
55 _AddEntries(areas, entry)
56 return fmap_util.EncodeFmap(self.section.GetImageSize() or 0, self.name,
59 def ObtainContents(self):
60 """Obtain a placeholder for the fmap contents"""
61 self.SetContents(self._GetFmap())
64 def ProcessContents(self):
65 return self.ProcessContentsUpdate(self._GetFmap())