dtoc: Allow syncing of the device tree back to a file

At present we require the caller to manually update the device tree using
individual calls to libfdt functions. This is not ideal. It would be
better if we could make changes using the Python structure and then call a
Sync() function to write them back.

Add this feature to the Fdt class. Update binman and the tests to match.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 8c48008..ded1b71 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -183,6 +183,7 @@
                     image.AddMissingProperties()
                 image.ProcessFdt(dtb)
 
+            dtb.Sync(auto_resize=True)
             dtb.Pack()
             dtb.Flush()
 
@@ -199,6 +200,7 @@
                 image.SetImagePos()
                 if options.update_fdt:
                     image.SetCalculatedProperties()
+                    dtb.Sync()
                 image.ProcessEntryContents()
                 image.WriteSymbols()
                 image.BuildImage()