hw/ppc: Implement -dtb support for PowerNV
PATCH 1/1 hw/ppc: Implement -dtb support for PowerNV
Currently any device tree passed with -dtb option in QEMU, was ignored by the PowerNV code.
Read and pass the passed -dtb to the kernel, thus enabling easier debugging with custom DTBs.
The existing behaviour when -dtb is 'not' passed, is preserved as-is.
But when a '-dtb' is passed, it completely overrides any dtb nodes or changes QEMU might have done, such as '-append' arguments to the kernel (which are mentioned in /chosen/bootargs in the dtb), hence add warning when -dtb is being used
---
Changelog
===========
v1:
+ use 'g_file_get_contents' and add check for -append & -dtb as suggested by Daniel
---
--- hw/ppc/pnv.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
hw/ppc/pnv.c +22 -3
@@ -736,10 +736,21 @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt =pnv_dt_create (machine); +if (machine->dtb) { +warn_report ("with manually passed dtb, some options like '-append'" +" will get ignored and the dtb passed will be used as-is" ); -/* Pack resulting tree */ -_FDT ((fdt_pack (fdt))); +/* read the file 'machine->dtb', and load it into 'fdt' buffer */ +if (!g_file_get_contents (machine->dtb, (gchar **)&fdt,NULL ,NULL )) { +error_report ("Could not load dtb '%s'" , machine->dtb); +exit (1 ); + } + }else { + fdt =pnv_dt_create (machine); + +/* Pack resulting tree */ +_FDT ((fdt_pack (fdt))); + }qemu_fdt_dumpdtb (fdt,fdt_totalsize (fdt));cpu_physical_memory_write (PNV_FDT_ADDR , fdt,fdt_totalsize (fdt));
@@ -952,6 +963,14 @@ static void pnv_init(MachineState *machine)g_free (sz);exit (EXIT_FAILURE ); } + +/* checks for invalid option combinations */ +if (machine->dtb && (strlen (machine->kernel_cmdline) !=0 )) { +error_report ("-append and -dtb cannot be used together, as passed" +" command line is ignored in case of custom dtb" ); +exit (EXIT_FAILURE ); + } +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/*
Signature · 1 line
2.45.2
Hello Aditya,
Quoted 30 lines · Aditya Gupta
Currently any device tree passed with -dtb option in QEMU, was ignored by the PowerNV code.
Read and pass the passed -dtb to the kernel, thus enabling easier debugging with custom DTBs.
The existing behaviour when -dtb is 'not' passed, is preserved as-is.
But when a '-dtb' is passed, it completely overrides any dtb nodes or changes QEMU might have done, such as '-append' arguments to the kernel (which are mentioned in /chosen/bootargs in the dtb), hence add warning when -dtb is being used
Signed-off-by Aditya Gupta <[email protected]>---
Changelog
===========
v1:
+ use 'g_file_get_contents' and add check for -append & -dtb as suggested by Daniel
------ hw/ppc/pnv.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)hw/ppc/pnv.c +0
-0
hw/ppc/pnv.c static void pnv_reset(MachineState *machine, ShutdownCause reason) · line 741
Quoted 7 lines
hw/ppc/pnv.c +3
-1@@ -736,10 +736,21 @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt =pnv_dt_create (machine); +if (machine->dtb) { +warn_report ("with manually passed dtb, some options like '-append'" +" will get ignored and the dtb passed will be used as-is" );
This warning should come after all other checks. See below.
hw/ppc/pnv.c static void pnv_reset(MachineState *machine, ShutdownCause reason) · line 747
Quoted 7 lines
hw/ppc/pnv.c +5
-2-/* Pack resulting tree */ -_FDT ((fdt_pack (fdt))); +/* read the file 'machine->dtb', and load it into 'fdt' buffer */ +if (!g_file_get_contents (machine->dtb, (gchar **)&fdt,NULL ,NULL )) { +error_report ("Could not load dtb '%s'" , machine->dtb); +exit (1 ); + }
We should try to report such errors earlier than in reset.
Can you please introduce a PnvMachineState::dtb attribute and initialize it in pnv_init() after ->initrd_filename.
Thanks,
C.
Quoted 24 lines
hw/ppc/pnv.c +14
-0+ }else { + fdt =pnv_dt_create (machine); + +/* Pack resulting tree */ +_FDT ((fdt_pack (fdt))); + }qemu_fdt_dumpdtb (fdt,fdt_totalsize (fdt));cpu_physical_memory_write (PNV_FDT_ADDR , fdt,fdt_totalsize (fdt));@@ -952,6 +963,14 @@ static void pnv_init(MachineState *machine)g_free (sz);exit (EXIT_FAILURE ); } + +/* checks for invalid option combinations */ +if (machine->dtb && (strlen (machine->kernel_cmdline) !=0 )) { +error_report ("-append and -dtb cannot be used together, as passed" +" command line is ignored in case of custom dtb" ); +exit (EXIT_FAILURE ); + } +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/*
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines
- /* Pack resulting tree */
- _FDT((fdt_pack(fdt)));
+ /* read the file 'machine->dtb', and load it into 'fdt' buffer */ + if (!g_file_get_contents(machine->dtb, (gchar **)&fdt, NULL, NULL)) { +error_report("Could not load dtb '%s'", machine->dtb); + exit(1);
+ }
Quoted 4 lines
We should try to report such errors earlier than in reset.
Can you please introduce a
PnvMachineState::dtbattribute and initialize it inpnv_init()after ->initrd_filename.
PnvMachineState::fdt might be a more appropriate name.
Thanks,
C.
Hello Cedric,
Quoted 30 lines
Quoted 13 lines
<...snip...>
hw/ppc/pnv.c +2
-0@@ -736,10 +736,21 @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt = pnv_dt_create(machine); + if (machine->dtb) { + warn_report("with manually passed dtb, some options likeQuoted 3 lines
'-append'"
+ " will get ignored and the dtb passed will be used as-is");This warning should come after all other checks. See below.
Quoted 9 lines
- /* Pack resulting tree */
- _FDT((fdt_pack(fdt)));
+ /* read the file 'machine->dtb', and load it into 'fdt' buffer */
+ if (!g_file_get_contents(machine->dtb, (gchar **)&fdt, NULL, NULL)) {
+error_report("Could not load dtb '%s'", machine->dtb); + exit(1);
+ }
Quoted 2 lines
We should try to report such errors earlier than in reset.
Thanks, I will remember this from next time.
Quoted 3 lines
Can you please introduce a
PnvMachineState::dtbattribute and initialize it inpnv_init()after ->initrd_filename.
Sure, I will move it to pnv_init.
Thanks,
Aditya Gupta
Quoted 32 lines
Thanks,
C.
Quoted 23 lines
+ } else {
+ fdt =pnv_dt_create(machine);
+
+ /* Pack resulting tree */
+ _FDT((fdt_pack(fdt)));
+ }
qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt));hw/ppc/pnv.c +4
-0@@ -952,6 +963,14 @@ static void pnv_init(MachineState *machine) g_free(sz); exit(EXIT_FAILURE); } + + /* checks for invalid option combinations */ + if (machine->dtb && (strlen(machine->kernel_cmdline) != 0)) { + error_report("-append and -dtb cannot be used together, aspassed"
+ " command line is ignored in case of custom dtb"); +exit(EXIT_FAILURE);
+ }
+
memory_region_add_subregion(get_system_memory(), 0, machine->ram); /*