[PATCH 0/4] bootm: Handle compressed arm64 images with bootm

Tom Rini trini at konsulko.com
Tue Nov 7 20:04:42 CET 2023


On Tue, Nov 07, 2023 at 07:30:33AM -0700, Simon Glass wrote:
> Hi Tom,
> 
> On Tue, 7 Nov 2023 at 06:49, Tom Rini <trini at konsulko.com> wrote:
> >
> > On Tue, Nov 07, 2023 at 06:31:15AM -0700, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Tue, 7 Nov 2023 at 06:04, Tom Rini <trini at konsulko.com> wrote:
> > > >
> > > > On Tue, Nov 07, 2023 at 05:23:05AM -0700, Simon Glass wrote:
> > > > > Hi Rasmus,
> > > > >
> > > > > On Tue, 7 Nov 2023 at 02:56, Rasmus Villemoes
> > > > > <rasmus.villemoes at prevas.dk> wrote:
> > > > > >
> > > > > > On 05/11/2023 21.03, Simon Glass wrote:
> > > > > > > This little series corrects a problem I noticed with arm64 images,
> > > > > > > where the kernel is not recognised:
> > > > > >
> > > > > > The $subject is misleading, bootm works just fine with compressed arm64
> > > > > > images, with the type set to "kernel".
> > > > > >
> > > > > > >         Type:         Kernel Image (no loading done)
> > > > > > >         Compression:  gzip compressed
> > > > > >
> > > > > > Isn't that a non-sensical combination to begin with? Decompressing the
> > > > > > Image.gz kernel image to any location (however you determine that
> > > > > > destination) _is_ loading it.
> > > > >
> > > > > Yes, I agree.
> > > > >
> > > > > >
> > > > > > If you want XIP, obviously the image must be uncompressed in the FIT. I
> > > > > > don't understand what you're trying to do here.
> > > > >
> > > > > Hmmm, I think I have just got confused about all of this, perhaps
> > > > > because ChromeOS uses kernel_noload with compression. Is that an
> > > > > invalid combination?
> > > >
> > > > Yes, that sounds like an invalid combination.
> > > >
> > > > > But then how does loading actually work? We don't want to put the load
> > > > > address in the FIT, since we don't know what it is...we want to use
> > > > > the address provided by the board. Which is kernel_noload...so how
> > > > > should this be implemented?
> > > >
> > > > What do you mean, provided by the board? With kernel_noload we XIP the
> > > > payload, because the board provided (by loading us to) a safe place to
> > > > execute whatevers in there. In the olden days, that would mean (almost
> > > > certainly) the zImage which in turn was already compressed and
> > > > self-relocating. I know technically one could use the raw vmlinux
> > > > instead. With the Linux Kernel and ARCH=arm64 (and a few other arches
> > > > now too), they dropped the self-decompression part and the whole payload
> > > > must be decompressed. We handle this case in "booti" today by having to
> > > > have the board (via environment) say where to decompress to (and how
> > > > much space is available). Then we move it back to where we started from,
> > > > which is likely not necessary.
> > > >
> > > > Looking at
> > > > https://www.kernel.org/doc/html/latest/arch/arm64/booting.html and
> > > > https://www.kernel.org/doc/html/latest/riscv/boot-image-header.html
> > > > stating "we're just like arm64" we can do better than we do today for
> > > > this format of OS image. If aren't compressed, we only need to ensure
> > > > that we are correctly aligned and move (and tell the user) if not. We
> > > > can even put the 2MB check under some legacy kernel CONFIG option (3.17
> > > > is over 9 years old). With respect to automatic decompression, if we
> > > > don't have something telling us where a buffer is and we can't pull from
> > > > the environment, we should tell the user and stop?
> > >
> > > With the booti command, the kern_comp_addr_r and kern_comp_size vars
> > > are used. Perhaps I should update my patch to use those too?
> >
> > As a fallback, perhaps? But what do we do today in a FIT to handle
> > compression = "gzip" to know where to uncompress things to?
> 
> In that case we decompress to the (kernel) load address in the FIT.

And handle overlap, so there's some small window where you just need to
not load the FIT to memory at that address as it's just Not Possible,
yes? I think that's how I recall how it works out.

> > > Do you understand what I am asking about, with bootm? It should be
> > > possible to ignore the load address. In fact, load addresses in FIT
> > > are mostly bad these days, IMO. If this is not kernel_noload, then
> > > what should we use?
> >
> > Well, your use case needs to be valid. I don't think "kernel_noload" is
> > valid with anything other than 'compression = "none"' because that's our
> > just execute things in place option. It's very dangerous to use and I
> > do not recall right now if we fixed the case where it will just let the
> > device tree be badly aligned and break the kernel, or if we say "no
> > load, but still fix THAT alignment". And your use case isn't "ignore the
> > load address" it's "ignore the load address and decompress the
> > payload(s)".  That needs _something_ to be known somehow. And I'm asking
> > how we do that today even, before saying we can or can't support
> > "kernel_noload" along with a compression of the payload.
> 
> OK I see.
> 
> >
> > > "provided by the board" means that the board knows the memory map, not
> > > the FIT, so only the board can provide the addresses to use for
> > > loading the kernel.
> >
> > To be clearer, where does the board document that knowledge and provide
> > it to be used? I'm not a super fan of environment variables especially
> > since we aren't always consistent with '_' or just nothing between
> > "words" of the variable. We have much better documentation these days
> > (once again, thanks everyone) so we can document environment variables
> > used here, and also what CONFIG options are used (as
> > CONFIG_SYS_BOOTM_LEN is part of the equation here and badly named as
> > been said in other threads about issues wrt decomp and overlap).
> 
> I agree about env vars. We have CONFIG_SYS_LOAD_ADDR which seems like
> a better model to me.

Maybe? Looking at the Kconfig entry for SYS_LOAD_ADDR the defaults here
are some really really really long-standing inherited values (why so
many times are we at base of DRAM + 32MB? It was probably good enough to
not be where we are or were running). Sometimes we then use that for
kernel_addr_r, sometimes we don't, and in turn that's because sometimes
we thought harder about how to avoid memory moves, and sometimes didn't.

I'm not immediately sure if this is a good idea to re-use, or a bad idea
to re-use, especially if we're then assuming the rest of the use case is
XIP.

> At the moment we have these, which have carried over from the
> distroboot scripts:
> 
> https://u-boot.readthedocs.io/en/latest/develop/bootstd.html#environment-variables
> 
> So I think we should be using kern_comp_addr_r as the buffer to
> decompress to

In that a lot of effort has been put in to documenting and setting these
variables, yes, re-using that variable as where FIT can be told where to
uncompress to and how much if we have no other value, is good.

> , with kernel_noload. But as you say, having env vars
> affect bootm (and boot ) is not ideal.

I'm still not sure about kernel_noload.

> Another thing we need to clarify is what kernel_noload means.

Yes, we do. I think it's unfortunately on the list of things that
weren't documented well enough in FIT and people assumed what it did and
didn't actually do.

> I have
> taken it to mean 'ignore the load address in the FIT', not 'no loading
> is done', since if compression is enabled, we have to load it to
> somewhere.

OK, but that's not what it means in code. The first step is to document
what cases do, and do not, work in a FIT image today, for a few
different payload options, probably at least
kernel/ramdisk/flatdt/kernel_noload and how it handles compression. I
know at one point there was some confusion about what happens when you
pass a ramdisk.gz and say compression = "gzip" and then what people
expected that to mean instead of what it did, and so what it does right
now.

> IMO 'ignore the load in the FIT' should be the normal situation with bootstd.

Oh no. That's getting things in the wrong order. We need to document
what kernel_noload actually does, today.

And we need to also look harder at our code for handling
Linux-Kernel-arm64-and-riscv-Image files because in the non-compressed
case the Image is probably at an XIP location (2MiB alignment is pretty
likely, we do need to check of course) and the initrd can be wherever,
and we only need to ensure the device tree is 8-byte aligned in memory.
So I think we may have some not-required moving happening at least in
the compressed case.

Then we can see if kernel_noload can sanely support something other than
'compression = "none"'.

Then whatever bootmeth is looking for and finding FIT images will take
whatever valid FIT images are found and boot them. And that may or may
not include having an Image that's compressed. I see that for example
the default v6.6 arm64 kernel has ~1k modules, but the Fedora 38 kernel
has ~4500 and so the distro Image is about the same size as the v6.6
Image.gz. As just a general size example.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20231107/99cc5979/attachment.sig>


More information about the U-Boot mailing list