2018-07-18 04:25:38 +09:00
|
|
|
# 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
|
2019-05-18 13:00:48 +09:00
|
|
|
import tools
|
2019-07-21 03:24:00 +09:00
|
|
|
from tools import ToHexSize
|
|
|
|
import tout
|
2018-07-18 04:25:38 +09:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2019-07-21 03:24:00 +09:00
|
|
|
FMAP does not support this. Also, CBFS entries appear as a single entry -
|
|
|
|
the sub-entries are ignored.
|
2018-07-18 04:25:38 +09:00
|
|
|
"""
|
|
|
|
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()
|
2019-07-21 03:24:00 +09:00
|
|
|
tout.Debug("fmap: Add entry '%s' type '%s' (%s subentries)" %
|
|
|
|
(entry.GetPath(), entry.etype, ToHexSize(entries)))
|
|
|
|
if entries and entry.etype != 'cbfs':
|
2018-07-18 04:25:38 +09:00
|
|
|
for subentry in entries.values():
|
|
|
|
_AddEntries(areas, subentry)
|
|
|
|
else:
|
2018-09-14 19:57:34 +09:00
|
|
|
pos = entry.image_pos
|
|
|
|
if pos is not None:
|
|
|
|
pos -= entry.section.GetRootSkipAtStart()
|
|
|
|
areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0,
|
2019-05-18 13:00:48 +09:00
|
|
|
tools.FromUnicode(entry.name), 0))
|
2018-07-18 04:25:38 +09:00
|
|
|
|
2019-07-21 03:23:46 +09:00
|
|
|
entries = self.GetImage().GetEntries()
|
2018-07-18 04:25:38 +09:00
|
|
|
areas = []
|
|
|
|
for entry in entries.values():
|
|
|
|
_AddEntries(areas, entry)
|
2018-09-14 19:57:34 +09:00
|
|
|
return fmap_util.EncodeFmap(self.section.GetImageSize() or 0, self.name,
|
2018-07-18 04:25:38 +09:00
|
|
|
areas)
|
|
|
|
|
|
|
|
def ObtainContents(self):
|
|
|
|
"""Obtain a placeholder for the fmap contents"""
|
|
|
|
self.SetContents(self._GetFmap())
|
|
|
|
return True
|
|
|
|
|
|
|
|
def ProcessContents(self):
|
2019-07-09 05:25:35 +09:00
|
|
|
return self.ProcessContentsUpdate(self._GetFmap())
|