public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 10/25] binman: Move section-building code into a function
Date: Mon, 19 Oct 2020 23:30:43 +0300	[thread overview]
Message-ID: <9f266db7-b31b-8396-2d5e-3ac99eef767d@gmail.com> (raw)
In-Reply-To: <20201019024138.3804540-10-sjg@chromium.org>

On 19/10/2020 05:41, Simon Glass wrote:
> Create a new _BuildSectionData() to hold the code that is now in
> GetData(), so that it is clearly separated from entry.GetData() base
> function.
> 
> Separate out the 'pad-before' processing to make this easier to
> understand.
> 
> Unfortunately this breaks the testDual test. Rather than squash several
> patches into an un-reviewable glob, disable the test for now.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  tools/binman/etype/section.py | 35 +++++++++++++++++++++++++++++------
>  tools/binman/ftest.py         |  3 ++-
>  2 files changed, 31 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
> index 9222042f5d8..d05adf00274 100644
> --- a/tools/binman/etype/section.py
> +++ b/tools/binman/etype/section.py
> @@ -144,24 +144,47 @@ class Entry_section(Entry):
>      def ObtainContents(self):
>          return self.GetEntryContents()
>  
> -    def GetData(self):
> +    def _BuildSectionData(self):
> +        """Build the contents of a section
> +
> +        This places all entries at the right place, dealing with padding before
> +        and after entries. It does not do padding for the section itself (the
> +        pad-before and pad-after properties in the section items) since that is
> +        handled by the parent section.
> +
> +        Returns:
> +            Contents of the section (bytes)
> +        """
>          section_data = b''
>  
>          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) + (entry.pad_before or 0)
> +            # Handle empty space before the entry
> +            pad = (entry.offset or 0) - self._skip_at_start - len(section_data)
>              if pad > 0:
>                  section_data += tools.GetBytes(self._pad_byte, pad)
> +
> +            # Handle padding before the entry
> +            if entry.pad_before:
> +                section_data += tools.GetBytes(self._pad_byte, entry.pad_before)

Consider this fragment:

    section {
        skip-at-start = <16>;

        blob {
            pad-before = <16>;
            filename = "foo";
        }
    }

Is this invalid as 'blob' isn't offset > skip-at-start? This wouldn't
be padded in the earlier code, but would be padded after this (assuming
it doesn't error out) -- was that a bug or undefined behaviour or
something?

> +
> +            # Add in the actual entry data
>              section_data += data
> +
> +            # Handle padding after the entry
> +            if entry.pad_after:
> +                section_data += tools.GetBytes(self._pad_byte, entry.pad_after)
> +
>          if self.size:
> -            pad = self.size - len(section_data)
> -            if pad > 0:
> -                section_data += tools.GetBytes(self._pad_byte, pad)
> +            section_data += tools.GetBytes(self._pad_byte,
> +                                           self.size - len(section_data))
>          self.Detail('GetData: %d entries, total size %#x' %
>                      (len(self._entries), len(section_data)))
>          return self.CompressData(section_data)
>  
> +    def GetData(self):
> +        return self._BuildSectionData()
> +
>      def GetOffsets(self):
>          """Handle entries that want to set the offset/size of other entries
>  
> diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
> index e265941a392..3c6eb7f6736 100644
> --- a/tools/binman/ftest.py
> +++ b/tools/binman/ftest.py
> @@ -706,7 +706,8 @@ class TestFunctional(unittest.TestCase):
>          """Test a simple binman run with debugging enabled"""
>          self._DoTestFile('005_simple.dts', debug=True)
>  
> -    def testDual(self):
> +    # Disable for now until padding of images is supported
> +    def xtestDual(self):

I think you could use @unittest.skip() here, but perhaps it's not worth
doing a v2 for that (especially since you're re-enabling it later in the
series).

>          """Test that we can handle creating two images
>  
>          This also tests image padding.
> 

  reply	other threads:[~2020-10-19 20:30 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19  2:41 [PATCH 00/25] binman: Support compression of sections Simon Glass
2020-10-19  2:41 ` [PATCH 01/25] binman: Give a sensible error if no command is given Simon Glass
2020-10-19  2:41 ` [PATCH 02/25] binman: Fix return from u-boot-ucode if there is no DT Simon Glass
2020-10-19  2:41 ` [PATCH 03/25] binman: Remove references to 'image' in entry_Section Simon Glass
2020-10-19  2:41 ` [PATCH 04/25] binman: Expand the error message for breaching a section Simon Glass
2020-10-19  2:41 ` [PATCH 05/25] binman: Move CompressData() into Entry base class Simon Glass
2020-10-19  2:41 ` [PATCH 06/25] binman: Use 'files-compress' to set compression for files Simon Glass
2020-10-19 19:01   ` Alper Nebi Yasak
2020-10-19  2:41 ` [PATCH 07/25] binman: Update testPackExtra with more checks Simon Glass
2020-10-19  2:41 ` [PATCH 08/25] binman: Expand docs and test for padding Simon Glass
2020-10-19  2:41 ` [PATCH 09/25] binman: Expand docs and test for alignment Simon Glass
2020-10-19  2:41 ` [PATCH 10/25] binman: Move section-building code into a function Simon Glass
2020-10-19 20:30   ` Alper Nebi Yasak [this message]
2020-10-26 19:22     ` Simon Glass
2020-10-26 23:17       ` Alper Nebi Yasak
2020-11-03 15:11         ` Simon Glass
2020-11-04 21:50           ` Alper Nebi Yasak
2021-01-23 16:15             ` Simon Glass
2020-10-19  2:41 ` [PATCH 11/25] binman: Refactor _BuildSectionData() Simon Glass
2020-10-19  2:41 ` [PATCH 12/25] binman: Move section padding to the parent Simon Glass
2020-10-19  2:41 ` [PATCH 13/25] binman: Make section padding consistent with other entries Simon Glass
2020-10-19  2:41 ` [PATCH 14/25] binman: Store the original data before compression Simon Glass
2020-10-19  2:41 ` [PATCH 15/25] binman: Set section contents in GetData() Simon Glass
2020-10-19  2:41 ` [PATCH 16/25] binman: Avoid reporting image-pos with compression Simon Glass
2020-10-19 21:15   ` Alper Nebi Yasak
2020-10-26 19:22     ` Simon Glass
2020-10-26 22:25       ` Alper Nebi Yasak
2020-10-30 18:15         ` Simon Glass
2020-11-04 19:45           ` Alper Nebi Yasak
2020-10-19  2:41 ` [PATCH 17/25] binman: Drop Entry.CheckOffset() Simon Glass
2020-10-19  2:41 ` [PATCH 18/25] binman: Move sort and expand to the main Pack() function Simon Glass
2020-10-19  2:41 ` [PATCH 19/25] binman: Drop the Entry.CheckSize() method Simon Glass
2020-10-19  2:41 ` [PATCH 20/25] binman: Call CheckSize() from the section's Pack() method Simon Glass
2020-10-19  2:41 ` [PATCH 21/25] binman: Drop CheckEntries() Simon Glass
2020-10-19  2:41 ` [PATCH 22/25] binman: Update CheckEntries() for compressed sections Simon Glass
2020-10-19  2:41 ` [PATCH 23/25] binman: Use the actual contents in CheckSize() Simon Glass
2020-10-19  2:41 ` [PATCH 24/25] binman: Support compression of sections Simon Glass
2020-10-19  2:41 ` [PATCH 25/25] binman: Avoid calculated section data repeatedly Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9f266db7-b31b-8396-2d5e-3ac99eef767d@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox