[PATCH 3/8] binman: Add a null entry

Simon Glass sjg at chromium.org
Thu Jan 12 00:10:14 CET 2023


It is sometimes useful to define an entry which does not have its own
contents but does appear in the image. The contents are set by the section
which contains it, even though it appears as an entry in the fdtmap.

Add support for this.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/entries.rst       | 13 +++++++++++++
 tools/binman/entry.py          |  5 +++--
 tools/binman/etype/null.py     | 25 +++++++++++++++++++++++++
 tools/binman/etype/section.py  |  6 ++++++
 tools/binman/ftest.py          |  5 +++++
 tools/binman/test/268_null.dts | 19 +++++++++++++++++++
 6 files changed, 71 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/etype/null.py
 create mode 100644 tools/binman/test/268_null.dts

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index f6cc8003853..2b32c131ede 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -1278,6 +1278,19 @@ This will pass in u-boot-spl as the input data and the .cfgout file as the
 
 
 
+.. _etype_null:
+
+Entry: null: An entry which has no contents of its own
+------------------------------------------------------
+
+Note that the size property must be set since otherwise this entry does not
+know how large it should be.
+
+The contents are set by the containing section, e.g. the section's pad
+byte.
+
+
+
 .. _etype_opensbi:
 
 Entry: opensbi: RISC-V OpenSBI fw_dynamic blob
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index f99618d4532..e6ff026ddb8 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -454,7 +454,7 @@ class Entry(object):
 
         Returns:
             True if the contents were found, False if another call is needed
-            after the other entries are processed.
+            after the other entries are processed, None if there is no contents
         """
         # No contents by default: subclasses can implement this
         return True
@@ -583,7 +583,8 @@ class Entry(object):
         Returns:
             bytes content of the entry, excluding any padding. If the entry is
                 compressed, the compressed data is returned. If the entry data
-                is not yet available, False can be returned
+                is not yet available, False can be returned. If the entry data
+                is null, then None is returned.
         """
         self.Detail('GetData: size %s' % to_hex_size(self.data))
         return self.data
diff --git a/tools/binman/etype/null.py b/tools/binman/etype/null.py
new file mode 100644
index 00000000000..c10d4824472
--- /dev/null
+++ b/tools/binman/etype/null.py
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2023 Google LLC
+# Written by Simon Glass <sjg at chromium.org>
+#
+
+from binman.entry import Entry
+from dtoc import fdt_util
+from patman import tools
+
+class Entry_null(Entry):
+    """An entry which has no contents of its own
+
+    Note that the size property must be set since otherwise this entry does not
+    know how large it should be.
+
+    The contents are set by the containing section, e.g. the section's pad
+    byte.
+    """
+    def __init__(self, section, etype, node):
+        super().__init__(section, etype, node)
+        self.required_props = ['size']
+
+    def ObtainContents(self):
+        # null contents
+        return None
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 85474f2411e..28f04cb84a5 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -320,6 +320,12 @@ class Entry_section(Entry):
             # earlier in the image description. See testCollectionSection().
             if not required and entry_data is None:
                 return None
+
+            if entry_data is None:
+                pad_byte = (entry._pad_byte if isinstance(entry, Entry_section)
+                            else self._pad_byte)
+                entry_data = tools.get_bytes(self._pad_byte, entry.size)
+
             data = self.GetPaddedDataForEntry(entry, entry_data)
             # Handle empty space before the entry
             pad = (entry.offset or 0) - self._skip_at_start - len(section_data)
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index a4f78ae041a..ac9b050fb6c 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6194,6 +6194,11 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         expected = U_BOOT_DATA + tools.get_bytes(0, 12)
         self.assertEqual(expected, data)
 
+    def testNull(self):
+        """Test an image with a null entry"""
+        data = self._DoReadFile('268_null.dts')
+        self.assertEqual(U_BOOT_DATA + b'\xff\xff\xff\xff' + U_BOOT_IMG_DATA, data)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/268_null.dts b/tools/binman/test/268_null.dts
new file mode 100644
index 00000000000..3824ba85090
--- /dev/null
+++ b/tools/binman/test/268_null.dts
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		pad-byte = <0xff>;
+		u-boot {
+		};
+		null {
+			size = <4>;
+		};
+		u-boot-img {
+		};
+	};
+};
-- 
2.39.0.314.g84b9a713c41-goog



More information about the U-Boot mailing list