All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: u-boot@lists.denx.de
Subject: [PATCH V2] mkimage: fit: Do not tail-pad fitImage with external data
Date: Thu, 7 May 2020 15:46:15 -0500	[thread overview]
Message-ID: <4c10945e-8cc2-bd0b-8501-4c8c0c9faf87@sholland.org> (raw)
In-Reply-To: <20200506170248.GQ12564@bill-the-cat>

On 5/6/20 12:02 PM, trini at konsulko.com (Tom Rini) wrote:
>>>>> I'm not sure that it is.  Can we easily/safely memmove the data to be
>>>>> aligned?  Is that really a better option in this case than ensuring
>>>>> alignment within the file?
>>>>
>>>> Can't we use the new mkimage -B option to enforce the alignment IFF and
>>>> only IFF it is required ? 
>>>
>>> Perhaps.  But..
>>>
>>>> Then we can enforce it separately for 32bit
>>>> and 64bit platforms to 4 and 8 bytes respectively even.
>>>
>>> It's 8 bytes for both.  It's possible that Linux doesn't hard fail if
>>> you only do 4 byte alignment but the documented requirement is 8, for
>>> arm32.
>>
>> With Linux you usually need to move the kernel anyway, no ? It's 2 MiB
>> for arm64 for example.
> 
> For arm64 you have to move it to where text_offset says it needs to be.
> For arm32 the common (always, practically?) case is you're firing off
> the zImage which does what's needed.  But..
> 
>> And what you usually parse in-place would be the DT then.
> 
> Yes, the practical case is that it's a DT and that needs 8 byte
> alignment.  And we should just get back to aligning that correctly.
> Going back to the v1 thread, it turns out the answer to "why do we even
> have this padding?" is "we need the DT to be aligned".

This change broke SPL booting for me on MACH_SUN50I as well. One thing that I
haven't seen brought up yet is that SPL FIT code assumes exactly a 4-byte
alignment of external data after the FIT. In spl_load_simple_fit():

 /*
  * For FIT with external data, figure out where the external images
  * start. This is the base for the data-offset properties in each
  * image.
  */
 size = fdt_totalsize(fit);
 size = (size + 3) & ~3;
 size = board_spl_fit_size_align(size);
 base_offset = (size + 3) & ~3;

And then later on in spl_load_fit_image():

 if (!fit_image_get_data_position(fit, node, &offset)) {
         external_data = true;
 } else if (!fit_image_get_data_offset(fit, node, &offset)) {
         offset += base_offset;
         external_data = true;
 }

In my case, after this change, the FIT binary was 0x453 bytes long. But SPL
rounded it up to 0x454, so the external data offsets were off by one, and the
first byte of every loadable was cut off in RAM:

 Trying to boot from MMC1
 fit read sector 50, sectors=3, dst=49fff980, count=3, size=0x454
 firmware: 'uboot'
 External data: dst=4a000000, offset=454, size=81208
 src = 4a000054, dest = 4a000000
 4a000000: 00 00 ea 35 00 00 14 00 00 00 00 00 00 00 00 00

If I remove both "(size + 3) & ~3" lines, I can boot successfully:

 Trying to boot from MMC1

 fit read sector 50, sectors=3, dst=49fff980, count=3, size=0x453
 firmware: 'uboot'

 External data: dst=4a000000, offset=453, size=81208
 src = 4a000053, dest = 4a000000

 4a000000: 1f 00 00 ea 35 00 00 14 00 00 00 00 00 00 00 00

In other words, it's not just FDTs that are affected by this change, but _all_
external data loaded from SPL.

So if you change the alignment to anything but 4 (be it 1 or 8 or something
else), you must also update the assumptions made by SPL.

Regards,
Samuel

  parent reply	other threads:[~2020-05-07 20:46 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01 15:40 [PATCH V2] mkimage: fit: Do not tail-pad fitImage with external data Marek Vasut
2020-05-03  2:26 ` Simon Glass
2020-05-04 11:27 ` Tom Rini
2020-05-05 13:22   ` Alex Kiernan
2020-05-05 13:28     ` Marek Vasut
2020-05-05 16:37       ` Alex Kiernan
2020-05-05 16:39         ` Marek Vasut
2020-05-05 17:50           ` Tom Rini
2020-05-05 17:53             ` Marek Vasut
2020-05-05 17:55               ` Tom Rini
2020-05-05 17:59                 ` Marek Vasut
2020-05-05 18:06                   ` Tom Rini
2020-05-05 18:18                     ` Marek Vasut
2020-05-05 18:41             ` Simon Glass
2020-05-05 21:17               ` Michael Walle
2020-05-06 10:15                 ` Michael Walle
2020-05-06 12:30                 ` Alex Kiernan
2020-05-06 13:48                 ` Tom Rini
2020-05-06 14:17                   ` Marek Vasut
2020-05-06 14:27                     ` Tom Rini
2020-05-06 14:33                       ` Marek Vasut
2020-05-06 14:37                         ` Tom Rini
2020-05-06 14:41                           ` Marek Vasut
2020-05-06 15:43                             ` Alex Kiernan
2020-05-06 15:52                               ` Marek Vasut
2020-05-06 16:04                                 ` Tom Rini
2020-05-06 16:17                                   ` Marek Vasut
2020-05-06 16:33                                     ` Tom Rini
2020-05-06 16:35                                       ` Marek Vasut
2020-05-06 17:02                                         ` Tom Rini
2020-05-06 18:11                                           ` Marek Vasut
2020-05-07 20:46                                           ` Samuel Holland [this message]
2020-05-08  1:37                                             ` Marek Vasut
2020-05-08 18:47                                               ` Tom Rini
2020-05-08 19:00                                                 ` Marek Vasut
2020-05-08 19:21                                                   ` Tom Rini
2020-05-10 19:24                                                     ` Marek Vasut
2020-05-11 19:36                                                       ` Tom Rini
2020-05-26 15:53                                                         ` Marek Vasut
2020-05-06 12:43               ` Alex Kiernan

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=4c10945e-8cc2-bd0b-8501-4c8c0c9faf87@sholland.org \
    --to=samuel@sholland.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.