diff mbox series

[1/2] hw/riscv: sifive_u: Allow passing custom DTB

Message ID 20201022053225.2596110-1-anup.patel@wdc.com
State New
Headers show
Series [1/2] hw/riscv: sifive_u: Allow passing custom DTB | expand

Commit Message

Anup Patel Oct. 22, 2020, 5:32 a.m. UTC
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(-)

Comments

Alistair Francis Oct. 23, 2020, 11:32 p.m. UTC | #1
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

>

>
Bin Meng March 24, 2021, 1:41 p.m. UTC | #2
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
Bin Meng March 26, 2021, 1:29 p.m. UTC | #3
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
diff mbox series

Patch

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)