Commit a326b495cdcfd56507841e38158683e6e4d5894c

Authored by Simon Glass
1 parent 35b384cbe5

binman: Tidy up the vblock entry

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@chromium.org>

Showing 5 changed files with 43 additions and 4 deletions Side-by-side Diff

tools/binman/README.entries
... ... @@ -546,6 +546,11 @@
546 546 - kernelkey: Name of the kernel key to use (inside keydir)
547 547 - preamble-flags: Value of the vboot preamble flags (typically 0)
548 548  
  549 +Output files:
  550 + - input.<unique_name> - input file passed to futility
  551 + - vblock.<unique_name> - output file generated by futility (which is
  552 + used as the entry contents)
  553 +
549 554 Chromium OS signs the read-write firmware and kernel, writing the signature
550 555 in this block. This allows U-Boot to verify that the next firmware stage
551 556 and kernel are genuine.
tools/binman/entry.py
... ... @@ -456,4 +456,22 @@
456 456 if missing:
457 457 raise ValueError('Documentation is missing for modules: %s' %
458 458 ', '.join(missing))
  459 +
  460 + def GetUniqueName(self):
  461 + """Get a unique name for a node
  462 +
  463 + Returns:
  464 + String containing a unique name for a node, consisting of the name
  465 + of all ancestors (starting from within the 'binman' node) separated
  466 + by a dot ('.'). This can be useful for generating unique filesnames
  467 + in the output directory.
  468 + """
  469 + name = self.name
  470 + node = self._node
  471 + while node.parent:
  472 + node = node.parent
  473 + if node.name == 'binman':
  474 + break
  475 + name = '%s.%s' % (node.name, name)
  476 + return name
tools/binman/entry_test.py
... ... @@ -54,6 +54,17 @@
54 54 self.assertIn("Unknown entry type 'invalid-name' in node "
55 55 "'invalid-path'", str(e.exception))
56 56  
  57 + def testUniqueName(self):
  58 + """Test Entry.GetUniqueName"""
  59 + import entry
  60 + Node = collections.namedtuple('Node', ['name', 'parent'])
  61 + base_node = Node('root', None)
  62 + base_entry = entry.Entry(None, None, base_node, read_node=False)
  63 + self.assertEqual('root', base_entry.GetUniqueName())
  64 + sub_node = Node('subnode', base_node)
  65 + sub_entry = entry.Entry(None, None, sub_node, read_node=False)
  66 + self.assertEqual('root.subnode', sub_entry.GetUniqueName())
  67 +
57 68  
58 69 if __name__ == "__main__":
59 70 unittest.main()
tools/binman/etype/vblock.py
... ... @@ -25,6 +25,11 @@
25 25 - kernelkey: Name of the kernel key to use (inside keydir)
26 26 - preamble-flags: Value of the vboot preamble flags (typically 0)
27 27  
  28 + Output files:
  29 + - input.<unique_name> - input file passed to futility
  30 + - vblock.<unique_name> - output file generated by futility (which is
  31 + used as the entry contents)
  32 +
28 33 Chromium OS signs the read-write firmware and kernel, writing the signature
29 34 in this block. This allows U-Boot to verify that the next firmware stage
30 35 and kernel are genuine.
... ... @@ -53,8 +58,9 @@
53 58 return False
54 59 input_data += data
55 60  
56   - output_fname = tools.GetOutputFilename('vblock.%s' % self.name)
57   - input_fname = tools.GetOutputFilename('input.%s' % self.name)
  61 + uniq = self.GetUniqueName()
  62 + output_fname = tools.GetOutputFilename('vblock.%s' % uniq)
  63 + input_fname = tools.GetOutputFilename('input.%s' % uniq)
58 64 tools.WriteFile(input_fname, input_data)
59 65 prefix = self.keydir + '/'
60 66 args = [
... ... @@ -69,7 +75,6 @@
69 75 ]
70 76 #out.Notice("Sign '%s' into %s" % (', '.join(self.value), self.label))
71 77 stdout = tools.Run('futility', *args)
72   - #out.Debug(stdout)
73 78 self.SetContents(tools.ReadFile(output_fname))
74 79 return True
tools/binman/ftest.py
... ... @@ -1316,7 +1316,7 @@
1316 1316 """Fake calls to the futility utility"""
1317 1317 if pipe_list[0][0] == 'futility':
1318 1318 fname = pipe_list[0][3]
1319   - with open(fname, 'w') as fd:
  1319 + with open(fname, 'wb') as fd:
1320 1320 fd.write(VBLOCK_DATA)
1321 1321 return command.CommandResult()
1322 1322