qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Question about loading bare metal firmware
@ 2022-09-13  9:38 Clément Chigot
  2022-09-13 12:37 ` Peter Maydell
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Clément Chigot @ 2022-09-13  9:38 UTC (permalink / raw)
  To: qemu-devel@nongnu.org Developers, Bin Meng

Hi all,

I'm wondering if there is an official way to load bare metal software
within qemu emulations.
I've seen a lot of people (including us) using -kernel. However, the
doc seems to imply that the generic loader would be a better approach
(cf [1]). I know that the compatibility with older Qemus is one of the
reasons why -kernel is still highly used. I've also seen that the
reset vector can be initialized automatically by -kernel unlike with
the generic loader (this is the case with RiscV AFAICT).
But is there any kind of official recommendation on that topic ?

I'm asking that because a recent change in RiscV Polarfire Soc is
forcing -dtb to be passed along -kernel. But in case of bare board
software, -dtb isn't needed (at least in our use case).
I've a patch that allows "-dtb" to be missing with "-kernel" only if
"-bios none" is provided. But I'm not sure if this is the right way to
say "it's a bare board software".

@Bin Meng you're the one that added this -kernel support in PolarFire
Soc. Thus, is my approach looking good for you or do you have a better
one in mind ?

[1] https://www.qemu.org/docs/master/system/qemu-manpage.html#hxtool-8

Thanks,
Clément


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about loading bare metal firmware
  2022-09-13  9:38 Question about loading bare metal firmware Clément Chigot
@ 2022-09-13 12:37 ` Peter Maydell
  2022-09-13 13:53 ` Bin Meng
  2022-09-13 14:35 ` Alex Bennée
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2022-09-13 12:37 UTC (permalink / raw)
  To: Clément Chigot; +Cc: qemu-devel@nongnu.org Developers, Bin Meng

On Tue, 13 Sept 2022 at 10:44, Clément Chigot <chigot@adacore.com> wrote:
> I'm wondering if there is an official way to load bare metal software
> within qemu emulations.
> I've seen a lot of people (including us) using -kernel. However, the
> doc seems to imply that the generic loader would be a better approach
> (cf [1]). I know that the compatibility with older Qemus is one of the
> reasons why -kernel is still highly used. I've also seen that the
> reset vector can be initialized automatically by -kernel unlike with
> the generic loader (this is the case with RiscV AFAICT).
> But is there any kind of official recommendation on that topic ?

I dunno if it's officially written down, but "-kernel" is the
"do what I mean" option, which is mostly intended to be "I am
a Linux kernel, load me accordingly", plus some odds and ends of
"do something sensible" for other formats.

For bare metal code you are almost always better off using something
else. There are two options:
(1) if the machine type supports -bios or -pflash type options,
you can use those for "load this binary blob into the flash/ROM"
(which is presumably where the CPU will start executing from on
reset). This is generally good for "here is a firmware image"
type use cases.

(2) the "generic loader"
https://www.qemu.org/docs/master/system/generic-loader.html
This will load the specified file (which can be an ELF file)
anywhere you like. It's probably what you want for "random
bare-metal test case code that expects to be loaded into RAM",
for instance.

> I'm asking that because a recent change in RiscV Polarfire Soc is
> forcing -dtb to be passed along -kernel. But in case of bare board
> software, -dtb isn't needed (at least in our use case).
> I've a patch that allows "-dtb" to be missing with "-kernel" only if
> "-bios none" is provided. But I'm not sure if this is the right way to
> say "it's a bare board software".

I would say that you should probably not be using -kernel for this.
On the other hand, most other board models don't insist on the -dtb
being passed in even if you are booting a Linux kernel.

-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about loading bare metal firmware
  2022-09-13  9:38 Question about loading bare metal firmware Clément Chigot
  2022-09-13 12:37 ` Peter Maydell
@ 2022-09-13 13:53 ` Bin Meng
  2022-09-13 14:35 ` Alex Bennée
  2 siblings, 0 replies; 6+ messages in thread
From: Bin Meng @ 2022-09-13 13:53 UTC (permalink / raw)
  To: Clément Chigot; +Cc: qemu-devel@nongnu.org Developers

On Tue, Sep 13, 2022 at 5:39 PM Clément Chigot <chigot@adacore.com> wrote:
>
> Hi all,
>
> I'm wondering if there is an official way to load bare metal software
> within qemu emulations.
> I've seen a lot of people (including us) using -kernel. However, the
> doc seems to imply that the generic loader would be a better approach
> (cf [1]). I know that the compatibility with older Qemus is one of the
> reasons why -kernel is still highly used. I've also seen that the
> reset vector can be initialized automatically by -kernel unlike with
> the generic loader (this is the case with RiscV AFAICT).
> But is there any kind of official recommendation on that topic ?
>
> I'm asking that because a recent change in RiscV Polarfire Soc is
> forcing -dtb to be passed along -kernel. But in case of bare board
> software, -dtb isn't needed (at least in our use case).
> I've a patch that allows "-dtb" to be missing with "-kernel" only if
> "-bios none" is provided. But I'm not sure if this is the right way to
> say "it's a bare board software".
>
> @Bin Meng you're the one that added this -kernel support in PolarFire
> Soc. Thus, is my approach looking good for you or do you have a better
> one in mind ?
>

As Peter said, you probably need to use the generic loader for your
use case. The "-kernel" is mainly for the Linux kernel, or a kernel
with Linux kernel compatible boot protocol. In this case, Linux kernel
won't boot without a proper DTB provided, as QEMU PolarFire machine
does not generate a DTB like other RISC-V machines.

> [1] https://www.qemu.org/docs/master/system/qemu-manpage.html#hxtool-8

Regards,
Bin


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about loading bare metal firmware
  2022-09-13  9:38 Question about loading bare metal firmware Clément Chigot
  2022-09-13 12:37 ` Peter Maydell
  2022-09-13 13:53 ` Bin Meng
@ 2022-09-13 14:35 ` Alex Bennée
  2022-09-13 14:53   ` Clément Chigot
  2 siblings, 1 reply; 6+ messages in thread
From: Alex Bennée @ 2022-09-13 14:35 UTC (permalink / raw)
  To: Clément Chigot; +Cc: Bin Meng, qemu-devel


Clément Chigot <chigot@adacore.com> writes:

> Hi all,
>
> I'm wondering if there is an official way to load bare metal software
> within qemu emulations.
> I've seen a lot of people (including us) using -kernel. However, the
> doc seems to imply that the generic loader would be a better approach
> (cf [1]). I know that the compatibility with older Qemus is one of the
> reasons why -kernel is still highly used. I've also seen that the
> reset vector can be initialized automatically by -kernel unlike with
> the generic loader (this is the case with RiscV AFAICT).
> But is there any kind of official recommendation on that topic ?

The recommendation is in the document you linked. For bare metal use the
generic loader and make sure you put the blob in the right place so the
architectural reset vector will jump to it.

> I'm asking that because a recent change in RiscV Polarfire Soc is
> forcing -dtb to be passed along -kernel. But in case of bare board
> software, -dtb isn't needed (at least in our use case).
> I've a patch that allows "-dtb" to be missing with "-kernel" only if
> "-bios none" is provided. But I'm not sure if this is the right way to
> say "it's a bare board software".
>
> @Bin Meng you're the one that added this -kernel support in PolarFire
> Soc. Thus, is my approach looking good for you or do you have a better
> one in mind ?
>
> [1] https://www.qemu.org/docs/master/system/qemu-manpage.html#hxtool-8
>
> Thanks,
> Clément


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about loading bare metal firmware
  2022-09-13 14:35 ` Alex Bennée
@ 2022-09-13 14:53   ` Clément Chigot
  2022-09-14 11:20     ` Alistair Francis
  0 siblings, 1 reply; 6+ messages in thread
From: Clément Chigot @ 2022-09-13 14:53 UTC (permalink / raw)
  To: Alex Bennée, Bin Meng, Peter Maydell
  Cc: qemu-devel@nongnu.org Developers

> > Hi all,
> >
> > I'm wondering if there is an official way to load bare metal software
> > within qemu emulations.
> > I've seen a lot of people (including us) using -kernel. However, the
> > doc seems to imply that the generic loader would be a better approach
> > (cf [1]). I know that the compatibility with older Qemus is one of the
> > reasons why -kernel is still highly used. I've also seen that the
> > reset vector can be initialized automatically by -kernel unlike with
> > the generic loader (this is the case with RiscV AFAICT).
> > But is there any kind of official recommendation on that topic ?
>
> The recommendation is in the document you linked. For bare metal use the
> generic loader and make sure you put the blob in the right place so the
> architectural reset vector will jump to it.

Alright. I should have missed something when I tried with the generic loader.
Thanks for the inputs and the confirmation that we were doing something wrong !

Thanks,
Clément


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about loading bare metal firmware
  2022-09-13 14:53   ` Clément Chigot
@ 2022-09-14 11:20     ` Alistair Francis
  0 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2022-09-14 11:20 UTC (permalink / raw)
  To: Clément Chigot
  Cc: Alex Bennée, Bin Meng, Peter Maydell,
	qemu-devel@nongnu.org Developers

On Tue, Sep 13, 2022 at 4:57 PM Clément Chigot <chigot@adacore.com> wrote:
>
> > > Hi all,
> > >
> > > I'm wondering if there is an official way to load bare metal software
> > > within qemu emulations.
> > > I've seen a lot of people (including us) using -kernel. However, the
> > > doc seems to imply that the generic loader would be a better approach
> > > (cf [1]). I know that the compatibility with older Qemus is one of the
> > > reasons why -kernel is still highly used. I've also seen that the
> > > reset vector can be initialized automatically by -kernel unlike with
> > > the generic loader (this is the case with RiscV AFAICT).
> > > But is there any kind of official recommendation on that topic ?
> >
> > The recommendation is in the document you linked. For bare metal use the
> > generic loader and make sure you put the blob in the right place so the
> > architectural reset vector will jump to it.
>
> Alright. I should have missed something when I tried with the generic loader.
> Thanks for the inputs and the confirmation that we were doing something wrong !

Just another note that for a few RISC-V machines we load OpenSBI by
default. So if you don't want OpenSBI you should also specify `-bios
none`. You should also be able to just use `-bios <my_elf>` to load
your bare metal application

Alistair

>
> Thanks,
> Clément
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-14 11:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-13  9:38 Question about loading bare metal firmware Clément Chigot
2022-09-13 12:37 ` Peter Maydell
2022-09-13 13:53 ` Bin Meng
2022-09-13 14:35 ` Alex Bennée
2022-09-13 14:53   ` Clément Chigot
2022-09-14 11:20     ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).