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

Simon Glass sjg at chromium.org
Tue Nov 7 15:30:33 CET 2023


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.

>
> > 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.

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, with kernel_noload. But as you say, having env vars
affect bootm (and boot ) is not ideal.

Another thing we need to clarify is what kernel_noload means. 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.

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

Regards,
Simon


More information about the U-Boot mailing list