[U-Boot] [PATCH 06/31] binman: Tidy up the vblock entry
Simon Glass
sjg at chromium.org
Fri Sep 14 10:57:11 UTC 2018
At present if there are two vblock entries an image their contents are
written to the same file in the output directory. This prevents checking
the contents of each separately.
Fix this by adding part of the entry path to the filename, and add some
missing comments.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/binman/README.entries | 5 +++++
tools/binman/entry.py | 18 ++++++++++++++++++
tools/binman/entry_test.py | 11 +++++++++++
tools/binman/etype/vblock.py | 11 ++++++++---
tools/binman/ftest.py | 2 +-
5 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 31bc725d577..5cb52a92ff9 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -546,6 +546,11 @@ Properties / Entry arguments:
- kernelkey: Name of the kernel key to use (inside keydir)
- preamble-flags: Value of the vboot preamble flags (typically 0)
+Output files:
+ - input.<unique_name> - input file passed to futility
+ - vblock.<unique_name> - output file generated by futility (which is
+ used as the entry contents)
+
Chromium OS signs the read-write firmware and kernel, writing the signature
in this block. This allows U-Boot to verify that the next firmware stage
and kernel are genuine.
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 77cfab9c5de..e671a2ea094 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -456,3 +456,21 @@ features to produce new behaviours.
if missing:
raise ValueError('Documentation is missing for modules: %s' %
', '.join(missing))
+
+ def GetUniqueName(self):
+ """Get a unique name for a node
+
+ Returns:
+ String containing a unique name for a node, consisting of the name
+ of all ancestors (starting from within the 'binman' node) separated
+ by a dot ('.'). This can be useful for generating unique filesnames
+ in the output directory.
+ """
+ name = self.name
+ node = self._node
+ while node.parent:
+ node = node.parent
+ if node.name == 'binman':
+ break
+ name = '%s.%s' % (node.name, name)
+ return name
diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index 6fa735ed596..4100bcc3d32 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -54,6 +54,17 @@ class TestEntry(unittest.TestCase):
self.assertIn("Unknown entry type 'invalid-name' in node "
"'invalid-path'", str(e.exception))
+ def testUniqueName(self):
+ """Test Entry.GetUniqueName"""
+ import entry
+ Node = collections.namedtuple('Node', ['name', 'parent'])
+ base_node = Node('root', None)
+ base_entry = entry.Entry(None, None, base_node, read_node=False)
+ self.assertEqual('root', base_entry.GetUniqueName())
+ sub_node = Node('subnode', base_node)
+ sub_entry = entry.Entry(None, None, sub_node, read_node=False)
+ self.assertEqual('root.subnode', sub_entry.GetUniqueName())
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/binman/etype/vblock.py b/tools/binman/etype/vblock.py
index 595af5456d1..c4d970ed160 100644
--- a/tools/binman/etype/vblock.py
+++ b/tools/binman/etype/vblock.py
@@ -25,6 +25,11 @@ class Entry_vblock(Entry):
- kernelkey: Name of the kernel key to use (inside keydir)
- preamble-flags: Value of the vboot preamble flags (typically 0)
+ Output files:
+ - input.<unique_name> - input file passed to futility
+ - vblock.<unique_name> - output file generated by futility (which is
+ used as the entry contents)
+
Chromium OS signs the read-write firmware and kernel, writing the signature
in this block. This allows U-Boot to verify that the next firmware stage
and kernel are genuine.
@@ -53,8 +58,9 @@ class Entry_vblock(Entry):
return False
input_data += data
- output_fname = tools.GetOutputFilename('vblock.%s' % self.name)
- input_fname = tools.GetOutputFilename('input.%s' % self.name)
+ uniq = self.GetUniqueName()
+ output_fname = tools.GetOutputFilename('vblock.%s' % uniq)
+ input_fname = tools.GetOutputFilename('input.%s' % uniq)
tools.WriteFile(input_fname, input_data)
prefix = self.keydir + '/'
args = [
@@ -69,6 +75,5 @@ class Entry_vblock(Entry):
]
#out.Notice("Sign '%s' into %s" % (', '.join(self.value), self.label))
stdout = tools.Run('futility', *args)
- #out.Debug(stdout)
self.SetContents(tools.ReadFile(output_fname))
return True
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 3f4f5f3a43a..c4065551e79 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1316,7 +1316,7 @@ class TestFunctional(unittest.TestCase):
"""Fake calls to the futility utility"""
if pipe_list[0][0] == 'futility':
fname = pipe_list[0][3]
- with open(fname, 'w') as fd:
+ with open(fname, 'wb') as fd:
fd.write(VBLOCK_DATA)
return command.CommandResult()
--
2.19.0.397.gdd90340f6a-goog
More information about the U-Boot
mailing list