[RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)

Alex Bennée posted 4 patches 4 years, 1 month ago
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20201009170742.23695-1-alex.bennee@linaro.org
include/hw/arm/virt.h            |   1 -
include/hw/boards.h              |   1 +
include/hw/core/generic-loader.h |   4 +
include/hw/riscv/virt.h          |   1 -
include/sysemu/device_tree.h     |  17 ++
device_tree.c                    |  26 +++
hw/arm/virt.c                    | 322 ++++++++++++++++---------------
hw/core/generic-loader.c         |  42 ++++
hw/riscv/virt.c                  |  18 +-
9 files changed, 268 insertions(+), 164 deletions(-)
[RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Alex Bennée 4 years, 1 month ago
Hi,

This series adds the ability to append FDT data for blobs loaded by
the generic loader. My principle use-case was to be able to directly
boot Xen with a kernel image which avoided having to:

  - get the kernel image into my system image
  - deal with bugs in FDT munging by -bios firmware and/or grub

as such this currently a developer hack that makes *my* life easy and
is thus presented as an RFC for discussion. While I've tested it with
Xen I'm sure the approach would be applicable to other hypervisors or
firmware which expect to consume FDT data pointing at various blobs.

An example command line that launches this is (magic from -kernel):

  ./aarch64-softmmu/qemu-system-aarch64 -cpu cortex-a57 \
    -machine type=virt,virtualization=on -display none \
    -serial mon:stdio \
    -netdev user,id=unet,hostfwd=tcp::2222-:22 \
    -device virtio-net-pci,netdev=unet,id=virt-net,disable-legacy=on \
    -device virtio-scsi-pci,id=virt-scsi,disable-legacy=on \
    -blockdev driver=raw,node-name=hd,discard=unmap,file.driver=host_device,file.filename=/dev/zen-disk/debian-buster-arm64 \
    -device scsi-hd,drive=hd,id=virt-scsi-hd \
    -smp 4 -m 4096 \
    -kernel ~/lsrc/xen.git/xen/xen \
    -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \
    -device loader,addr=0x47000000,file=$HOME/lsrc/linux.git/builds/arm64/arch/arm64/boot/Image,len-fdt-compat=2,fdt-compat[0]='multiboot,,module',fdt-compat[1]='multiboot,,kernel',fdt-bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen"

So a couple of choices I've made doing this:

Promoting *fdt to MachineState

This seemed the simplest approach to making the fdt available to the
global state, especially as MachineState already has a *dtb pointer.
I've converted the ARM virt machine and a RISCV machine but if this is
acceptable I can convert the others.

"Polluting" the generic loader arguments

This was mainly out of convenience as the loader already knows the
size of the blob being loaded. However you could certainly argue it
makes sense to have a more generic "FDT expander" virtual device that
could for example query the QOM model somehow to find the details it
needs.

FDT isn't the only way of passing system information up the boot
chain. We could reasonably want to do a similar thing with ACPI which
is what should be being used on SBSA like devices to communicate with
the hypervisor.

Also relying on ,, in the QemuOpt parser is ugly. It might be worth
having better quoting support if I press on with this.

So what do people think? Something worth developing?


Alex Bennée (4):
  hw/board: promote fdt from ARM VirtMachineState to MachineState
  hw/riscv: migrate fdt field to generic MachineState
  device_tree: add qemu_fdt_setprop_string_array helper
  generic_loader: allow the insertion of /chosen/module stanzas

 include/hw/arm/virt.h            |   1 -
 include/hw/boards.h              |   1 +
 include/hw/core/generic-loader.h |   4 +
 include/hw/riscv/virt.h          |   1 -
 include/sysemu/device_tree.h     |  17 ++
 device_tree.c                    |  26 +++
 hw/arm/virt.c                    | 322 ++++++++++++++++---------------
 hw/core/generic-loader.c         |  42 ++++
 hw/riscv/virt.c                  |  18 +-
 9 files changed, 268 insertions(+), 164 deletions(-)

-- 
2.20.1


Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by no-reply@patchew.org 4 years, 1 month ago
Patchew URL: https://patchew.org/QEMU/20201009170742.23695-1-alex.bennee@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20201009170742.23695-1-alex.bennee@linaro.org
Subject: [RFC PATCH  0/4] generic loader FDT support (for direct Xen boot)

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20201009170742.23695-1-alex.bennee@linaro.org -> patchew/20201009170742.23695-1-alex.bennee@linaro.org
Switched to a new branch 'test'
8fbccbe generic_loader: allow the insertion of /chosen/module stanzas
2baf07a device_tree: add qemu_fdt_setprop_string_array helper
dd6eea3 hw/riscv: migrate fdt field to generic MachineState
dd8ee86 hw/board: promote fdt from ARM VirtMachineState to MachineState

=== OUTPUT BEGIN ===
1/4 Checking commit dd8ee86f5cdf (hw/board: promote fdt from ARM VirtMachineState to MachineState)
2/4 Checking commit dd6eea3e6e34 (hw/riscv: migrate fdt field to generic MachineState)
3/4 Checking commit 2baf07a7abfc (device_tree: add qemu_fdt_setprop_string_array helper)
WARNING: line over 80 characters
#35: FILE: device_tree.c:406:
+int qemu_fdt_setprop_string_array(void *fdt, const char *node_path, const char *prop,

total: 0 errors, 1 warnings, 61 lines checked

Patch 3/4 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
4/4 Checking commit 8fbccbec9628 (generic_loader: allow the insertion of /chosen/module stanzas)
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead
#51: FILE: hw/core/generic-loader.c:73:
+    g_autofree char *node = g_strdup_printf("/chosen/module@%#08lx", s->addr);

WARNING: line over 80 characters
#71: FILE: hw/core/generic-loader.c:93:
+        if (qemu_fdt_setprop_string(fdt, node, "bootargs", s->fdt_bootargs) < 0) {

total: 1 errors, 1 warnings, 76 lines checked

Patch 4/4 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20201009170742.23695-1-alex.bennee@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Alistair Francis 4 years, 1 month ago
On Fri, Oct 9, 2020 at 10:07 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Hi,
>
> This series adds the ability to append FDT data for blobs loaded by
> the generic loader. My principle use-case was to be able to directly
> boot Xen with a kernel image which avoided having to:
>
>   - get the kernel image into my system image
>   - deal with bugs in FDT munging by -bios firmware and/or grub
>
> as such this currently a developer hack that makes *my* life easy and
> is thus presented as an RFC for discussion. While I've tested it with
> Xen I'm sure the approach would be applicable to other hypervisors or
> firmware which expect to consume FDT data pointing at various blobs.

An interesting idea. I think this comes up enough that it's worth
thinking about.

>
> An example command line that launches this is (magic from -kernel):
>
>   ./aarch64-softmmu/qemu-system-aarch64 -cpu cortex-a57 \
>     -machine type=virt,virtualization=on -display none \
>     -serial mon:stdio \
>     -netdev user,id=unet,hostfwd=tcp::2222-:22 \
>     -device virtio-net-pci,netdev=unet,id=virt-net,disable-legacy=on \
>     -device virtio-scsi-pci,id=virt-scsi,disable-legacy=on \
>     -blockdev driver=raw,node-name=hd,discard=unmap,file.driver=host_device,file.filename=/dev/zen-disk/debian-buster-arm64 \
>     -device scsi-hd,drive=hd,id=virt-scsi-hd \
>     -smp 4 -m 4096 \
>     -kernel ~/lsrc/xen.git/xen/xen \
>     -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \
>     -device loader,addr=0x47000000,file=$HOME/lsrc/linux.git/builds/arm64/arch/arm64/boot/Image,len-fdt-compat=2,fdt-compat[0]='multiboot,,module',fdt-compat[1]='multiboot,,kernel',fdt-bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen"

You are loading the kernel `Image` file, but changing the device tree
that was generated by QEMU and is being loaded in memory. As a user
that is really confusing.

>
> So a couple of choices I've made doing this:
>
> Promoting *fdt to MachineState
>
> This seemed the simplest approach to making the fdt available to the
> global state, especially as MachineState already has a *dtb pointer.
> I've converted the ARM virt machine and a RISCV machine but if this is
> acceptable I can convert the others.

This seems fine to me.

>
> "Polluting" the generic loader arguments
>
> This was mainly out of convenience as the loader already knows the
> size of the blob being loaded. However you could certainly argue it
> makes sense to have a more generic "FDT expander" virtual device that
> could for example query the QOM model somehow to find the details it
> needs.

That seems like a better option. Why not have a generic way to modify
the device tree with a specific argument? It could either be -device
loader,file=fdt,... or -fdt ...

Alistair

>
> FDT isn't the only way of passing system information up the boot
> chain. We could reasonably want to do a similar thing with ACPI which
> is what should be being used on SBSA like devices to communicate with
> the hypervisor.
>
> Also relying on ,, in the QemuOpt parser is ugly. It might be worth
> having better quoting support if I press on with this.
>
> So what do people think? Something worth developing?
>
>
> Alex Bennée (4):
>   hw/board: promote fdt from ARM VirtMachineState to MachineState
>   hw/riscv: migrate fdt field to generic MachineState
>   device_tree: add qemu_fdt_setprop_string_array helper
>   generic_loader: allow the insertion of /chosen/module stanzas
>
>  include/hw/arm/virt.h            |   1 -
>  include/hw/boards.h              |   1 +
>  include/hw/core/generic-loader.h |   4 +
>  include/hw/riscv/virt.h          |   1 -
>  include/sysemu/device_tree.h     |  17 ++
>  device_tree.c                    |  26 +++
>  hw/arm/virt.c                    | 322 ++++++++++++++++---------------
>  hw/core/generic-loader.c         |  42 ++++
>  hw/riscv/virt.c                  |  18 +-
>  9 files changed, 268 insertions(+), 164 deletions(-)
>
> --
> 2.20.1
>
>

Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Alex Bennée 4 years, 1 month ago
Alistair Francis <alistair23@gmail.com> writes:

> On Fri, Oct 9, 2020 at 10:07 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>> Hi,
>>
>> This series adds the ability to append FDT data for blobs loaded by
>> the generic loader. My principle use-case was to be able to directly
>> boot Xen with a kernel image which avoided having to:
>>
>>   - get the kernel image into my system image
>>   - deal with bugs in FDT munging by -bios firmware and/or grub
>>
>> as such this currently a developer hack that makes *my* life easy and
>> is thus presented as an RFC for discussion. While I've tested it with
>> Xen I'm sure the approach would be applicable to other hypervisors or
>> firmware which expect to consume FDT data pointing at various blobs.
>
> An interesting idea. I think this comes up enough that it's worth
> thinking about.
>
>>
>> An example command line that launches this is (magic from -kernel):
>>
>>   ./aarch64-softmmu/qemu-system-aarch64 -cpu cortex-a57 \
>>     -machine type=virt,virtualization=on -display none \
>>     -serial mon:stdio \
>>     -netdev user,id=unet,hostfwd=tcp::2222-:22 \
>>     -device virtio-net-pci,netdev=unet,id=virt-net,disable-legacy=on \
>>     -device virtio-scsi-pci,id=virt-scsi,disable-legacy=on \
>>     -blockdev driver=raw,node-name=hd,discard=unmap,file.driver=host_device,file.filename=/dev/zen-disk/debian-buster-arm64 \
>>     -device scsi-hd,drive=hd,id=virt-scsi-hd \
>>     -smp 4 -m 4096 \
>>     -kernel ~/lsrc/xen.git/xen/xen \
>>     -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \
>>     -device loader,addr=0x47000000,file=$HOME/lsrc/linux.git/builds/arm64/arch/arm64/boot/Image,len-fdt-compat=2,fdt-compat[0]='multiboot,,module',fdt-compat[1]='multiboot,,kernel',fdt-bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen"
>
> You are loading the kernel `Image` file, but changing the device tree
> that was generated by QEMU and is being loaded in memory. As a user
> that is really confusing.

Well in this case the "kernel" is Xen which helpfully comes with a
kernel compatible header that the kernel loaded understand. The blob
could be any Dom0 kernel - it just happens to be a Linux kernel in this
case.

>
>>
>> So a couple of choices I've made doing this:
>>
>> Promoting *fdt to MachineState
>>
>> This seemed the simplest approach to making the fdt available to the
>> global state, especially as MachineState already has a *dtb pointer.
>> I've converted the ARM virt machine and a RISCV machine but if this is
>> acceptable I can convert the others.
>
> This seems fine to me.
>
>>
>> "Polluting" the generic loader arguments
>>
>> This was mainly out of convenience as the loader already knows the
>> size of the blob being loaded. However you could certainly argue it
>> makes sense to have a more generic "FDT expander" virtual device that
>> could for example query the QOM model somehow to find the details it
>> needs.
>
> That seems like a better option. Why not have a generic way to modify
> the device tree with a specific argument? It could either be -device
> loader,file=fdt,... or -fdt ...

Well it comes down to how much of a special case this is? Pretty much
all FDT (and ACPI for the matter) is basically down to the board level
models - and not all of them just the funky configurable ones. For other
board models we just expect the user to pass the FDT they got with their
kernel blob.

For modern VirtIO systems the only thing you really need to expose is
the root PCI bus because the rest of the devices are discover-able
there.

So the real question is are there any other -devices that we want to be
able to graft FDT entries on or is the generic loader enough of a
special case that we keep all the logic in there?

>
> Alistair
>
>>
>> FDT isn't the only way of passing system information up the boot
>> chain. We could reasonably want to do a similar thing with ACPI which
>> is what should be being used on SBSA like devices to communicate with
>> the hypervisor.
>>
>> Also relying on ,, in the QemuOpt parser is ugly. It might be worth
>> having better quoting support if I press on with this.
>>
>> So what do people think? Something worth developing?
>>
>>
>> Alex Bennée (4):
>>   hw/board: promote fdt from ARM VirtMachineState to MachineState
>>   hw/riscv: migrate fdt field to generic MachineState
>>   device_tree: add qemu_fdt_setprop_string_array helper
>>   generic_loader: allow the insertion of /chosen/module stanzas
>>
>>  include/hw/arm/virt.h            |   1 -
>>  include/hw/boards.h              |   1 +
>>  include/hw/core/generic-loader.h |   4 +
>>  include/hw/riscv/virt.h          |   1 -
>>  include/sysemu/device_tree.h     |  17 ++
>>  device_tree.c                    |  26 +++
>>  hw/arm/virt.c                    | 322 ++++++++++++++++---------------
>>  hw/core/generic-loader.c         |  42 ++++
>>  hw/riscv/virt.c                  |  18 +-
>>  9 files changed, 268 insertions(+), 164 deletions(-)
>>
>> --
>> 2.20.1
>>
>>


-- 
Alex Bennée

Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Peter Maydell 4 years, 1 month ago
On Mon, 12 Oct 2020 at 17:19, Alex Bennée <alex.bennee@linaro.org> wrote:
> So the real question is are there any other -devices that we want to be
> able to graft FDT entries on or is the generic loader enough of a
> special case that we keep all the logic in there?

To my mind the point of the generic loader is exactly that
it is not a special case. It works exactly the same way
for every board, for every architecture. It shouldn't have
special case "this makes things work for the thing I want
to load on these boards that all have FDT and want a
particular change to it". We already have a loader that
has that kind of "do what I mean" behaviour (--kernel),
and I very much do not want the generic loader device to
go in that direction. Its whole advantage is that it is
not that, but is just a "load the file, nothing else,
no magic" operation.

thanks
-- PMM

Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Alex Bennée 4 years, 1 month ago
Peter Maydell <peter.maydell@linaro.org> writes:

> On Mon, 12 Oct 2020 at 17:19, Alex Bennée <alex.bennee@linaro.org> wrote:
>> So the real question is are there any other -devices that we want to be
>> able to graft FDT entries on or is the generic loader enough of a
>> special case that we keep all the logic in there?
>
> To my mind the point of the generic loader is exactly that
> it is not a special case. It works exactly the same way
> for every board, for every architecture. It shouldn't have
> special case "this makes things work for the thing I want
> to load on these boards that all have FDT and want a
> particular change to it". We already have a loader that
> has that kind of "do what I mean" behaviour (--kernel),
> and I very much do not want the generic loader device to
> go in that direction. Its whole advantage is that it is
> not that, but is just a "load the file, nothing else,
> no magic" operation.

So should we introduce a sub-classed -device guest-loader which behaves
like generic loader except that it is also aware of platform data
issues?

The other option would be to add the logic to each board that supports
dynamic platform data. It would keep the problem bounded but also lead
to a fair amount of duplicated boiler-plate.

>
> thanks
> -- PMM


-- 
Alex Bennée

Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Edgar E. Iglesias 4 years, 1 month ago
On Mon, Oct 12, 2020 at 05:02:57PM +0100, Alex Bennée wrote:
> 
> Alistair Francis <alistair23@gmail.com> writes:
> 
> > On Fri, Oct 9, 2020 at 10:07 AM Alex Bennée <alex.bennee@linaro.org> wrote:
> >>
> >> Hi,
> >>
> >> This series adds the ability to append FDT data for blobs loaded by
> >> the generic loader. My principle use-case was to be able to directly
> >> boot Xen with a kernel image which avoided having to:
> >>
> >>   - get the kernel image into my system image
> >>   - deal with bugs in FDT munging by -bios firmware and/or grub
> >>
> >> as such this currently a developer hack that makes *my* life easy and
> >> is thus presented as an RFC for discussion. While I've tested it with
> >> Xen I'm sure the approach would be applicable to other hypervisors or
> >> firmware which expect to consume FDT data pointing at various blobs.
> >
> > An interesting idea. I think this comes up enough that it's worth
> > thinking about.
> >
> >>
> >> An example command line that launches this is (magic from -kernel):
> >>
> >>   ./aarch64-softmmu/qemu-system-aarch64 -cpu cortex-a57 \
> >>     -machine type=virt,virtualization=on -display none \
> >>     -serial mon:stdio \
> >>     -netdev user,id=unet,hostfwd=tcp::2222-:22 \
> >>     -device virtio-net-pci,netdev=unet,id=virt-net,disable-legacy=on \
> >>     -device virtio-scsi-pci,id=virt-scsi,disable-legacy=on \
> >>     -blockdev driver=raw,node-name=hd,discard=unmap,file.driver=host_device,file.filename=/dev/zen-disk/debian-buster-arm64 \
> >>     -device scsi-hd,drive=hd,id=virt-scsi-hd \
> >>     -smp 4 -m 4096 \
> >>     -kernel ~/lsrc/xen.git/xen/xen \
> >>     -append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \
> >>     -device loader,addr=0x47000000,file=$HOME/lsrc/linux.git/builds/arm64/arch/arm64/boot/Image,len-fdt-compat=2,fdt-compat[0]='multiboot,,module',fdt-compat[1]='multiboot,,kernel',fdt-bootargs="root=/dev/sda2 ro console=hvc0 earlyprintk=xen"
> >
> > You are loading the kernel `Image` file, but changing the device tree
> > that was generated by QEMU and is being loaded in memory. As a user
> > that is really confusing.
> 
> Well in this case the "kernel" is Xen which helpfully comes with a
> kernel compatible header that the kernel loaded understand. The blob
> could be any Dom0 kernel - it just happens to be a Linux kernel in this
> case.
> 
> >
> >>
> >> So a couple of choices I've made doing this:
> >>
> >> Promoting *fdt to MachineState
> >>
> >> This seemed the simplest approach to making the fdt available to the
> >> global state, especially as MachineState already has a *dtb pointer.
> >> I've converted the ARM virt machine and a RISCV machine but if this is
> >> acceptable I can convert the others.
> >
> > This seems fine to me.
> >
> >>
> >> "Polluting" the generic loader arguments
> >>
> >> This was mainly out of convenience as the loader already knows the
> >> size of the blob being loaded. However you could certainly argue it
> >> makes sense to have a more generic "FDT expander" virtual device that
> >> could for example query the QOM model somehow to find the details it
> >> needs.
> >
> > That seems like a better option. Why not have a generic way to modify
> > the device tree with a specific argument? It could either be -device
> > loader,file=fdt,... or -fdt ...
> 
> Well it comes down to how much of a special case this is? Pretty much
> all FDT (and ACPI for the matter) is basically down to the board level
> models - and not all of them just the funky configurable ones. For other
> board models we just expect the user to pass the FDT they got with their
> kernel blob.
> 
> For modern VirtIO systems the only thing you really need to expose is
> the root PCI bus because the rest of the devices are discover-able
> there.
> 
> So the real question is are there any other -devices that we want to be
> able to graft FDT entries on or is the generic loader enough of a
> special case that we keep all the logic in there?
>

Hi,

Another option is to allow the user to pass along a DTB overlay with the
generic loader option (or with a separate option as Alistair suggested).
With overlways we wouldn't need all the command-line options to enable
construction of dtb fragments, it would be more or less transparent to
QEMU. There may be limitations with the overlay flows that I'm not aware
of though...

Cheers,
Edgar


Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Alex Bennée 4 years, 1 month ago
Edgar E. Iglesias <edgar.iglesias@gmail.com> writes:

> On Mon, Oct 12, 2020 at 05:02:57PM +0100, Alex Bennée wrote:
>> 
>> Alistair Francis <alistair23@gmail.com> writes:
>> 
>> > On Fri, Oct 9, 2020 at 10:07 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>> >>
>> >> Hi,
>> >>
>> >> This series adds the ability to append FDT data for blobs loaded by
>> >> the generic loader. My principle use-case was to be able to directly
>> >> boot Xen with a kernel image which avoided having to:
>> >>
>> >>   - get the kernel image into my system image
>> >>   - deal with bugs in FDT munging by -bios firmware and/or grub
<snip>
>> >> "Polluting" the generic loader arguments
>> >>
>> >> This was mainly out of convenience as the loader already knows the
>> >> size of the blob being loaded. However you could certainly argue it
>> >> makes sense to have a more generic "FDT expander" virtual device that
>> >> could for example query the QOM model somehow to find the details it
>> >> needs.
>> >
>> > That seems like a better option. Why not have a generic way to modify
>> > the device tree with a specific argument? It could either be -device
>> > loader,file=fdt,... or -fdt ...
>> 
>> Well it comes down to how much of a special case this is? Pretty much
>> all FDT (and ACPI for the matter) is basically down to the board level
>> models - and not all of them just the funky configurable ones. For other
>> board models we just expect the user to pass the FDT they got with their
>> kernel blob.
>> 
>> For modern VirtIO systems the only thing you really need to expose is
>> the root PCI bus because the rest of the devices are discover-able
>> there.
>> 
>> So the real question is are there any other -devices that we want to be
>> able to graft FDT entries on or is the generic loader enough of a
>> special case that we keep all the logic in there?
>>
>
> Hi,
>
> Another option is to allow the user to pass along a DTB overlay with the
> generic loader option (or with a separate option as Alistair suggested).
> With overlways we wouldn't need all the command-line options to enable
> construction of dtb fragments, it would be more or less transparent to
> QEMU. There may be limitations with the overlay flows that I'm not aware
> of though...

So the problem of adding DTB overlays is it's not that much easier than
the current options of using -machine dumpdtb and then hand hacking the
magic values and rebuilding, for example:

  https://medium.com/@denisobrezkov/xen-on-arm-and-qemu-1654f24dea75

Unless we come up with some sort of template support that allows QEMU to
insert numbers like address and size while processing the template. But
that seems a little too over engineered and likely introduces complexity
into the system.

Given the generic-loader is so simple I'm leaning towards another
approach of just c&p'ing generic-loader into a new "magic" device (maybe
guest-loader) and stripping out the bits we don't need (data, data-len,
be etc) and making the options more tuned what we are trying to achieve.
For example:

  -device guest-loader,kernel=path/to/Image,args="command line",addr=0x47000000,hyp=xen
  -device guest-loader,initrd=path/to/initrd,addr=0x42000000,hyp=xen

And then we can embed the smarts in the loader to set either DTB or ACPI
entries as required and if we need additional magic to support different
hypervisors (which hopefully you don't but...) you can modulate the
hyp=FOO variable.

There may be an argument for having a -hypervisor as a sugar alias for
-kernel (which maps to machine.kernel) but currently I see no practical
differences you need to launch it except maybe forcing the
virtualisation property to true if it exists - but that seems a little
ARM focused.

-- 
Alex Bennée

Re: [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot)
Posted by Alistair Francis 4 years, 1 month ago
On Tue, Oct 13, 2020 at 3:11 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>
>
> Edgar E. Iglesias <edgar.iglesias@gmail.com> writes:
>
> > On Mon, Oct 12, 2020 at 05:02:57PM +0100, Alex Bennée wrote:
> >>
> >> Alistair Francis <alistair23@gmail.com> writes:
> >>
> >> > On Fri, Oct 9, 2020 at 10:07 AM Alex Bennée <alex.bennee@linaro.org> wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> This series adds the ability to append FDT data for blobs loaded by
> >> >> the generic loader. My principle use-case was to be able to directly
> >> >> boot Xen with a kernel image which avoided having to:
> >> >>
> >> >>   - get the kernel image into my system image
> >> >>   - deal with bugs in FDT munging by -bios firmware and/or grub
> <snip>
> >> >> "Polluting" the generic loader arguments
> >> >>
> >> >> This was mainly out of convenience as the loader already knows the
> >> >> size of the blob being loaded. However you could certainly argue it
> >> >> makes sense to have a more generic "FDT expander" virtual device that
> >> >> could for example query the QOM model somehow to find the details it
> >> >> needs.
> >> >
> >> > That seems like a better option. Why not have a generic way to modify
> >> > the device tree with a specific argument? It could either be -device
> >> > loader,file=fdt,... or -fdt ...
> >>
> >> Well it comes down to how much of a special case this is? Pretty much
> >> all FDT (and ACPI for the matter) is basically down to the board level
> >> models - and not all of them just the funky configurable ones. For other
> >> board models we just expect the user to pass the FDT they got with their
> >> kernel blob.
> >>
> >> For modern VirtIO systems the only thing you really need to expose is
> >> the root PCI bus because the rest of the devices are discover-able
> >> there.
> >>
> >> So the real question is are there any other -devices that we want to be
> >> able to graft FDT entries on or is the generic loader enough of a
> >> special case that we keep all the logic in there?
> >>
> >
> > Hi,
> >
> > Another option is to allow the user to pass along a DTB overlay with the
> > generic loader option (or with a separate option as Alistair suggested).
> > With overlways we wouldn't need all the command-line options to enable
> > construction of dtb fragments, it would be more or less transparent to
> > QEMU. There may be limitations with the overlay flows that I'm not aware
> > of though...
>
> So the problem of adding DTB overlays is it's not that much easier than
> the current options of using -machine dumpdtb and then hand hacking the
> magic values and rebuilding, for example:

I agree with this. If a user is changing a DTB from a command line
they probably only want small changes and are unlikely to need the
full power of an overlay.

>
>   https://medium.com/@denisobrezkov/xen-on-arm-and-qemu-1654f24dea75
>
> Unless we come up with some sort of template support that allows QEMU to
> insert numbers like address and size while processing the template. But
> that seems a little too over engineered and likely introduces complexity
> into the system.

This though sounds interesting :)

>
> Given the generic-loader is so simple I'm leaning towards another
> approach of just c&p'ing generic-loader into a new "magic" device (maybe
> guest-loader) and stripping out the bits we don't need (data, data-len,
> be etc) and making the options more tuned what we are trying to achieve.
> For example:
>
>   -device guest-loader,kernel=path/to/Image,args="command line",addr=0x47000000,hyp=xen
>   -device guest-loader,initrd=path/to/initrd,addr=0x42000000,hyp=xen

At first I'm not thrilled of adding a new loader. In saying that,
there are lots of times where -kernel and friends doesn't do what I
want it to do and I have to fall back to the generic loader and code
changes to QEMU so maybe this is a good idea for image loading.

I'm guessing this would be the same for every platform which would be
a nice change from -kernel.

Alistair

>
> And then we can embed the smarts in the loader to set either DTB or ACPI
> entries as required and if we need additional magic to support different
> hypervisors (which hopefully you don't but...) you can modulate the
> hyp=FOO variable.
>
> There may be an argument for having a -hypervisor as a sugar alias for
> -kernel (which maps to machine.kernel) but currently I see no practical
> differences you need to launch it except maybe forcing the
> virtualisation property to true if it exists - but that seems a little
> ARM focused.
>
> --
> Alex Bennée