* [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB
@ 2020-10-22 5:32 Anup Patel
2020-10-22 5:32 ` [PATCH 2/2] hw/riscv: virt: " Anup Patel
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Anup Patel @ 2020-10-22 5:32 UTC (permalink / raw)
To: Peter Maydell, Palmer Dabbelt, Alistair Francis, Sagar Karandikar
Cc: Atish Patra, Anup Patel, qemu-riscv, qemu-devel, Anup Patel
Extend sifive_u machine to allow passing custom DTB using "-dtb"
command-line parameter. This will help users pass modified DTB
or Linux SiFive DTB to sifive_u machine.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
---
hw/riscv/sifive_u.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 6ad975d692..554e38abf0 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -100,14 +100,25 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
int cpu;
uint32_t *cells;
char *nodename;
+ const char *dtb_filename;
char ethclk_names[] = "pclk\0hclk";
uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle = 1;
uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle;
- fdt = s->fdt = create_device_tree(&s->fdt_size);
- if (!fdt) {
- error_report("create_device_tree() failed");
- exit(1);
+ dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
+ if (dtb_filename) {
+ fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size);
+ if (!fdt) {
+ error_report("load_device_tree() failed");
+ exit(1);
+ }
+ goto update_bootargs;
+ } else {
+ fdt = s->fdt = create_device_tree(&s->fdt_size);
+ if (!fdt) {
+ error_report("create_device_tree() failed");
+ exit(1);
+ }
}
qemu_fdt_setprop_string(fdt, "/", "model", "SiFive HiFive Unleashed A00");
@@ -390,13 +401,14 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
qemu_fdt_add_subnode(fdt, "/chosen");
qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
- if (cmdline) {
- qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
- }
-
qemu_fdt_setprop_string(fdt, "/aliases", "serial0", nodename);
g_free(nodename);
+
+update_bootargs:
+ if (cmdline) {
+ qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
+ }
}
static void sifive_u_machine_reset(void *opaque, int n, int level)
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] hw/riscv: virt: Allow passing custom DTB
2020-10-22 5:32 [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB Anup Patel
@ 2020-10-22 5:32 ` Anup Patel
2020-10-23 23:33 ` Alistair Francis
2020-10-23 23:32 ` [PATCH 1/2] hw/riscv: sifive_u: " Alistair Francis
2021-03-24 13:41 ` Bin Meng
2 siblings, 1 reply; 6+ messages in thread
From: Anup Patel @ 2020-10-22 5:32 UTC (permalink / raw)
To: Peter Maydell, Palmer Dabbelt, Alistair Francis, Sagar Karandikar
Cc: Atish Patra, Anup Patel, qemu-riscv, qemu-devel, Anup Patel
Extend virt machine to allow passing custom DTB using "-dtb"
command-line parameter. This will help users pass modified DTB
to virt machine.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
---
hw/riscv/virt.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 41bd2f38ba..d535119e37 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -181,6 +181,7 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
{
void *fdt;
int i, cpu, socket;
+ const char *dtb_filename;
MachineState *mc = MACHINE(s);
uint64_t addr, size;
uint32_t *clint_cells, *plic_cells;
@@ -194,10 +195,20 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
- fdt = s->fdt = create_device_tree(&s->fdt_size);
- if (!fdt) {
- error_report("create_device_tree() failed");
- exit(1);
+ dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
+ if (dtb_filename) {
+ fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size);
+ if (!fdt) {
+ error_report("load_device_tree() failed");
+ exit(1);
+ }
+ goto update_bootargs;
+ } else {
+ fdt = s->fdt = create_device_tree(&s->fdt_size);
+ if (!fdt) {
+ error_report("create_device_tree() failed");
+ exit(1);
+ }
}
qemu_fdt_setprop_string(fdt, "/", "model", "riscv-virtio,qemu");
@@ -418,9 +429,6 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
qemu_fdt_add_subnode(fdt, "/chosen");
qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", name);
- if (cmdline) {
- qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
- }
g_free(name);
name = g_strdup_printf("/soc/rtc@%lx", (long)memmap[VIRT_RTC].base);
@@ -441,6 +449,11 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
2, flashbase + flashsize, 2, flashsize);
qemu_fdt_setprop_cell(s->fdt, name, "bank-width", 4);
g_free(name);
+
+update_bootargs:
+ if (cmdline) {
+ qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
+ }
}
static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB
2020-10-22 5:32 [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB Anup Patel
2020-10-22 5:32 ` [PATCH 2/2] hw/riscv: virt: " Anup Patel
@ 2020-10-23 23:32 ` Alistair Francis
2021-03-24 13:41 ` Bin Meng
2 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2020-10-23 23:32 UTC (permalink / raw)
To: Anup Patel
Cc: Peter Maydell, open list:RISC-V, Sagar Karandikar, Anup Patel,
qemu-devel@nongnu.org Developers, Atish Patra, Alistair Francis,
Palmer Dabbelt
On Wed, Oct 21, 2020 at 10:33 PM Anup Patel <anup.patel@wdc.com> wrote:
>
> Extend sifive_u machine to allow passing custom DTB using "-dtb"
> command-line parameter. This will help users pass modified DTB
> or Linux SiFive DTB to sifive_u machine.
>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> hw/riscv/sifive_u.c | 28 ++++++++++++++++++++--------
> 1 file changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
> index 6ad975d692..554e38abf0 100644
> --- a/hw/riscv/sifive_u.c
> +++ b/hw/riscv/sifive_u.c
> @@ -100,14 +100,25 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
> int cpu;
> uint32_t *cells;
> char *nodename;
> + const char *dtb_filename;
> char ethclk_names[] = "pclk\0hclk";
> uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle = 1;
> uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle;
>
> - fdt = s->fdt = create_device_tree(&s->fdt_size);
> - if (!fdt) {
> - error_report("create_device_tree() failed");
> - exit(1);
> + dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
> + if (dtb_filename) {
> + fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size);
> + if (!fdt) {
> + error_report("load_device_tree() failed");
> + exit(1);
> + }
> + goto update_bootargs;
> + } else {
> + fdt = s->fdt = create_device_tree(&s->fdt_size);
> + if (!fdt) {
> + error_report("create_device_tree() failed");
> + exit(1);
> + }
> }
>
> qemu_fdt_setprop_string(fdt, "/", "model", "SiFive HiFive Unleashed A00");
> @@ -390,13 +401,14 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,
>
> qemu_fdt_add_subnode(fdt, "/chosen");
> qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", nodename);
> - if (cmdline) {
> - qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
> - }
> -
> qemu_fdt_setprop_string(fdt, "/aliases", "serial0", nodename);
>
> g_free(nodename);
> +
> +update_bootargs:
> + if (cmdline) {
> + qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
> + }
> }
>
> static void sifive_u_machine_reset(void *opaque, int n, int level)
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] hw/riscv: virt: Allow passing custom DTB
2020-10-22 5:32 ` [PATCH 2/2] hw/riscv: virt: " Anup Patel
@ 2020-10-23 23:33 ` Alistair Francis
0 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2020-10-23 23:33 UTC (permalink / raw)
To: Anup Patel
Cc: Peter Maydell, open list:RISC-V, Sagar Karandikar, Anup Patel,
qemu-devel@nongnu.org Developers, Atish Patra, Alistair Francis,
Palmer Dabbelt
On Wed, Oct 21, 2020 at 10:34 PM Anup Patel <anup.patel@wdc.com> wrote:
>
> Extend virt machine to allow passing custom DTB using "-dtb"
> command-line parameter. This will help users pass modified DTB
> to virt machine.
>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> hw/riscv/virt.c | 27 ++++++++++++++++++++-------
> 1 file changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 41bd2f38ba..d535119e37 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -181,6 +181,7 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
> {
> void *fdt;
> int i, cpu, socket;
> + const char *dtb_filename;
> MachineState *mc = MACHINE(s);
> uint64_t addr, size;
> uint32_t *clint_cells, *plic_cells;
> @@ -194,10 +195,20 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
> hwaddr flashsize = virt_memmap[VIRT_FLASH].size / 2;
> hwaddr flashbase = virt_memmap[VIRT_FLASH].base;
>
> - fdt = s->fdt = create_device_tree(&s->fdt_size);
> - if (!fdt) {
> - error_report("create_device_tree() failed");
> - exit(1);
> + dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
> + if (dtb_filename) {
> + fdt = s->fdt = load_device_tree(dtb_filename, &s->fdt_size);
> + if (!fdt) {
> + error_report("load_device_tree() failed");
> + exit(1);
> + }
> + goto update_bootargs;
> + } else {
> + fdt = s->fdt = create_device_tree(&s->fdt_size);
> + if (!fdt) {
> + error_report("create_device_tree() failed");
> + exit(1);
> + }
> }
>
> qemu_fdt_setprop_string(fdt, "/", "model", "riscv-virtio,qemu");
> @@ -418,9 +429,6 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
>
> qemu_fdt_add_subnode(fdt, "/chosen");
> qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", name);
> - if (cmdline) {
> - qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
> - }
> g_free(name);
>
> name = g_strdup_printf("/soc/rtc@%lx", (long)memmap[VIRT_RTC].base);
> @@ -441,6 +449,11 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,
> 2, flashbase + flashsize, 2, flashsize);
> qemu_fdt_setprop_cell(s->fdt, name, "bank-width", 4);
> g_free(name);
> +
> +update_bootargs:
> + if (cmdline) {
> + qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline);
> + }
> }
>
> static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem,
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB
2020-10-22 5:32 [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB Anup Patel
2020-10-22 5:32 ` [PATCH 2/2] hw/riscv: virt: " Anup Patel
2020-10-23 23:32 ` [PATCH 1/2] hw/riscv: sifive_u: " Alistair Francis
@ 2021-03-24 13:41 ` Bin Meng
2021-03-26 13:29 ` Bin Meng
2 siblings, 1 reply; 6+ messages in thread
From: Bin Meng @ 2021-03-24 13:41 UTC (permalink / raw)
To: Anup Patel
Cc: Peter Maydell, open list:RISC-V, Sagar Karandikar, Anup Patel,
qemu-devel@nongnu.org Developers, Atish Patra, Alistair Francis,
Palmer Dabbelt
Hi Anup,
On Thu, Oct 22, 2020 at 1:34 PM Anup Patel <anup.patel@wdc.com> wrote:
>
> Extend sifive_u machine to allow passing custom DTB using "-dtb"
> command-line parameter. This will help users pass modified DTB
> or Linux SiFive DTB to sifive_u machine.
>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
> ---
> hw/riscv/sifive_u.c | 28 ++++++++++++++++++++--------
> 1 file changed, 20 insertions(+), 8 deletions(-)
>
I am using the following command to boot a Linux v5.11 kernel, but it hangs at:
$ qemu-system-riscv64 -M sifive_u -smp 5 -m 8G -display none -serial
stdio -kernel arch/riscv/boot/Image -dtb
arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dtb -append
"earlycon=sbi console=ttySIF0"
[ 0.000000] smp: Bringing up secondary CPUs ...
Removing -dtb makes the kernel continue booting.
I am not sure what's missing ofusing "-dtb"?
Regards,
Bin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB
2021-03-24 13:41 ` Bin Meng
@ 2021-03-26 13:29 ` Bin Meng
0 siblings, 0 replies; 6+ messages in thread
From: Bin Meng @ 2021-03-26 13:29 UTC (permalink / raw)
To: Anup Patel
Cc: Peter Maydell, open list:RISC-V, Sagar Karandikar, Anup Patel,
qemu-devel@nongnu.org Developers, Atish Patra, Alistair Francis,
Palmer Dabbelt
On Wed, Mar 24, 2021 at 9:41 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Anup,
>
> On Thu, Oct 22, 2020 at 1:34 PM Anup Patel <anup.patel@wdc.com> wrote:
> >
> > Extend sifive_u machine to allow passing custom DTB using "-dtb"
> > command-line parameter. This will help users pass modified DTB
> > or Linux SiFive DTB to sifive_u machine.
> >
> > Signed-off-by: Anup Patel <anup.patel@wdc.com>
> > ---
> > hw/riscv/sifive_u.c | 28 ++++++++++++++++++++--------
> > 1 file changed, 20 insertions(+), 8 deletions(-)
> >
>
> I am using the following command to boot a Linux v5.11 kernel, but it hangs at:
>
> $ qemu-system-riscv64 -M sifive_u -smp 5 -m 8G -display none -serial
> stdio -kernel arch/riscv/boot/Image -dtb
> arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dtb -append
> "earlycon=sbi console=ttySIF0"
>
> [ 0.000000] smp: Bringing up secondary CPUs ...
>
> Removing -dtb makes the kernel continue booting.
>
> I am not sure what's missing ofusing "-dtb"?
I figured out what's missing, and will send a patch on documentation soon.
Regards,
Bin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-26 13:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 5:32 [PATCH 1/2] hw/riscv: sifive_u: Allow passing custom DTB Anup Patel
2020-10-22 5:32 ` [PATCH 2/2] hw/riscv: virt: " Anup Patel
2020-10-23 23:33 ` Alistair Francis
2020-10-23 23:32 ` [PATCH 1/2] hw/riscv: sifive_u: " Alistair Francis
2021-03-24 13:41 ` Bin Meng
2021-03-26 13:29 ` Bin Meng
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).