binman: Convert to using the futility bintool

Update the GBB and vblock entry types to use this bintool, instead of
running futility directly. This simplifies the code and provides more
consistency as well as supporting missing bintools.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2022-01-09 20:14:00 -07:00
parent 388f04fb67
commit a104bb2b48
2 changed files with 39 additions and 26 deletions

View file

@ -77,20 +77,27 @@ class Entry_gbb(Entry):
bmpfv_size = gbb_size - 0x2180
if bmpfv_size < 0:
self.Raise('GBB is too small (minimum 0x2180 bytes)')
sizes = [0x100, 0x1000, bmpfv_size, 0x1000]
sizes = ['%#x' % size for size in sizes]
keydir = tools.GetInputFilename(self.keydir)
gbb_set_command = [
'gbb_utility', '-s',
'--hwid=%s' % self.hardware_id,
'--rootkey=%s/root_key.vbpubk' % keydir,
'--recoverykey=%s/recovery_key.vbpubk' % keydir,
'--flags=%d' % self.gbb_flags,
'--bmpfv=%s' % tools.GetInputFilename(self.bmpblk),
fname]
tools.Run('futility', 'gbb_utility', '-c', ','.join(sizes), fname)
tools.Run('futility', *gbb_set_command)
stdout = self.futility.gbb_create(
fname, [0x100, 0x1000, bmpfv_size, 0x1000])
if stdout is not None:
stdout = self.futility.gbb_set(
fname,
hwid=self.hardware_id,
rootkey='%s/root_key.vbpubk' % keydir,
recoverykey='%s/recovery_key.vbpubk' % keydir,
flags=self.gbb_flags,
bmpfv=tools.GetInputFilename(self.bmpblk))
if stdout is not None:
self.SetContents(tools.ReadFile(fname))
else:
# Bintool is missing; just use the required amount of zero data
self.record_missing_bintool(self.futility)
self.SetContents(tools.GetBytes(0, gbb_size))
self.SetContents(tools.ReadFile(fname))
return True
def AddBintools(self, tools):
self.futility = self.AddBintool(tools, 'futility')

View file

@ -38,6 +38,7 @@ class Entry_vblock(Entry_collection):
"""
def __init__(self, section, etype, node):
super().__init__(section, etype, node)
self.futility = None
(self.keydir, self.keyblock, self.signprivate, self.version,
self.kernelkey, self.preamble_flags) = self.GetEntryArgsOrProps([
EntryArg('keydir', str),
@ -68,19 +69,21 @@ class Entry_vblock(Entry_collection):
input_fname = tools.GetOutputFilename('input.%s' % uniq)
tools.WriteFile(input_fname, input_data)
prefix = self.keydir + '/'
args = [
'vbutil_firmware',
'--vblock', output_fname,
'--keyblock', prefix + self.keyblock,
'--signprivate', prefix + self.signprivate,
'--version', '%d' % self.version,
'--fv', input_fname,
'--kernelkey', prefix + self.kernelkey,
'--flags', '%d' % self.preamble_flags,
]
#out.Notice("Sign '%s' into %s" % (', '.join(self.value), self.label))
stdout = tools.Run('futility', *args)
return tools.ReadFile(output_fname)
stdout = self.futility.sign_firmware(
vblock=output_fname,
keyblock=prefix + self.keyblock,
signprivate=prefix + self.signprivate,
version=f'{self.version,}',
firmware=input_fname,
kernelkey=prefix + self.kernelkey,
flags=f'{self.preamble_flags}')
if stdout is not None:
data = tools.ReadFile(output_fname)
else:
# Bintool is missing; just use 4KB of zero data
self.record_missing_bintool(self.futility)
data = tools.GetBytes(0, 4096)
return data
def ObtainContents(self):
data = self.GetVblock(False)
@ -93,3 +96,6 @@ class Entry_vblock(Entry_collection):
# The blob may have changed due to WriteSymbols()
data = self.GetVblock(True)
return self.ProcessContentsUpdate(data)
def AddBintools(self, tools):
self.futility = self.AddBintool(tools, 'futility')