[PATCH v3 03/10] binman: section: add AlignUp+PadToAlignment helpers

Sam Day via B4 Relay devnull+me.samcday.com at kernel.org
Wed Jun 10 03:27:41 CEST 2026


From: Sam Day <me at samcday.com>

In the following commits we will be introducing new etypes derived from
Entry_section which need to align values and pad data. To avoid
duplication we introduce the shared helpers here.
---
 tools/binman/etype/section.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 8530b7ee17f..a8eca3eaf5f 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -1040,3 +1040,12 @@ class Entry_section(Entry):
             for entry in entries.values():
                 return entry.read_elf_segments()
         return None
+
+    def AlignUp(self, value, align):
+        """Return value aligned to given power of 2"""
+        return (value + align - 1) & ~(align - 1)
+
+
+    def PadToAlignment(self, data, align):
+        """Null-pads given data to given power of 2"""
+        return data + b'\0' * (self.AlignUp(len(data), align) - len(data))

-- 
2.54.0




More information about the U-Boot mailing list