# Make this global so that it can be referenced from tests
images = OrderedDict()
+# Records the device-tree files known to binman, keyed by filename (e.g.
+# 'u-boot-spl.dtb')
+fdt_files = {}
+
+
def _ReadImageDesc(binman_node):
"""Read the image descriptions from the /binman node
return node
return None
+def GetFdt(fname):
+ """Get the Fdt object for a particular device-tree filename
+
+ 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
+ filename and returns the associated Fdt object.
+
+ Args:
+ fname: Filename to look up (e.g. 'u-boot.dtb').
+
+ Returns:
+ Fdt object associated with the filename
+ """
+ return fdt_files[fname]
+
+def GetFdtPath(fname):
+ return fdt_files[fname]._fname
+
def Binman(options, args):
"""The main control code for binman
try:
tools.SetInputDirs(options.indir)
tools.PrepareOutputDir(options.outdir, options.preserve)
- dtb = fdt.FdtScan(dtb_fname)
+
+ # Get the device tree ready by compiling it and copying the compiled
+ # output into a file in our output directly. Then scan it for use
+ # in binman.
+ dtb_fname = fdt_util.EnsureCompiled(dtb_fname)
+ fname = tools.GetOutputFilename('u-boot-out.dtb')
+ with open(dtb_fname) as infd:
+ with open(fname, 'wb') as outfd:
+ outfd.write(infd.read())
+ dtb = fdt.FdtScan(fname)
+
+ # Note the file so that GetFdt() can find it
+ fdt_files['u-boot.dtb'] = dtb
node = _FindBinmanNode(dtb)
if not node:
raise ValueError("Device tree '%s' does not have a 'binman' "
"node" % dtb_fname)
+
images = _ReadImageDesc(node)
+
+ # Prepare the device tree by making sure that any missing
+ # properties are added (e.g. 'pos' and 'size'). The values of these
+ # may not be correct yet, but we add placeholders so that the
+ # size of the device tree is correct. Later, in
+ # SetCalculatedProperties() we will insert the correct values
+ # without changing the device-tree size, thus ensuring that our
+ # entry positions remain the same.
+ for image in images.values():
+ if options.update_fdt:
+ image.AddMissingProperties()
+ image.ProcessFdt(dtb)
+
+ dtb.Pack()
+ dtb.Flush()
+
for image in images.values():
# Perform all steps for this image, including checking and
# writing it. This means that errors found with a later
image.PackEntries()
image.CheckSize()
image.CheckEntries()
+ if options.update_fdt:
+ image.SetCalculatedProperties()
image.ProcessEntryContents()
image.WriteSymbols()
image.BuildImage()
+ if options.map:
+ image.WriteMap()
finally:
tools.FinaliseOutputDir()
finally: