diff mbox series

[v2,2/3] binman: Respect pad-before property of section subentries

Message ID 20200831095820.38130-3-alpernebiyasak@gmail.com
State Accepted
Commit 3fdeb14d951b28fa18494b4c3f819ad33b5fcc09
Delegated to: Simon Glass
Headers show
Series binman: Make FIT image subentries respect offset, alignment and padding | expand

Commit Message

Alper Nebi Yasak Aug. 31, 2020, 9:58 a.m. UTC
Other relevant properties (pad-after, offset, size, align, align-size,
align-end) already work since Pack() sets correct ranges for subentries'
data (.offset, .size variables), but some padding here is necessary to
align the data within this range to match the pad-before property.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---

Changes in v2:
- Move section padding test to the end of file
- Renumber test to accommodate for the first patch's new test

 tools/binman/etype/section.py             |  2 +-
 tools/binman/ftest.py                     |  8 +++++++
 tools/binman/test/166_pad_in_sections.dts | 26 +++++++++++++++++++++++
 3 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/test/166_pad_in_sections.dts

Comments

Simon Glass Aug. 31, 2020, 1:41 p.m. UTC | #1
On Mon, 31 Aug 2020 at 03:59, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>
> Other relevant properties (pad-after, offset, size, align, align-size,
> align-end) already work since Pack() sets correct ranges for subentries'
> data (.offset, .size variables), but some padding here is necessary to
> align the data within this range to match the pad-before property.
>
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---
>
> Changes in v2:
> - Move section padding test to the end of file
> - Renumber test to accommodate for the first patch's new test
>
>  tools/binman/etype/section.py             |  2 +-
>  tools/binman/ftest.py                     |  8 +++++++
>  tools/binman/test/166_pad_in_sections.dts | 26 +++++++++++++++++++++++
>  3 files changed, 35 insertions(+), 1 deletion(-)
>  create mode 100644 tools/binman/test/166_pad_in_sections.dts

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Sept. 1, 2020, 3:17 p.m. UTC | #2
On Mon, 31 Aug 2020 at 03:59, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>
> Other relevant properties (pad-after, offset, size, align, align-size,
> align-end) already work since Pack() sets correct ranges for subentries'
> data (.offset, .size variables), but some padding here is necessary to
> align the data within this range to match the pad-before property.
>
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---
>
> Changes in v2:
> - Move section padding test to the end of file
> - Renumber test to accommodate for the first patch's new test
>
>  tools/binman/etype/section.py             |  2 +-
>  tools/binman/ftest.py                     |  8 +++++++
>  tools/binman/test/166_pad_in_sections.dts | 26 +++++++++++++++++++++++
>  3 files changed, 35 insertions(+), 1 deletion(-)
>  create mode 100644 tools/binman/test/166_pad_in_sections.dts

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index c5166a5b57..72600b1ef3 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -152,7 +152,7 @@  class Entry_section(Entry):
         for entry in self._entries.values():
             data = entry.GetData()
             base = self.pad_before + (entry.offset or 0) - self._skip_at_start
-            pad = base - len(section_data)
+            pad = base - len(section_data) + (entry.pad_before or 0)
             if pad > 0:
                 section_data += tools.GetBytes(self._pad_byte, pad)
             section_data += data
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index ab88ee96ab..53da709d51 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -3483,5 +3483,13 @@  class TestFunctional(unittest.TestCase):
         expected = (U_BOOT_DATA + U_BOOT_DATA)
         self.assertEqual(expected, data)
 
+    def testPadInSections(self):
+        """Test pad-before, pad-after for entries in sections"""
+        data = self._DoReadFile('166_pad_in_sections.dts')
+        expected = (U_BOOT_DATA + tools.GetBytes(ord('!'), 12) +
+                    U_BOOT_DATA + tools.GetBytes(ord('!'), 6) +
+                    U_BOOT_DATA)
+        self.assertEqual(expected, data)
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/166_pad_in_sections.dts b/tools/binman/test/166_pad_in_sections.dts
new file mode 100644
index 0000000000..f2b327ff9f
--- /dev/null
+++ b/tools/binman/test/166_pad_in_sections.dts
@@ -0,0 +1,26 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		pad-byte = <0x26>;
+		section {
+			pad-byte = <0x21>;
+
+			before {
+				type = "u-boot";
+			};
+			u-boot {
+				pad-before = <12>;
+				pad-after = <6>;
+			};
+			after {
+				type = "u-boot";
+			};
+		};
+	};
+};