summaryrefslogtreecommitdiff
path: root/tools/binman/etype
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-07-17 13:25:38 -0600
committerSimon Glass <sjg@chromium.org>2018-08-01 16:30:48 -0600
commit11e36ccea174043229319263f9d0b5b7f7cca654 (patch)
treeae97c27416a1f44cf45da09364480818784e4eea /tools/binman/etype
parent5a5da7ce153b19bc3106e0bdb625b2e211852914 (diff)
binman: Add support for flashrom FMAP
Add an entry which can hold an FMAP region as used by flashrom, an open-source flashing tool used on Linux x86 machines. This provides a simplified non-hierarchical view of the entries in the image and has a signature at the start to allow flashrom to find it in the image. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/etype')
-rw-r--r--tools/binman/etype/fmap.py61
-rw-r--r--tools/binman/etype/section.py7
2 files changed, 66 insertions, 2 deletions
diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
new file mode 100644
index 00000000000..f1dd81ec493
--- /dev/null
+++ b/tools/binman/etype/fmap.py
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass <sjg@chromium.org>
+#
+# Entry-type module for a Flash map, as used by the flashrom SPI flash tool
+#
+
+from entry import Entry
+import fmap_util
+
+
+class Entry_fmap(Entry):
+ """An entry which contains an Fmap section
+
+ Properties / Entry arguments:
+ None
+
+ FMAP is a simple format used by flashrom, an open-source utility for
+ reading and writing the SPI flash, typically on x86 CPUs. The format
+ provides flashrom with a list of areas, so it knows what it in the flash.
+ It can then read or write just a single area, instead of the whole flash.
+
+ The format is defined by the flashrom project, in the file lib/fmap.h -
+ see www.flashrom.org/Flashrom for more information.
+
+ When used, this entry will be populated with an FMAP which reflects the
+ entries in the current image. Note that any hierarchy is squashed, since
+ FMAP does not support this.
+ """
+ def __init__(self, section, etype, node):
+ Entry.__init__(self, section, etype, node)
+
+ def _GetFmap(self):
+ """Build an FMAP from the entries in the current image
+
+ Returns:
+ FMAP binary data
+ """
+ def _AddEntries(areas, entry):
+ entries = entry.GetEntries()
+ if entries:
+ for subentry in entries.values():
+ _AddEntries(areas, subentry)
+ else:
+ areas.append(fmap_util.FmapArea(entry.image_pos or 0,
+ entry.size or 0, entry.name, 0))
+
+ entries = self.section.GetEntries()
+ areas = []
+ for entry in entries.values():
+ _AddEntries(areas, entry)
+ return fmap_util.EncodeFmap(self.section.GetSize() or 0, self.name,
+ areas)
+
+ def ObtainContents(self):
+ """Obtain a placeholder for the fmap contents"""
+ self.SetContents(self._GetFmap())
+ return True
+
+ def ProcessContents(self):
+ self.SetContents(self._GetFmap())
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 2e68f276f0d..f5b2ed67cf8 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -30,8 +30,8 @@ class Entry_section(Entry):
hierarchical images to be created. See 'Sections and hierarchical images'
in the binman README for more information.
"""
- def __init__(self, image, etype, node):
- Entry.__init__(self, image, etype, node)
+ def __init__(self, section, etype, node):
+ Entry.__init__(self, section, etype, node)
self._section = bsection.Section(node.name, node)
def ProcessFdt(self, fdt):
@@ -89,3 +89,6 @@ class Entry_section(Entry):
fd: File to write the map to
"""
self._section.WriteMap(fd, indent)
+
+ def GetEntries(self):
+ return self._section.GetEntries()