diff mbox series

[v9,11/14] hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj

Message ID 20200911052101.2602693-12-hskinnemoen@google.com
State Superseded
Headers show
Series Add Nuvoton NPCM730/NPCM750 SoCs and two BMC machines | expand

Commit Message

Gonglei (Arei)" via Sept. 11, 2020, 5:20 a.m. UTC
This allows these NPCM7xx-based boards to boot from a flash image, e.g.
one built with OpenBMC. For example like this:

IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
qemu-system-arm -machine quanta-gsj -nographic \
	-drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on

Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Tested-by: Cédric Le Goater <clg@kaod.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
---
 hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Philippe Mathieu-Daudé Sept. 11, 2020, 12:46 p.m. UTC | #1
On 9/11/20 7:20 AM, Havard Skinnemoen via wrote:
> This allows these NPCM7xx-based boards to boot from a flash image, e.g.
> one built with OpenBMC. For example like this:
> 
> IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
> qemu-system-arm -machine quanta-gsj -nographic \
> 	-drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on
> 
> Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
> Reviewed-by: Cédric Le Goater <clg@kaod.org>
> Tested-by: Cédric Le Goater <clg@kaod.org>
> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
> ---
>  hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
> index b4c772d6b5..79e2e2744c 100644
> --- a/hw/arm/npcm7xx_boards.c
> +++ b/hw/arm/npcm7xx_boards.c
> @@ -20,6 +20,7 @@
>  #include "hw/arm/npcm7xx.h"
>  #include "hw/core/cpu.h"
>  #include "hw/loader.h"
> +#include "hw/qdev-properties.h"
>  #include "qapi/error.h"
>  #include "qemu-common.h"
>  #include "qemu/units.h"
> @@ -55,6 +56,22 @@ static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
>      }
>  }
>  
> +static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
> +                                  const char *flash_type, DriveInfo *dinfo)
> +{
> +    DeviceState *flash;
> +    qemu_irq flash_cs;
> +
> +    flash = qdev_new(flash_type);
> +    if (dinfo) {
> +        qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
> +    }
> +    qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
> +
> +    flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
> +    qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
> +}
> +
>  static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
>  {
>      memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
> @@ -92,6 +109,7 @@ static void npcm750_evb_init(MachineState *machine)
>      qdev_realize(DEVICE(soc), NULL, &error_fatal);
>  
>      npcm7xx_load_bootrom(machine, soc);
> +    npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));

Nitpicking: add definition for '0' magic number
(consider as future cleanup).

>      npcm7xx_load_kernel(machine, soc);
>  }
>  
> @@ -104,6 +122,8 @@ static void quanta_gsj_init(MachineState *machine)
>      qdev_realize(DEVICE(soc), NULL, &error_fatal);
>  
>      npcm7xx_load_bootrom(machine, soc);
> +    npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
> +                          drive_get(IF_MTD, 0, 0));

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>      npcm7xx_load_kernel(machine, soc);
>  }
>  
>
Havard Skinnemoen Sept. 12, 2020, 10:24 p.m. UTC | #2
On Fri, Sep 11, 2020 at 5:46 AM Philippe Mathieu-Daudé <f4bug@amsat.org>
wrote:

>
>
> On 9/11/20 7:20 AM, Havard Skinnemoen via wrote:
> > This allows these NPCM7xx-based boards to boot from a flash image, e.g.
> > one built with OpenBMC. For example like this:
> >
> > IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
> > qemu-system-arm -machine quanta-gsj -nographic \
> >       -drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on
> >
> > Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
> > Reviewed-by: Cédric Le Goater <clg@kaod.org>
> > Tested-by: Cédric Le Goater <clg@kaod.org>
> > Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
> > ---
> >  hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> >
> > diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
> > index b4c772d6b5..79e2e2744c 100644
> > --- a/hw/arm/npcm7xx_boards.c
> > +++ b/hw/arm/npcm7xx_boards.c
> > @@ -20,6 +20,7 @@
> >  #include "hw/arm/npcm7xx.h"
> >  #include "hw/core/cpu.h"
> >  #include "hw/loader.h"
> > +#include "hw/qdev-properties.h"
> >  #include "qapi/error.h"
> >  #include "qemu-common.h"
> >  #include "qemu/units.h"
> > @@ -55,6 +56,22 @@ static void npcm7xx_load_bootrom(MachineState
> *machine, NPCM7xxState *soc)
> >      }
> >  }
> >
> > +static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
> > +                                  const char *flash_type, DriveInfo
> *dinfo)
> > +{
> > +    DeviceState *flash;
> > +    qemu_irq flash_cs;
> > +
> > +    flash = qdev_new(flash_type);
> > +    if (dinfo) {
> > +        qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
> > +    }
> > +    qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
> > +
> > +    flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
> > +    qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
> > +}
> > +
> >  static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
> >  {
> >      memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA,
> dram);
> > @@ -92,6 +109,7 @@ static void npcm750_evb_init(MachineState *machine)
> >      qdev_realize(DEVICE(soc), NULL, &error_fatal);
> >
> >      npcm7xx_load_bootrom(machine, soc);
> > +    npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD,
> 0, 0));
>
> Nitpicking: add definition for '0' magic number
> (consider as future cleanup).
>

Thanks. I've made the change, but won't send it out until this series is
merged, or I'll fold it in if I need to do another iteration for other
reasons.

>      npcm7xx_load_kernel(machine, soc);
> >  }
> >
> > @@ -104,6 +122,8 @@ static void quanta_gsj_init(MachineState *machine)
> >      qdev_realize(DEVICE(soc), NULL, &error_fatal);
> >
> >      npcm7xx_load_bootrom(machine, soc);
> > +    npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
> > +                          drive_get(IF_MTD, 0, 0));
>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> >      npcm7xx_load_kernel(machine, soc);
> >  }
> >
> >
>
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 11, 2020 at 5:46 AM Philippe Mathieu-Daudé &lt;<a href="mailto:f4bug@amsat.org">f4bug@amsat.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 9/11/20 7:20 AM, Havard Skinnemoen via wrote:<br>
&gt; This allows these NPCM7xx-based boards to boot from a flash image, e.g.<br>
&gt; one built with OpenBMC. For example like this:<br>
&gt; <br>
&gt; IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc<br>
&gt; qemu-system-arm -machine quanta-gsj -nographic \<br>
&gt;       -drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on<br>
&gt; <br>
&gt; Reviewed-by: Tyrone Ting &lt;<a href="mailto:kfting@nuvoton.com" target="_blank" class="cremed">kfting@nuvoton.com</a>&gt;<br>
&gt; Reviewed-by: Cédric Le Goater &lt;<a href="mailto:clg@kaod.org" target="_blank" class="cremed">clg@kaod.org</a>&gt;<br>
&gt; Tested-by: Cédric Le Goater &lt;<a href="mailto:clg@kaod.org" target="_blank" class="cremed">clg@kaod.org</a>&gt;<br>
&gt; Tested-by: Philippe Mathieu-Daudé &lt;<a href="mailto:f4bug@amsat.org" target="_blank" class="cremed">f4bug@amsat.org</a>&gt;<br>
&gt; Signed-off-by: Havard Skinnemoen &lt;<a href="mailto:hskinnemoen@google.com" target="_blank" class="cremed">hskinnemoen@google.com</a>&gt;<br>
&gt; ---<br>
&gt;  hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++<br>
&gt;  1 file changed, 20 insertions(+)<br>
&gt; <br>
&gt; diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c<br>
&gt; index b4c772d6b5..79e2e2744c 100644<br>
&gt; --- a/hw/arm/npcm7xx_boards.c<br>
&gt; +++ b/hw/arm/npcm7xx_boards.c<br>
&gt; @@ -20,6 +20,7 @@<br>
&gt;  #include &quot;hw/arm/npcm7xx.h&quot;<br>
&gt;  #include &quot;hw/core/cpu.h&quot;<br>
&gt;  #include &quot;hw/loader.h&quot;<br>
&gt; +#include &quot;hw/qdev-properties.h&quot;<br>
&gt;  #include &quot;qapi/error.h&quot;<br>
&gt;  #include &quot;qemu-common.h&quot;<br>
&gt;  #include &quot;qemu/units.h&quot;<br>
&gt; @@ -55,6 +56,22 @@ static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)<br>
&gt;      }<br>
&gt;  }<br>
&gt;  <br>
&gt; +static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,<br>
&gt; +                                  const char *flash_type, DriveInfo *dinfo)<br>
&gt; +{<br>
&gt; +    DeviceState *flash;<br>
&gt; +    qemu_irq flash_cs;<br>
&gt; +<br>
&gt; +    flash = qdev_new(flash_type);<br>
&gt; +    if (dinfo) {<br>
&gt; +        qdev_prop_set_drive(flash, &quot;drive&quot;, blk_by_legacy_dinfo(dinfo));<br>
&gt; +    }<br>
&gt; +    qdev_realize_and_unref(flash, BUS(fiu-&gt;spi), &amp;error_fatal);<br>
&gt; +<br>
&gt; +    flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);<br>
&gt; +    qdev_connect_gpio_out_named(DEVICE(fiu), &quot;cs&quot;, cs_no, flash_cs);<br>
&gt; +}<br>
&gt; +<br>
&gt;  static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)<br>
&gt;  {<br>
&gt;      memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);<br>
&gt; @@ -92,6 +109,7 @@ static void npcm750_evb_init(MachineState *machine)<br>
&gt;      qdev_realize(DEVICE(soc), NULL, &amp;error_fatal);<br>
&gt;  <br>
&gt;      npcm7xx_load_bootrom(machine, soc);<br>
&gt; +    npcm7xx_connect_flash(&amp;soc-&gt;fiu[0], 0, &quot;w25q256&quot;, drive_get(IF_MTD, 0, 0));<br>
<br>
Nitpicking: add definition for &#39;0&#39; magic number<br>
(consider as future cleanup).<br></blockquote><div><br></div><div>Thanks. I&#39;ve made the change, but won&#39;t send it out until this series is merged, or I&#39;ll fold it in if I need to do another iteration for other reasons.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
&gt;      npcm7xx_load_kernel(machine, soc);<br>
&gt;  }<br>
&gt;  <br>
&gt; @@ -104,6 +122,8 @@ static void quanta_gsj_init(MachineState *machine)<br>
&gt;      qdev_realize(DEVICE(soc), NULL, &amp;error_fatal);<br>
&gt;  <br>
&gt;      npcm7xx_load_bootrom(machine, soc);<br>
&gt; +    npcm7xx_connect_flash(&amp;soc-&gt;fiu[0], 0, &quot;mx25l25635e&quot;,<br>
&gt; +                          drive_get(IF_MTD, 0, 0));<br>
<br>
Reviewed-by: Philippe Mathieu-Daudé &lt;<a href="mailto:f4bug@amsat.org" target="_blank" class="cremed">f4bug@amsat.org</a>&gt;<br>
<br>
&gt;      npcm7xx_load_kernel(machine, soc);<br>
&gt;  }<br>
&gt;  <br>
&gt; <br>
</blockquote></div></div>
diff mbox series

Patch

diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
index b4c772d6b5..79e2e2744c 100644
--- a/hw/arm/npcm7xx_boards.c
+++ b/hw/arm/npcm7xx_boards.c
@@ -20,6 +20,7 @@ 
 #include "hw/arm/npcm7xx.h"
 #include "hw/core/cpu.h"
 #include "hw/loader.h"
+#include "hw/qdev-properties.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "qemu/units.h"
@@ -55,6 +56,22 @@  static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
     }
 }
 
+static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
+                                  const char *flash_type, DriveInfo *dinfo)
+{
+    DeviceState *flash;
+    qemu_irq flash_cs;
+
+    flash = qdev_new(flash_type);
+    if (dinfo) {
+        qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
+    }
+    qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
+
+    flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
+    qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
+}
+
 static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
 {
     memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
@@ -92,6 +109,7 @@  static void npcm750_evb_init(MachineState *machine)
     qdev_realize(DEVICE(soc), NULL, &error_fatal);
 
     npcm7xx_load_bootrom(machine, soc);
+    npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
     npcm7xx_load_kernel(machine, soc);
 }
 
@@ -104,6 +122,8 @@  static void quanta_gsj_init(MachineState *machine)
     qdev_realize(DEVICE(soc), NULL, &error_fatal);
 
     npcm7xx_load_bootrom(machine, soc);
+    npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
+                          drive_get(IF_MTD, 0, 0));
     npcm7xx_load_kernel(machine, soc);
 }