]> git.sur5r.net Git - u-boot/blobdiff - tools/binman/control.py
binman: Add a ProcessFdt() method
[u-boot] / tools / binman / control.py
index 92434729061c1669c656975846ecd1c8747569cf..5325a6a00669d2c40d159d5770f853f3c5c0ab92 100644 (file)
@@ -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
 
@@ -93,12 +116,39 @@ def Binman(options, args):
         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():
+                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