binman: Adjust state.fdt_files to be keyed by entry type

It makes more sense to use entry type as the key for this dictionary,
since the filename can in principle be anything. Make this change and also
rename fdt_files and add a comment to explain it better.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2019-07-20 12:23:32 -06:00
parent 4bdd30055c
commit fb5e8b163e
3 changed files with 38 additions and 29 deletions

View File

@@ -23,12 +23,12 @@ class Entry_blob_dtb(Entry_blob):
def ObtainContents(self): def ObtainContents(self):
"""Get the device-tree from the list held by the 'state' module""" """Get the device-tree from the list held by the 'state' module"""
self._filename = self.GetDefaultFilename() self._filename = self.GetDefaultFilename()
self._pathname, _ = state.GetFdtContents(self._filename) self._pathname, _ = state.GetFdtContents(self.GetFdtEtype())
return Entry_blob.ReadBlobContents(self) return Entry_blob.ReadBlobContents(self)
def ProcessContents(self): def ProcessContents(self):
"""Re-read the DTB contents so that we get any calculated properties""" """Re-read the DTB contents so that we get any calculated properties"""
_, indata = state.GetFdtContents(self._filename) _, indata = state.GetFdtContents(self.GetFdtEtype())
data = self.CompressData(indata) data = self.CompressData(indata)
return self.ProcessContentsUpdate(data) return self.ProcessContentsUpdate(data)

View File

@@ -56,11 +56,11 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob_dtb):
return True return True
# Remove the microcode # Remove the microcode
fname = self.GetDefaultFilename() etype = self.GetFdtEtype()
fdt = state.GetFdtForEtype(fname) fdt = state.GetFdtForEtype(etype)
self.ucode = fdt.GetNode('/microcode') self.ucode = fdt.GetNode('/microcode')
if not self.ucode: if not self.ucode:
raise self.Raise("No /microcode node found in '%s'" % fname) raise self.Raise("No /microcode node found in '%s'" % etype)
# There's no need to collate it (move all microcode into one place) # There's no need to collate it (move all microcode into one place)
# if we only have one chunk of microcode. # if we only have one chunk of microcode.

View File

@@ -11,9 +11,15 @@ import re
import os import os
import tools import tools
# Records the device-tree files known to binman, keyed by filename (e.g. # Records the device-tree files known to binman, keyed by entry type (e.g.
# 'u-boot-spl.dtb') # 'u-boot-spl-dtb'). These are the output FDT files, which can be updated by
fdt_files = {} # binman. They have been copied to <xxx>.out files.
#
# key: entry type
# value: tuple:
# Fdt object
# Filename
output_fdt_files = {}
# Arguments passed to binman to provide arguments to entries # Arguments passed to binman to provide arguments to entries
entry_args = {} entry_args = {}
@@ -36,36 +42,36 @@ main_dtb = None
# Entry.ProcessContentsUpdate() # Entry.ProcessContentsUpdate()
allow_entry_expansion = True allow_entry_expansion = True
def GetFdtForEtype(fname): def GetFdtForEtype(etype):
"""Get the Fdt object for a particular device-tree filename """Get the Fdt object for a particular device-tree entry
Binman keeps track of at least one device-tree file called u-boot.dtb but Binman keeps track of at least one device-tree file called u-boot.dtb but
can also have others (e.g. for SPL). This function looks up the given can also have others (e.g. for SPL). This function looks up the given
filename and returns the associated Fdt object. entry and returns the associated Fdt object.
Args: Args:
fname: Filename to look up (e.g. 'u-boot.dtb'). etype: Entry type of device tree (e.g. 'u-boot-dtb')
Returns: Returns:
Fdt object associated with the filename Fdt object associated with the entry type
""" """
return fdt_files[fname] return output_fdt_files[etype][0]
def GetFdtPath(fname): def GetFdtPath(etype):
"""Get the full pathname of a particular Fdt object """Get the full pathname of a particular Fdt object
Similar to GetFdtForEtype() but returns the pathname associated with the Similar to GetFdtForEtype() but returns the pathname associated with the
Fdt. Fdt.
Args: Args:
fname: Filename to look up (e.g. 'u-boot.dtb'). etype: Entry type of device tree (e.g. 'u-boot-dtb')
Returns: Returns:
Full path name to the associated Fdt Full path name to the associated Fdt
""" """
return fdt_files[fname]._fname return output_fdt_files[etype][0]._fname
def GetFdtContents(fname='u-boot.dtb'): def GetFdtContents(etype='u-boot-dtb'):
"""Looks up the FDT pathname and contents """Looks up the FDT pathname and contents
This is used to obtain the Fdt pathname and contents when needed by an This is used to obtain the Fdt pathname and contents when needed by an
@@ -73,17 +79,18 @@ def GetFdtContents(fname='u-boot.dtb'):
the real dtb. the real dtb.
Args: Args:
fname: Filename to look up (e.g. 'u-boot.dtb'). etype: Entry type to look up (e.g. 'u-boot.dtb').
Returns: Returns:
tuple: tuple:
pathname to Fdt pathname to Fdt
Fdt data (as bytes) Fdt data (as bytes)
""" """
if fname in fdt_files and not use_fake_dtb: if etype in output_fdt_files and not use_fake_dtb:
pathname = GetFdtPath(fname) pathname = GetFdtPath(etype)
data = GetFdtForEtype(fname).GetContents() data = GetFdtForEtype(etype).GetContents()
else: else:
fname = output_fdt_files[etype][1]
pathname = tools.GetInputFilename(fname) pathname = tools.GetInputFilename(fname)
data = tools.ReadFile(pathname) data = tools.ReadFile(pathname)
return pathname, data return pathname, data
@@ -128,7 +135,7 @@ def Prepare(images, dtb):
images: List of images being used images: List of images being used
dtb: Main dtb dtb: Main dtb
""" """
global fdt_set, fdt_subset, fdt_files, main_dtb global fdt_set, fdt_subset, output_fdt_files, main_dtb
# Import these here in case libfdt.py is not available, in which case # Import these here in case libfdt.py is not available, in which case
# the above help option still works. # the above help option still works.
import fdt import fdt
@@ -139,8 +146,10 @@ def Prepare(images, dtb):
# since it is assumed to be the one passed in with options.dt, and # since it is assumed to be the one passed in with options.dt, and
# was handled just above. # was handled just above.
main_dtb = dtb main_dtb = dtb
fdt_files.clear() output_fdt_files.clear()
fdt_files['u-boot.dtb'] = dtb output_fdt_files['u-boot-dtb'] = [dtb, 'u-boot.dtb']
output_fdt_files['u-boot-spl-dtb'] = [dtb, 'spl/u-boot-spl.dtb']
output_fdt_files['u-boot-tpl-dtb'] = [dtb, 'tpl/u-boot-tpl.dtb']
fdt_subset = {} fdt_subset = {}
if not use_fake_dtb: if not use_fake_dtb:
for image in images.values(): for image in images.values():
@@ -155,7 +164,7 @@ def Prepare(images, dtb):
os.path.split(other_fname)[1]) os.path.split(other_fname)[1])
tools.WriteFile(out_fname, tools.ReadFile(other_fname_dtb)) tools.WriteFile(out_fname, tools.ReadFile(other_fname_dtb))
other_dtb = fdt.FdtScan(out_fname) other_dtb = fdt.FdtScan(out_fname)
fdt_files[other_fname] = other_dtb output_fdt_files[etype] = [other_dtb, other_fname]
def GetAllFdts(): def GetAllFdts():
"""Yield all device tree files being used by binman """Yield all device tree files being used by binman
@@ -164,8 +173,8 @@ def GetAllFdts():
Device trees being used (U-Boot proper, SPL, TPL) Device trees being used (U-Boot proper, SPL, TPL)
""" """
yield main_dtb yield main_dtb
for etype, other_fname in fdt_subset.values(): for etype in fdt_subset:
yield fdt_files[other_fname] yield output_fdt_files[etype][0]
def GetUpdateNodes(node): def GetUpdateNodes(node):
"""Yield all the nodes that need to be updated in all device trees """Yield all the nodes that need to be updated in all device trees
@@ -182,7 +191,7 @@ def GetUpdateNodes(node):
is node, SPL and TPL) is node, SPL and TPL)
""" """
yield node yield node
for dtb in fdt_files.values(): for dtb, fname in output_fdt_files.values():
if dtb != node.GetFdt(): if dtb != node.GetFdt():
other_node = dtb.GetNode(node.path) other_node = dtb.GetNode(node.path)
if other_node: if other_node: