[PATCH v3 03/10] binman: section: add AlignUp+PadToAlignment helpers
Simon Glass
sjg at chromium.org
Sun Jun 14 18:18:39 CEST 2026
Hi Sam,
On 2026-06-10T01:27:41, Sam Day via B4 Relay
<devnull+me.samcday.com at kernel.org> wrote:
> binman: section: add AlignUp+PadToAlignment helpers
>
> 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
> @@ -1040,3 +1040,12 @@ class Entry_section(Entry):
> + def AlignUp(self, value, align):
> + """Return value aligned to given power of 2"""
> + return (value + align - 1) & ~(align - 1)
We already have tools.align() in u_boot_pylib which does exactly this,
and it is used widely in binman - please drop AlignUp() and have the
qcdt/dtbh/android_boot callers use tools.align() directly.
> diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
> @@ -1040,3 +1040,12 @@ class Entry_section(Entry):
> +
> + 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))
This is a one-liner over tools.align() + tools.get_bytes():
data + tools.get_bytes(0, tools.align(len(data), align) - len(data))
I'd rather not add a method on Entry_section just for this - neither
helper uses self, and the new etypes are the only callers. If you do
want a shared helper, please put it in u_boot_pylib/tools.py as a
plain function (e.g. pad_align()) alongside align() and get_bytes(),
and use snake_case to match the convention there.
Also, stray double blank line between the two new methods.
Regards,
Simon
More information about the U-Boot
mailing list