diff options
author | Simon Glass <sjg@chromium.org> | 2021-03-21 08:24:31 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-03-27 06:26:48 +0300 |
commit | 189f291914cb867f8782d7224a1073d6e17fc800 (patch) | |
tree | f848d1a376d44180ce736afba75c34bc0f2b4b67 /tools/binman/etype | |
parent | 3d4333829388db834e6f0945bbefc837da590d78 (diff) | |
download | u-boot-189f291914cb867f8782d7224a1073d6e17fc800.tar.xz |
binman: Add support for a collection of entries
The vblock entry type includes code to collect the data from a number of
other entries (not necessarily subentries) and concatenating it. This is
a useful feature for other entry types.
Make it a base class, so that vblock can use it, along with other entry
types.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/etype')
-rw-r--r-- | tools/binman/etype/collection.py | 61 | ||||
-rw-r--r-- | tools/binman/etype/vblock.py | 26 |
2 files changed, 74 insertions, 13 deletions
diff --git a/tools/binman/etype/collection.py b/tools/binman/etype/collection.py new file mode 100644 index 0000000000..c0c552ac4f --- /dev/null +++ b/tools/binman/etype/collection.py @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2021 Google LLC +# Written by Simon Glass <sjg@chromium.org> +# + +# Support for a collection of entries from other parts of an image + +from collections import OrderedDict +import os + +from binman.entry import Entry +from dtoc import fdt_util + +class Entry_collection(Entry): + """An entry which contains a collection of other entries + + Properties / Entry arguments: + - content: List of phandles to entries to include + + This allows reusing the contents of other entries. The contents of the + listed entries are combined to form this entry. This serves as a useful + base class for entry types which need to process data from elsewhere in + the image, not necessarily child entries. + """ + def __init__(self, section, etype, node): + super().__init__(section, etype, node) + self.content = fdt_util.GetPhandleList(self._node, 'content') + if not self.content: + self.Raise("Collection must have a 'content' property") + + def GetContents(self): + """Get the contents of this entry + + Returns: + bytes content of the entry + """ + # Join up all the data + self.Info('Getting content') + data = b'' + for entry_phandle in self.content: + entry_data = self.section.GetContentsByPhandle(entry_phandle, self) + if entry_data is None: + # Data not available yet + return None + data += entry_data + + self.Info('Returning contents size %x' % len(data)) + + return data + + def ObtainContents(self): + data = self.GetContents() + if data is None: + return False + self.SetContents(data) + return True + + def ProcessContents(self): + # The blob may have changed due to WriteSymbols() + data = self.GetContents() + return self.ProcessContentsUpdate(data) diff --git a/tools/binman/etype/vblock.py b/tools/binman/etype/vblock.py index eba5351dd5..d473083cab 100644 --- a/tools/binman/etype/vblock.py +++ b/tools/binman/etype/vblock.py @@ -9,12 +9,13 @@ from collections import OrderedDict import os -from binman.entry import Entry, EntryArg +from binman.entry import EntryArg +from binman.etype.collection import Entry_collection from dtoc import fdt_util from patman import tools -class Entry_vblock(Entry): +class Entry_vblock(Entry_collection): """An entry which contains a Chromium OS verified boot block Properties / Entry arguments: @@ -37,9 +38,6 @@ class Entry_vblock(Entry): """ def __init__(self, section, etype, node): super().__init__(section, etype, node) - self.content = fdt_util.GetPhandleList(self._node, 'content') - if not self.content: - self.Raise("Vblock must have a 'content' property") (self.keydir, self.keyblock, self.signprivate, self.version, self.kernelkey, self.preamble_flags) = self.GetEntryArgsOrProps([ EntryArg('keydir', str), @@ -50,14 +48,16 @@ class Entry_vblock(Entry): EntryArg('preamble-flags', int)]) def GetVblock(self): + """Get the contents of this entry + + Returns: + bytes content of the entry, which is the signed vblock for the + provided data + """ # Join up the data files to be signed - input_data = b'' - for entry_phandle in self.content: - data = self.section.GetContentsByPhandle(entry_phandle, self) - if data is None: - # Data not available yet - return False - input_data += data + input_data = self.GetContents() + if input_data is None: + return None uniq = self.GetUniqueName() output_fname = tools.GetOutputFilename('vblock.%s' % uniq) @@ -80,7 +80,7 @@ class Entry_vblock(Entry): def ObtainContents(self): data = self.GetVblock() - if data is False: + if data is None: return False self.SetContents(data) return True |