]> git.sur5r.net Git - u-boot/blobdiff - tools/binman/control.py
binman: Add a SetCalculatedProperties() method
[u-boot] / tools / binman / control.py
index e9d48df03014cde346fd9175c5d32fb8b6d75e9a..eafabf05c7cbaf5584bd097803ade468ffeb9863 100644 (file)
@@ -1,8 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0+
 # Copyright (c) 2016 Google, Inc
 # Written by Simon Glass <sjg@chromium.org>
 #
-# SPDX-License-Identifier:      GPL-2.0+
-#
 # Creates binary images from input files controlled by a description
 #
 
@@ -12,6 +11,7 @@ import sys
 import tools
 
 import command
+import elf
 import fdt
 import fdt_util
 from image import Image
@@ -21,6 +21,11 @@ import tout
 # 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
 
@@ -53,6 +58,24 @@ def _FindBinmanNode(dtb):
             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
 
@@ -89,15 +112,45 @@ def Binman(options, args):
 
     try:
         tout.Init(options.verbosity)
+        elf.debug = options.debug
         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
@@ -108,8 +161,13 @@ def Binman(options, args):
                 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: