[PATCH 1/2] binman: Add 'min-size' entry property

Samuel Holland samuel at sholland.org
Sun Jan 22 00:25:16 CET 2023


This property sets the minimum size of an entry, including padding but
not alignment. It can be used to reserve space for growth of an entry,
or to enforce a minimum offset for later entries in the section.

Signed-off-by: Samuel Holland <samuel at sholland.org>
---

 tools/binman/binman.rst              |  8 ++++++++
 tools/binman/entry.py                |  4 ++++
 tools/binman/ftest.py                | 21 +++++++++++++++++----
 tools/binman/test/009_pack_extra.dts |  7 +++++++
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index fa8abdcd86..03a99a19bc 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -615,6 +615,14 @@ size:
     this size. If this is not provided, it will be set to the size of the
     contents.
 
+min-size:
+    Sets the minimum size of the entry. This size includes explicit padding
+    ('pad-before' and 'pad-after'), but not padding added to meet alignment
+    requirements. While this does not affect the contents of the entry within
+    binman itself (the padding is performed only when its parent section is
+    assembled), the end result will be that the entry ends with the padding
+    bytes, so may grow. Defaults to 0.
+
 pad-before:
     Padding before the contents of the entry. Normally this is 0, meaning
     that the contents start at the beginning of the entry. This can be used
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 5d8696e32a..5eacc5fa6c 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -49,6 +49,7 @@ class Entry(object):
         offset: Offset of entry within the section, None if not known yet (in
             which case it will be calculated by Pack())
         size: Entry size in bytes, None if not known
+        min_size: Minimum entry size in bytes
         pre_reset_size: size as it was before ResetForPack(). This allows us to
             keep track of the size we started with and detect size changes
         uncomp_size: Size of uncompressed data in bytes, if the entry is
@@ -114,6 +115,7 @@ class Entry(object):
         self.name = node and (name_prefix + node.name) or 'none'
         self.offset = None
         self.size = None
+        self.min_size = 0
         self.pre_reset_size = None
         self.uncomp_size = None
         self.data = None
@@ -270,6 +272,7 @@ class Entry(object):
             self.Raise("Please use 'extend-size' instead of 'expand-size'")
         self.offset = fdt_util.GetInt(self._node, 'offset')
         self.size = fdt_util.GetInt(self._node, 'size')
+        self.min_size = fdt_util.GetInt(self._node, 'min-size', 0)
         self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset')
         self.orig_size = fdt_util.GetInt(self._node, 'orig-size')
         if self.GetImage().copy_to_orig:
@@ -507,6 +510,7 @@ class Entry(object):
             else:
                 self.offset = tools.align(offset, self.align)
         needed = self.pad_before + self.contents_size + self.pad_after
+        needed = max(needed, self.min_size)
         needed = tools.align(needed, self.align_size)
         size = self.size
         if not size:
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index be0aea49ce..93b332972a 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -883,9 +883,9 @@ class TestFunctional(unittest.TestCase):
         self.assertIn('image', control.images)
         image = control.images['image']
         entries = image.GetEntries()
-        self.assertEqual(5, len(entries))
+        self.assertEqual(6, len(entries))
 
-        # First u-boot with padding before and after
+        # First u-boot with padding before and after (included in minimum size)
         self.assertIn('u-boot', entries)
         entry = entries['u-boot']
         self.assertEqual(0, entry.offset)
@@ -934,8 +934,17 @@ class TestFunctional(unittest.TestCase):
         self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 64 - len(U_BOOT_DATA)),
                          data[pos:pos + entry.size])
 
+        # Sixth u-boot with both minimum size and aligned size
+        self.assertIn('u-boot-min-size', entries)
+        entry = entries['u-boot-min-size']
+        self.assertEqual(128, entry.offset)
+        self.assertEqual(32, entry.size)
+        self.assertEqual(U_BOOT_DATA, entry.data[:len(U_BOOT_DATA)])
+        self.assertEqual(U_BOOT_DATA + tools.get_bytes(0, 32 - len(U_BOOT_DATA)),
+                         data[pos:pos + entry.size])
+
         self.CheckNoGaps(entries)
-        self.assertEqual(128, image.size)
+        self.assertEqual(160, image.size)
 
         dtb = fdt.Fdt(out_dtb_fname)
         dtb.Scan()
@@ -943,7 +952,7 @@ class TestFunctional(unittest.TestCase):
         expected = {
             'image-pos': 0,
             'offset': 0,
-            'size': 128,
+            'size': 160,
 
             'u-boot:image-pos': 0,
             'u-boot:offset': 0,
@@ -964,6 +973,10 @@ class TestFunctional(unittest.TestCase):
             'u-boot-align-both:image-pos': 64,
             'u-boot-align-both:offset': 64,
             'u-boot-align-both:size': 64,
+
+            'u-boot-min-size:image-pos': 128,
+            'u-boot-min-size:offset': 128,
+            'u-boot-min-size:size': 32,
             }
         self.assertEqual(expected, props)
 
diff --git a/tools/binman/test/009_pack_extra.dts b/tools/binman/test/009_pack_extra.dts
index 1b31555771..8d6f4910c9 100644
--- a/tools/binman/test/009_pack_extra.dts
+++ b/tools/binman/test/009_pack_extra.dts
@@ -6,6 +6,7 @@
 
 	binman {
 		u-boot {
+			min-size = <12>;
 			pad-before = <3>;
 			pad-after = <5>;
 		};
@@ -31,5 +32,11 @@
 			align = <64>;
 			align-end = <128>;
 		};
+
+		u-boot-min-size {
+			type = "u-boot";
+			min-size = <24>;
+			align-size = <16>;
+		};
 	};
 };
-- 
2.37.4



More information about the U-Boot mailing list