hw/arm/boot: allow using a command line specified dtb without a kernel
PATCH 1/1 hw/arm/boot: allow using a command line specified dtb without a kernel
When kernel and device tree are specified in the QEMU commandline, then this device tree may be modified e.g. to add virtio_mmio devices. With a bootloader e.g. on a flash device these extra devices are not available.
With this change, the device tree can be specified at the QEMU commandline. The modified device tree made available to the bootloader with the same mechanism already supported by device trees fully generated by QEMU.
--- hw/arm/boot.c | 4 ++-- vl.c | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-)
hw/arm/boot.c +2 -2
@@ -773,6 +773,8 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)*/ assert (!(info->secure_board_setup &&kvm_enabled ())); + info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); +/* Load the kernel. */ if (!info->kernel_filename || info->firmware_loaded) {
@@ -833,8 +835,6 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) elf_machine =EM_ARM ; } - info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (!info->secondary_cpu_reset_hook) { info->secondary_cpu_reset_hook = default_reset_secondary; }
vl.c +0 -5
@@ -4335,11 +4335,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -if (!linux_boot &&qemu_opt_get (machine_opts,"dtb" )) { -error_report ("-dtb only allowed with -kernel option" ); -exit (1 ); - } -if (semihosting_enabled () && !semihosting_get_argc () && kernel_filename) {/* fall back to the -kernel/-append */ semihosting_arg_fallback (kernel_filename, kernel_cmdline);
Signature · 1 line
2.9.3
Quoted 7 lines · Michael Olbrich
When kernel and device tree are specified in the QEMU commandline, then this device tree may be modified e.g. to add
virtio_mmiodevices. With a bootloader e.g. on a flash device these extra devices are not available.
With this change, the device tree can be specified at the QEMU commandline. The modified device tree made available to the bootloader with the same mechanism already supported by device trees fully generated by QEMU.
Would you mind explaining your usecase in a little more detail (for instance which machine model are you using) ?
Quoted 20 lines
Signed-off-by Michael Olbrich <[email protected]>--- hw/arm/boot.c | 4 ++-- vl.c | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-)hw/arm/boot.c +2
-0@@ -773,6 +773,8 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)*/ assert (!(info->secure_board_setup &&kvm_enabled ())); + info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); +/* Load the kernel. */ if (!info->kernel_filename || info->firmware_loaded) {
hw/arm/boot.c static void arm_load_kernel_notify(Notifier *notifier, void *data) · line 840
Quoted 8 lines
hw/arm/boot.c +0
-2@@ -833,8 +835,6 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) elf_machine =EM_ARM ; } - info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (!info->secondary_cpu_reset_hook) { info->secondary_cpu_reset_hook = default_reset_secondary; }
This change definitely makes sense -- we check info->dtb_filename in have_dtb() so we need to set it before we call that function, not afterwards.
vl.c int main(int argc, char **argv, char **envp) · line 4342
Quoted 13 lines
vl.c +0
-5@@ -4335,11 +4335,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -if (!linux_boot &&qemu_opt_get (machine_opts,"dtb" )) { -error_report ("-dtb only allowed with -kernel option" ); -exit (1 ); - } -
I can see why you want this change, but what worries me a little is that this is changing the behaviour of -dtb for all QEMU target architectures, not just ARM (they no longer get a helpful message on user error). I'm not sure how to address that, though.
thanks
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 7 lines · Michael Olbrich
When kernel and device tree are specified in the QEMU commandline, then this device tree may be modified e.g. to add
virtio_mmiodevices. With a bootloader e.g. on a flash device these extra devices are not available.
With this change, the device tree can be specified at the QEMU commandline. The modified device tree made available to the bootloader with the same mechanism already supported by device trees fully generated by QEMU.Would you mind explaining your usecase in a little more detail (for instance which machine model are you using) ?
I'm using qemu for system integration testing. Including some bootloader / Linux kernel and userspace interaction. I'm currently using vexpress-a9 but I plan to investigate if the new imx6 machine is suitable for my use-case.
In a setup without bootloader I already use a 9p rootfs. It's great for debugging and a lot easier to set up than networking and a NFS server.
With this patch (and some bootloader patches to handle the device tree) I can do the same when a bootloader is involved.
Quoted 41 lines
Quoted 20 lines
Signed-off-by Michael Olbrich <[email protected]>--- hw/arm/boot.c | 4 ++-- vl.c | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-)hw/arm/boot.c +2
-0@@ -773,6 +773,8 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)*/ assert (!(info->secure_board_setup &&kvm_enabled ())); + info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); +/* Load the kernel. */ if (!info->kernel_filename || info->firmware_loaded) {hw/arm/boot.c static void arm_load_kernel_notify(Notifier *notifier, void *data) · line 840
Quoted 8 lines
hw/arm/boot.c +0
-2@@ -833,8 +835,6 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) elf_machine =EM_ARM ; } - info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (!info->secondary_cpu_reset_hook) { info->secondary_cpu_reset_hook = default_reset_secondary; }This change definitely makes sense -- we check
info->dtb_filenameinhave_dtb()so we need to set it before we call that function, not afterwards.Quoted 8 lines
vl.c +0
-0@@ -4335,11 +4335,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); }
Quoted 10 lines
vl.c int main(int argc, char **argv, char **envp) · line 4342
Quoted 5 lines
vl.c +0
-5-if (!linux_boot &&qemu_opt_get (machine_opts,"dtb" )) { -error_report ("-dtb only allowed with -kernel option" ); -exit (1 ); - } -I can see why you want this change, but what worries me a little is that this is changing the behaviour of -dtb for all QEMU target architectures, not just ARM (they no longer get a helpful message on user error). I'm not sure how to address that, though.
Would a 'if !arm' be possible or useful here?
Michael
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 21 lines · Michael Olbrich
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Michael Olbrich
vl.c +0
-0@@ -4335,11 +4335,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); }Quoted 10 lines
vl.c int main(int argc, char **argv, char **envp) · line 4342
Quoted 5 lines
vl.c +0
-5-if (!linux_boot &&qemu_opt_get (machine_opts,"dtb" )) { -error_report ("-dtb only allowed with -kernel option" ); -exit (1 ); - } -I can see why you want this change, but what worries me a little is that this is changing the behaviour of -dtb for all QEMU target architectures, not just ARM (they no longer get a helpful message on user error). I'm not sure how to address that, though.
Quoted 1 line
Would a 'if !arm' be possible or useful here?
It's not quite that simple :-)
I think we have two choices:
(1) just go ahead and remove the error-check, on the basis that:
* for some boards -dtb is useful even without -kernel
* -dtb might be ignored even with -kernel if the specified kernel isn't a DTB-aware kernel, but we ignore that
* -dtb is ignored even with -kernel for target archs/boards which don't support or use DTB, and we don't warn about that
* we don't warn about -kernel being useless for target boards that don't pay any attention to it
(2) add some kind of field to MachineClass indicating whether the machine can handle dtb files with/without a kernel (and perhaps also whether the machine supports -kernel at all), use that to gate the warning messages, and update all the machines to correctly indicate what they can or can't handle. This would let us give warning messages when the user asks for something we're going to ignore (including letting us fix up some of the cases we don't currently deal with as enumerated above), but it would be a fair chunk of effort for a fairly small user-friendliness gain
Thinking about it more, I'm inclining towards the simpler option (1). Paolo, do you have an opinion here ?
thanks
-- PMM
Quoted 46 lines · Peter Maydell
Quoted 21 lines · Michael Olbrich
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Michael Olbrich
vl.c +0
-0@@ -4335,11 +4335,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); }Quoted 10 lines
vl.c int main(int argc, char **argv, char **envp) · line 4342
Quoted 5 lines
vl.c +0
-5-if (!linux_boot &&qemu_opt_get (machine_opts,"dtb" )) { -error_report ("-dtb only allowed with -kernel option" ); -exit (1 ); - } -I can see why you want this change, but what worries me a little is that this is changing the behaviour of -dtb for all QEMU target architectures, not just ARM (they no longer get a helpful message on user error). I'm not sure how to address that, though.
Quoted 1 line
Would a 'if !arm' be possible or useful here?
It's not quite that simple :-)
I think we have two choices:
(1) just go ahead and remove the error-check, on the basis that:
* for some boards -dtb is useful even without -kernel
* -dtb might be ignored even with -kernel if the specified kernel isn't a DTB-aware kernel, but we ignore that
* -dtb is ignored even with -kernel for target archs/boards which don't support or use DTB, and we don't warn about that
* we don't warn about -kernel being useless for target boards that don't pay any attention to it
(2) add some kind of field to MachineClass indicating whether the machine can handle dtb files with/without a kernel (and perhaps also whether the machine supports -kernel at all), use that to gate the warning messages, and update all the machines to correctly indicate what they can or can't handle. This would let us give warning messages when the user asks for something we're going to ignore (including letting us fix up some of the cases we don't currently deal with as enumerated above), but it would be a fair chunk of effort for a fairly small user-friendliness gain
Quoted 2 lines
Thinking about it more, I'm inclining towards the simpler option (1). Paolo, do you have an opinion here ?
The error check doesn't seem worth the effort. It's a convenience message to notify users that their configuration is broken but we can't detect all the cases where it's broken. It doesn't seem like a good business to be in :).
Stefan
Quoted 21 lines · Stefan Hajnoczi
Quoted 20 lines · Peter Maydell
I think we have two choices:
(1) just go ahead and remove the error-check, on the basis that:
* for some boards -dtb is useful even without -kernel
* -dtb might be ignored even with -kernel if the specified kernel isn't a DTB-aware kernel, but we ignore that
* -dtb is ignored even with -kernel for target archs/boards which don't support or use DTB, and we don't warn about that
* we don't warn about -kernel being useless for target boards that don't pay any attention to it
(2) add some kind of field to MachineClass indicating whether the machine can handle dtb files with/without a kernel (and perhaps also whether the machine supports -kernel at all), use that to gate the warning messages, and update all the machines to correctly indicate what they can or can't handle. This would let us give warning messages when the user asks for something we're going to ignore (including letting us fix up some of the cases we don't currently deal with as enumerated above), but it would be a fair chunk of effort for a fairly small user-friendliness gain
Quoted 7 lines
Quoted 2 lines
Thinking about it more, I'm inclining towards the simpler option (1). Paolo, do you have an opinion here ?
The error check doesn't seem worth the effort. It's a convenience message to notify users that their configuration is broken but we can't detect all the cases where it's broken. It doesn't seem like a good business to be in :).
I agree, so let's apply this patch as-is; added to target-arm.next.
thanks
-- PMM