public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: Simon Glass <sjg@chromium.org>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	Heiko Thiery <heiko.thiery@gmail.com>,
	Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH 7/7] binman: Refuse to replace sections for now
Date: Sat, 23 Apr 2022 18:46:57 +0300	[thread overview]
Message-ID: <150d615d-16ab-1998-701c-caa430a18c79@gmail.com> (raw)
In-Reply-To: <CAPnjgZ0ExqbAtuPk7zqxNqz8x_9OX9VKv+Hz5etKJ1ooWz3neQ@mail.gmail.com>

On 20/04/2022 00:54, Simon Glass wrote:
> On Sun, 27 Mar 2022 at 09:32, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>>
>> Binman interfaces allow attempts to replace any entry in the image with
>> arbitrary data. When trying to replace sections, the changes in the
>> section entry's data are not propagated to its child entries. This,
>> combined with how sections rebuild their contents from its children,
>> eventually causes the replaced contents to be silently overwritten by
>> rebuilt contents equivalent to the original data.
>>
>> Add a simple test for replacing a section that is currently failing due
>> to this behaviour, and mark it as an expected failure. Also, raise an
>> error when replacing a section instead of silently pretending it was
>> replaced.
>>
>> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
>> ---
>>
>>  tools/binman/etype/section.py                 |  3 +++
>>  tools/binman/ftest.py                         |  9 ++++++++
>>  .../test/234_replace_section_simple.dts       | 23 +++++++++++++++++++
>>  3 files changed, 35 insertions(+)
>>  create mode 100644 tools/binman/test/234_replace_section_simple.dts
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> Is it not better to assertRaises() and check that the error message is
> as expected?

IMO, that would imply the tested 'binman replace' call should raise an
error instead of replacing the data. The test should work as-is, and
when section replacement is fixed we can just remove the expectedFailure
line to be strict about it.

> 
>>
>> diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
>> index ccac658c1831..bd67238b9199 100644
>> --- a/tools/binman/etype/section.py
>> +++ b/tools/binman/etype/section.py
>> @@ -788,6 +788,9 @@ def ReadChildData(self, child, decomp=True, alt_format=None):
>>                  data = new_data
>>          return data
>>
>> +    def WriteData(self, data, decomp=True):
>> +        self.Raise("Replacing sections is not implemented yet")
>> +
>>      def WriteChildData(self, child):
>>          return True
>>
>> diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
>> index 43bec4a88841..058651cc18a0 100644
>> --- a/tools/binman/ftest.py
>> +++ b/tools/binman/ftest.py
>> @@ -5641,6 +5641,15 @@ def testReplaceFitSubentryLeafSmallerSize(self):
>>          self.assertIsNotNone(path)
>>          self.assertEqual(expected_fdtmap, fdtmap)
>>
>> +    @unittest.expectedFailure
>> +    def testReplaceSectionSimple(self):
>> +        """Test replacing a simple section with arbitrary data"""
>> +        new_data = b'w' * len(COMPRESS_DATA + U_BOOT_DATA)
>> +        data, expected_fdtmap, _ = self._RunReplaceCmd(
>> +            'section', new_data,
>> +            dts='234_replace_section_simple.dts')
>> +        self.assertEqual(new_data, data)
>> +
>>
>>  if __name__ == "__main__":
>>      unittest.main()
>> diff --git a/tools/binman/test/234_replace_section_simple.dts b/tools/binman/test/234_replace_section_simple.dts
>> new file mode 100644
>> index 000000000000..c9d5c3285615
>> --- /dev/null
>> +++ b/tools/binman/test/234_replace_section_simple.dts
>> @@ -0,0 +1,23 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/dts-v1/;
>> +
>> +/ {
>> +       binman {
>> +               allow-repack;
>> +
>> +               u-boot-dtb {
>> +               };
>> +
>> +               section {
>> +                       blob {
>> +                               filename = "compress";
>> +                       };
>> +
>> +                       u-boot {
>> +                       };
>> +               };
>> +
>> +               fdtmap {
>> +               };
>> +       };
>> +};
>> --
>> 2.35.1
>>

      reply	other threads:[~2022-04-23 15:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-27 15:31 [PATCH 0/7] binman: Fix replacing FIT subentries Alper Nebi Yasak
2022-03-27 15:31 ` [PATCH 1/7] binman: Fix unique names having '/.' for images read from files Alper Nebi Yasak
2022-04-19 21:54   ` Simon Glass
2022-03-27 15:31 ` [PATCH 2/7] binman: Collect bintools for images when replacing entries Alper Nebi Yasak
2022-04-19 21:54   ` Simon Glass
2022-03-27 15:31 ` [PATCH 3/7] binman: Don't reset offset/size if image doesn't allow repacking Alper Nebi Yasak
2022-04-19 21:54   ` Simon Glass
2022-03-27 15:31 ` [PATCH 4/7] binman: Remove '/images/' fragment from FIT subentry paths Alper Nebi Yasak
2022-03-27 15:31 ` [PATCH 5/7] binman: Create FIT subentries in the FIT section, not its parent Alper Nebi Yasak
2022-04-19 21:54   ` Simon Glass
2022-03-27 15:31 ` [PATCH 6/7] binman: Test replacing non-section entries in FIT subsections Alper Nebi Yasak
2022-04-19 21:54   ` Simon Glass
2022-03-27 15:31 ` [PATCH 7/7] binman: Refuse to replace sections for now Alper Nebi Yasak
2022-04-19 21:54   ` Simon Glass
2022-04-23 15:46     ` Alper Nebi Yasak [this message]

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=150d615d-16ab-1998-701c-caa430a18c79@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=heiko.thiery@gmail.com \
    --cc=jan.kiszka@siemens.com \
    --cc=sjg@chromium.org \
    --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