]>
Commit | Line | Data |
---|---|---|
11e36cce SG |
1 | # SPDX-License-Identifier: GPL-2.0+ |
2 | # Copyright (c) 2018 Google, Inc | |
3 | # Written by Simon Glass <[email protected]> | |
4 | # | |
5 | # Entry-type module for a Flash map, as used by the flashrom SPI flash tool | |
6 | # | |
7 | ||
16287933 SG |
8 | from binman.entry import Entry |
9 | from binman import fmap_util | |
bf776679 | 10 | from patman import tools |
16287933 | 11 | from patman.tools import ToHexSize |
bf776679 | 12 | from patman import tout |
11e36cce SG |
13 | |
14 | ||
15 | class Entry_fmap(Entry): | |
16 | """An entry which contains an Fmap section | |
17 | ||
18 | Properties / Entry arguments: | |
19 | None | |
20 | ||
21 | FMAP is a simple format used by flashrom, an open-source utility for | |
22 | reading and writing the SPI flash, typically on x86 CPUs. The format | |
23 | provides flashrom with a list of areas, so it knows what it in the flash. | |
24 | It can then read or write just a single area, instead of the whole flash. | |
25 | ||
26 | The format is defined by the flashrom project, in the file lib/fmap.h - | |
27 | see www.flashrom.org/Flashrom for more information. | |
28 | ||
29 | When used, this entry will be populated with an FMAP which reflects the | |
30 | entries in the current image. Note that any hierarchy is squashed, since | |
95a0f3c6 SG |
31 | FMAP does not support this. Also, CBFS entries appear as a single entry - |
32 | the sub-entries are ignored. | |
11e36cce SG |
33 | """ |
34 | def __init__(self, section, etype, node): | |
35 | Entry.__init__(self, section, etype, node) | |
36 | ||
37 | def _GetFmap(self): | |
38 | """Build an FMAP from the entries in the current image | |
39 | ||
40 | Returns: | |
41 | FMAP binary data | |
42 | """ | |
43 | def _AddEntries(areas, entry): | |
44 | entries = entry.GetEntries() | |
95a0f3c6 SG |
45 | tout.Debug("fmap: Add entry '%s' type '%s' (%s subentries)" % |
46 | (entry.GetPath(), entry.etype, ToHexSize(entries))) | |
47 | if entries and entry.etype != 'cbfs': | |
11e36cce SG |
48 | for subentry in entries.values(): |
49 | _AddEntries(areas, subentry) | |
50 | else: | |
f8f8df6e SG |
51 | pos = entry.image_pos |
52 | if pos is not None: | |
53 | pos -= entry.section.GetRootSkipAtStart() | |
54 | areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0, | |
f3a58c8a | 55 | tools.FromUnicode(entry.name), 0)) |
11e36cce | 56 | |
c5ad04b7 | 57 | entries = self.GetImage().GetEntries() |
11e36cce SG |
58 | areas = [] |
59 | for entry in entries.values(): | |
60 | _AddEntries(areas, entry) | |
f8f8df6e | 61 | return fmap_util.EncodeFmap(self.section.GetImageSize() or 0, self.name, |
11e36cce SG |
62 | areas) |
63 | ||
64 | def ObtainContents(self): | |
65 | """Obtain a placeholder for the fmap contents""" | |
66 | self.SetContents(self._GetFmap()) | |
67 | return True | |
68 | ||
69 | def ProcessContents(self): | |
a0dcaf20 | 70 | return self.ProcessContentsUpdate(self._GetFmap()) |