:p
atchew
Login
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 <adityag@linux.ibm.com> --- This is an RFC patch, and hence might not be the final implementation, though this current one is a solution which works --- --- hw/ppc/pnv.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index XXXXXXX..XXXXXXX 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -XXX,XX +XXX,XX @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) PnvMachineState *pnv = PNV_MACHINE(machine); IPMIBmc *bmc; void *fdt; + FILE *fdt_file; + uint32_t fdt_size; qemu_devices_reset(reason); @@ -XXX,XX +XXX,XX @@ 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'" + " might ignored and the dtb passed will be used as-is"); - /* Pack resulting tree */ - _FDT((fdt_pack(fdt))); + fdt = g_malloc0(FDT_MAX_SIZE); + + /* read the file 'machine->dtb', and load it into 'fdt' buffer */ + fdt_file = fopen(machine->dtb, "r"); + if (fdt_file != NULL) { + fdt_size = fread(fdt, sizeof(char), FDT_MAX_SIZE, fdt_file); + if (ferror(fdt_file) != 0) { + error_report("Could not load dtb '%s'", + machine->dtb); + exit(1); + } + + /* mark end of the fdt buffer with '\0' */ + ((char *)fdt)[fdt_size] = '\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)); -- 2.45.2
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 <adityag@linux.ibm.com> --- Changelog =========== v2: + move reading dtb and warning to pnv_init v1: + use 'g_file_get_contents' and add check for -append & -dtb as suggested by Daniel --- --- hw/ppc/pnv.c | 29 ++++++++++++++++++++++++++--- include/hw/ppc/pnv.h | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index XXXXXXX..XXXXXXX 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -XXX,XX +XXX,XX @@ static void pnv_reset(MachineState *machine, ShutdownCause reason) } } - fdt = pnv_dt_create(machine); + if (!pnv->fdt) { + pnv->fdt = pnv_dt_create(machine); - /* Pack resulting tree */ - _FDT((fdt_pack(fdt))); + /* Pack resulting tree */ + _FDT((fdt_pack(pnv->fdt))); + } + fdt = pnv->fdt; qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt)); @@ -XXX,XX +XXX,XX @@ 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); /* @@ -XXX,XX +XXX,XX @@ static void pnv_init(MachineState *machine) } } + /* load dtb if passed */ + 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"); + + /* read the file 'machine->dtb', and load it into 'fdt' buffer */ + if (!g_file_get_contents(machine->dtb, (gchar **)&pnv->fdt, NULL, NULL)) { + error_report("Could not load dtb '%s'", machine->dtb); + exit(1); + } + } + /* MSIs are supported on this platform */ msi_nonbroken = true; diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h index XXXXXXX..XXXXXXX 100644 --- a/include/hw/ppc/pnv.h +++ b/include/hw/ppc/pnv.h @@ -XXX,XX +XXX,XX @@ struct PnvMachineState { uint32_t initrd_base; long initrd_size; + void *fdt; + uint32_t num_chips; PnvChip **chips; -- 2.45.2