Skip to contentSkip to conversation

aspeed/smc: Improve support for the alternate boot function

PATCH Superseded Cédric Le Goater 3 participants 12 messages Oct 4, 2021 – Oct 18, 2021 Arm/Aspeed machine support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover aspeed/smc: Improve support for the alternate boot function

Hello,

The Aspeed SoCs have a dual boot function for firmware fail-over recovery. The system auto-reboots from the second flash if the main flash does not boot successfully within a certain amount of time. This function is called alternate boot (ABR) in the FMC controllers.

On the AST2600, the ABR registers controlling the 2nd watchdog timer were moved from the watchdog register to the FMC controller. To control WDT2 through the FMC model register set, this series creates a local address space on top of WDT2 memory region.

To test on the fuji-bmc machine, run :

    devmem 0x1e620064
    devmem 0x1e78504C 

    devmem 0x1e620064 32 0xffffffff
    devmem 0x1e620064
    devmem 0x1e78504C

Thanks

C.

Cédric Le Goater (4):
aspeed/wdt: Add trace events
aspeed/smc: Dump address offset in trace events aspeed/wdt: Add an alias for the MMIO region aspeed/smc: Improve support for the alternate boot function

 include/hw/ssi/aspeed_smc.h      |  3 ++
 include/hw/watchdog/wdt_aspeed.h |  1 +
 hw/arm/aspeed_ast2600.c          |  2 +
 hw/ssi/aspeed_smc.c              | 84 ++++++++++++++++++++++++++++++--
 hw/watchdog/wdt_aspeed.c         | 20 ++++++--
 hw/ssi/trace-events              |  1 +
 hw/watchdog/trace-events         |  4 ++
 7 files changed, 107 insertions(+), 8 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/4 aspeed/wdt: Add trace events

---
 hw/watchdog/wdt_aspeed.c | 5 +++++
 hw/watchdog/trace-events | 4 ++++
 2 files changed, 9 insertions(+)
hw/watchdog/wdt_aspeed.c +5 -0
index 69c37af9a6e9..146ffcd71301 100644
@@ -19,6 +19,7 @@
 #include "hw/sysbus.h"
 #include "hw/watchdog/wdt_aspeed.h"
 #include "migration/vmstate.h"
+#include "trace.h"
 
 #define WDT_STATUS                      (0x00 / 4)
 #define WDT_RELOAD_VALUE                (0x04 / 4)
@@ -60,6 +61,8 @@ static uint64_t aspeed_wdt_read(void *opaque, hwaddr offset, unsigned size)
 {
     AspeedWDTState *s = ASPEED_WDT(opaque);
 
+    trace_aspeed_wdt_read(offset, size);
+
     offset >>= 2;
 
     switch (offset) {
@@ -140,6 +143,8 @@ static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
     AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(s);
     bool enable;
 
+    trace_aspeed_wdt_write(offset, size, data);
+
     offset >>= 2;
 
     switch (offset) {
hw/watchdog/trace-events +4 -0
index c3bafbffa911..e7523e22aaf2 100644
@@ -5,3 +5,7 @@ cmsdk_apb_watchdog_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK AP
 cmsdk_apb_watchdog_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB watchdog write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
 cmsdk_apb_watchdog_reset(void) "CMSDK APB watchdog: reset"
 cmsdk_apb_watchdog_lock(uint32_t lock) "CMSDK APB watchdog: lock %" PRIu32
+
+# wdt-aspeed.c
+aspeed_wdt_read(uint64_t addr, uint32_t size) "@0x%" PRIx64 " size=%d"
+aspeed_wdt_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size=%d value=0x%"PRIx64
Signature · 1 line
2.31.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] aspeed/wdt: Add trace events

Quoted 1 line · Cédric Le Goater
Quoted 51 lines
---
 hw/watchdog/wdt_aspeed.c | 5 +++++
 hw/watchdog/trace-events | 4 ++++
 2 files changed, 9 insertions(+)
hw/watchdog/wdt_aspeed.c +5 -0
index 69c37af9a6e9..146ffcd71301 100644
@@ -19,6 +19,7 @@
 #include "hw/sysbus.h"
 #include "hw/watchdog/wdt_aspeed.h"
 #include "migration/vmstate.h"
+#include "trace.h"
 
 #define WDT_STATUS                      (0x00 / 4)
 #define WDT_RELOAD_VALUE                (0x04 / 4)
@@ -60,6 +61,8 @@ static uint64_t aspeed_wdt_read(void *opaque, hwaddr offset, unsigned size)
 {
     AspeedWDTState *s = ASPEED_WDT(opaque);
 
+    trace_aspeed_wdt_read(offset, size);
+
     offset >>= 2;
 
     switch (offset) {
@@ -140,6 +143,8 @@ static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
     AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(s);
     bool enable;
 
+    trace_aspeed_wdt_write(offset, size, data);
+
     offset >>= 2;
 
     switch (offset) {
hw/watchdog/trace-events +4 -0
index c3bafbffa911..e7523e22aaf2 100644
@@ -5,3 +5,7 @@ cmsdk_apb_watchdog_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK AP
 cmsdk_apb_watchdog_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB watchdog write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
 cmsdk_apb_watchdog_reset(void) "CMSDK APB watchdog: reset"
 cmsdk_apb_watchdog_lock(uint32_t lock) "CMSDK APB watchdog: lock %" PRIu32
+
+# wdt-aspeed.c
+aspeed_wdt_read(uint64_t addr, uint32_t size) "@0x%" PRIx64 " size=%d"
+aspeed_wdt_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size=%d value=0x%"PRIx64
Signature · 1 line
2.31.1
Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] aspeed/wdt: Add trace events

In reply to Cédric Le Goater

hw/watchdog/trace-events cmsdk_apb_watchdog_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK AP · line 11

Quoted 9 lines · Cédric Le Goater
---
 hw/watchdog/wdt_aspeed.c | 5 +++++
 hw/watchdog/trace-events | 4 ++++
 2 files changed, 9 insertions(+)
hw/watchdog/trace-events +3 -0
+# wdt-aspeed.c
+aspeed_wdt_read(uint64_t addr, uint32_t size) "@0x%" PRIx64 " size=%d"
+aspeed_wdt_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size=%d value=0x%"PRIx64

"size=%u", otherwise:

#4 lore raw

PATCH 2/4 aspeed/smc: Dump address offset in trace events

In reply to Cédric Le Goater

The register index is currently printed and this is confusing.

---
 hw/ssi/aspeed_smc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/ssi/aspeed_smc.c +3 -3
index 7129341c129e..8a988c167604 100644
@@ -728,7 +728,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
          addr < R_SEG_ADDR0 + asc->max_peripherals) ||
         (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + asc->max_peripherals)) {
 
-        trace_aspeed_smc_read(addr, size, s->regs[addr]);
+        trace_aspeed_smc_read(addr << 2, size, s->regs[addr]);
 
         return s->regs[addr];
     } else {
@@ -1029,10 +1029,10 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
     AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
     uint32_t value = data;
 
-    addr >>= 2;
-
     trace_aspeed_smc_write(addr, size, data);
 
+    addr >>= 2;
+
     if (addr == s->r_conf ||
         (addr >= s->r_timings &&
          addr < s->r_timings + asc->nregs_timings) ||
Signature · 1 line
2.31.1
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] aspeed/smc: Dump address offset in trace events

Quoted 3 lines · Cédric Le Goater

The register index is currently printed and this is confusing.

Quoted 34 lines
---
 hw/ssi/aspeed_smc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/ssi/aspeed_smc.c +3 -3
index 7129341c129e..8a988c167604 100644
@@ -728,7 +728,7 @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
          addr < R_SEG_ADDR0 + asc->max_peripherals) ||
         (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + asc->max_peripherals)) {
 
-        trace_aspeed_smc_read(addr, size, s->regs[addr]);
+        trace_aspeed_smc_read(addr << 2, size, s->regs[addr]);
 
         return s->regs[addr];
     } else {
@@ -1029,10 +1029,10 @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
     AspeedSMCClass *asc = ASPEED_SMC_GET_CLASS(s);
     uint32_t value = data;
 
-    addr >>= 2;
-
     trace_aspeed_smc_write(addr, size, data);
 
+    addr >>= 2;
+
     if (addr == s->r_conf ||
         (addr >= s->r_timings &&
          addr < s->r_timings + asc->nregs_timings) ||
Signature · 1 line
2.31.1
#7 lore raw

PATCH 3/4 aspeed/wdt: Add an alias for the MMIO region

In reply to Cédric Le Goater

Initialize the region in the instance_init handler because we will want to link this region in the FMC object before the WDT object is realized.

---
 include/hw/watchdog/wdt_aspeed.h |  1 +
 hw/watchdog/wdt_aspeed.c         | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
include/hw/watchdog/wdt_aspeed.h +1 -0
index f945cd6c5833..008e7d9b498c 100644
@@ -29,6 +29,7 @@ struct AspeedWDTState {
 
     /*< public >*/
     MemoryRegion iomem;
+    MemoryRegion iomem_alias;
     uint32_t regs[ASPEED_WDT_REGS_MAX];
 
     AspeedSCUState *scu;
hw/watchdog/wdt_aspeed.c +12 -3
index 146ffcd71301..6426f3a77494 100644
@@ -261,6 +261,16 @@ static void aspeed_wdt_timer_expired(void *dev)
 
 #define PCLK_HZ 24000000
 
+static void aspeed_wdt_instance_init(Object *obj)
+{
+    AspeedWDTState *s = ASPEED_WDT(obj);
+
+    memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
+                          TYPE_ASPEED_WDT, ASPEED_WDT_REGS_MAX * 4);
+    memory_region_init_alias(&s->iomem_alias, OBJECT(s),
+                             TYPE_ASPEED_WDT ".alias",
+                             &s->iomem, 0, ASPEED_WDT_REGS_MAX * 4);
+}
 static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
 {
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
@@ -275,9 +285,7 @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
      */
     s->pclk_freq = PCLK_HZ;
 
-    memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
-                          TYPE_ASPEED_WDT, ASPEED_WDT_REGS_MAX * 4);
-    sysbus_init_mmio(sbd, &s->iomem);
+    sysbus_init_mmio(sbd, &s->iomem_alias);
 }
 
 static Property aspeed_wdt_properties[] = {
@@ -301,6 +309,7 @@ static void aspeed_wdt_class_init(ObjectClass *klass, void *data)
 static const TypeInfo aspeed_wdt_info = {
     .parent = TYPE_SYS_BUS_DEVICE,
     .name  = TYPE_ASPEED_WDT,
+    .instance_init  = aspeed_wdt_instance_init,
     .instance_size  = sizeof(AspeedWDTState),
     .class_init = aspeed_wdt_class_init,
     .class_size    = sizeof(AspeedWDTClass),
Signature · 1 line
2.31.1
#8 lore raw

Re: [PATCH 3/4] aspeed/wdt: Add an alias for the MMIO region

Hi Cédric,

Quoted 33 lines · Cédric Le Goater

Initialize the region in the instance_init handler because we will want to link this region in the FMC object before the WDT object is realized.

---
 include/hw/watchdog/wdt_aspeed.h |  1 +
 hw/watchdog/wdt_aspeed.c         | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
hw/watchdog/wdt_aspeed.c +10 -0
index 146ffcd71301..6426f3a77494 100644
@@ -261,6 +261,16 @@ static void aspeed_wdt_timer_expired(void *dev)
 
 #define PCLK_HZ 24000000
 
+static void aspeed_wdt_instance_init(Object *obj)
+{
+    AspeedWDTState *s = ASPEED_WDT(obj);
+
+    memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
+                          TYPE_ASPEED_WDT, ASPEED_WDT_REGS_MAX * 4);
+    memory_region_init_alias(&s->iomem_alias, OBJECT(s),
+                             TYPE_ASPEED_WDT ".alias",
+                             &s->iomem, 0, ASPEED_WDT_REGS_MAX * 4);
+}
 static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
 {
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);

hw/watchdog/wdt_aspeed.c static void aspeed_wdt_realize(DeviceState *dev, Error **errp) · line 288

Quoted 7 lines
hw/watchdog/wdt_aspeed.c +1 -3
@@ -275,9 +285,7 @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
      */
     s->pclk_freq = PCLK_HZ;
 
-    memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
-                          TYPE_ASPEED_WDT, ASPEED_WDT_REGS_MAX * 4);
-    sysbus_init_mmio(sbd, &s->iomem);
+    sysbus_init_mmio(sbd, &s->iomem_alias);

Exposing an alias that way seems odd. Don't you want to use/expose a container instead?

Anyhow, by moving memory_region_init_io() in init(), the region is available for linking before realize(), so why do you need an alias?

#9 lore raw

Re: [PATCH 3/4] aspeed/wdt: Add an alias for the MMIO region

Hello Phil,

Quoted 39 lines · Philippe Mathieu-Daudé

Hi Cédric,

Quoted 36 lines · Cédric Le Goater

Initialize the region in the instance_init handler because we will want to link this region in the FMC object before the WDT object is realized.

---
  include/hw/watchdog/wdt_aspeed.h |  1 +
  hw/watchdog/wdt_aspeed.c         | 15 ++++++++++++---
  2 files changed, 13 insertions(+), 3 deletions(-)
hw/watchdog/wdt_aspeed.c +10 -0
index 146ffcd71301..6426f3a77494 100644
@@ -261,6 +261,16 @@ static void aspeed_wdt_timer_expired(void *dev)
 
  #define PCLK_HZ 24000000
 
+static void aspeed_wdt_instance_init(Object *obj)
+{
+    AspeedWDTState *s = ASPEED_WDT(obj);
+
+    memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
+                          TYPE_ASPEED_WDT, ASPEED_WDT_REGS_MAX * 4);
+    memory_region_init_alias(&s->iomem_alias, OBJECT(s),
+                             TYPE_ASPEED_WDT ".alias",
+                             &s->iomem, 0, ASPEED_WDT_REGS_MAX * 4);
+}
  static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
  {
      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
@@ -275,9 +285,7 @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
       */
      s->pclk_freq = PCLK_HZ;
 
Quoted 7 lines

hw/watchdog/wdt_aspeed.c static void aspeed_wdt_realize(DeviceState *dev, Error **errp) · line 288

Quoted 4 lines
hw/watchdog/wdt_aspeed.c +1 -3
-    memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_wdt_ops, s,
-                          TYPE_ASPEED_WDT, ASPEED_WDT_REGS_MAX * 4);
-    sysbus_init_mmio(sbd, &s->iomem);
+    sysbus_init_mmio(sbd, &s->iomem_alias);

Exposing an alias that way seems odd. Don't you want to use/expose a container instead?

I think I got confused by changes in e9c568dbc225 ("hw/arm/aspeed:
Do not sysbus-map mmio flash region directly, use alias") :)

You are right. This needs a container, not an alias. I will respin and fix the aspeed-smc flash address space also.

Quoted 2 lines

Anyhow, by moving memory_region_init_io() in init(), the region is available for linking before realize(), so why do you need an alias?

yes.

I still need to initialize the watchdog models before the FMC. There will be a little change in the order.

Thanks,

C.

#10 lore raw

PATCH 4/4 aspeed/smc: Improve support for the alternate boot function

In reply to Cédric Le Goater

Map the WDT2 registers in the AST2600 FMC memory region by creating a local address space on top of WDT2 memory region.

The model only implements the enable bit of the control register. The reload register uses a 0.1s unit instead of a 1us. Values are converted on the fly when doing the accesses. The restart register is the same.

---
 include/hw/ssi/aspeed_smc.h |  3 ++
 hw/arm/aspeed_ast2600.c     |  2 +
 hw/ssi/aspeed_smc.c         | 78 ++++++++++++++++++++++++++++++++++++-
 hw/ssi/trace-events         |  1 +
 4 files changed, 82 insertions(+), 2 deletions(-)
include/hw/ssi/aspeed_smc.h +3 -0
index 75bc793bd269..ad3c80f2d809 100644
@@ -76,6 +76,9 @@ struct AspeedSMCState {
     MemoryRegion *dram_mr;
     AddressSpace dram_as;
 
+    AddressSpace wdt2_as;
+    MemoryRegion *wdt2_mr;
+
     AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX];
 
     uint8_t snoop_index;
hw/arm/aspeed_ast2600.c +2 -0
index 0384357a9510..2c53d77899a8 100644
@@ -353,6 +353,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     }
 
     /* FMC, The number of CS is set at the board level */
+    object_property_set_link(OBJECT(&s->fmc), "wdt2", OBJECT(&s->wdt[2].iomem),
+                             &error_abort);
     object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr),
                              &error_abort);
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->fmc), errp)) {
hw/ssi/aspeed_smc.c +76 -2

126 lines not on this page · raw message

hw/ssi/trace-events +1 -0
index 612d3d6087aa..0de79bf9c6a5 100644
@@ -9,6 +9,7 @@ aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
 aspeed_smc_dma_rw(const char *dir, uint32_t flash_addr, uint32_t dram_addr, uint32_t size) "%s flash:@0x%08x dram:@0x%08x size:0x%08x"
 aspeed_smc_write(uint64_t addr,  uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
 aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
+aspeed_smc_wdt2_enable(const char *prefix) "WDT2 is %sabled"
 
 # npcm7xx_fiu.c
 
Signature · 1 line
2.31.1
#11 lore raw
In reply to Cédric Le Goater
Quoted 23 lines · Cédric Le Goater

Hello,

The Aspeed SoCs have a dual boot function for firmware fail-over recovery. The system auto-reboots from the second flash if the main flash does not boot successfully within a certain amount of time. This function is called alternate boot (ABR) in the FMC controllers.

On the AST2600, the ABR registers controlling the 2nd watchdog timer were moved from the watchdog register to the FMC controller. To control WDT2 through the FMC model register set, this series creates a local address space on top of WDT2 memory region.

To test on the fuji-bmc machine, run :

     devmem 0x1e620064
     devmem 0x1e78504C

     devmem 0x1e620064 32 0xffffffff
     devmem 0x1e620064
     devmem 0x1e78504C

Thanks

Quoted 8 lines

C.

Cédric Le Goater (4):
aspeed/wdt: Add trace events
aspeed/smc: Dump address offset in trace events aspeed/wdt: Add an alias for the MMIO region aspeed/smc: Improve support for the alternate boot function

Andrew, Peter D., Joel,

Would you have time to tell me what you think about the last 2 patches ? It would be a nice extension for the Fuji in QEMU 6.2.

Here are some images for tests.

https://github.com/peterdelevoryas/openbmc/releases/download/fuji-v0.1-alpha/fuji.mtd

This one is recent :

https://github.com/peterdelevoryas/openbmc/releases/download/fuji.mtd.0/fuji.mtd

U-Boot 2019.04 fuji-bd6ee58668 (Sep 13 2021 - 21:29:46 +0000)

  [    0.000000] Linux version 5.10.23-fuji (oe-user@oe-host) (arm-fb-linux-gnueabi-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Thu Sep 9 23:22:29 UTC 2021

Thanks,

C.

Quoted 10 lines
  include/hw/ssi/aspeed_smc.h      |  3 ++
  include/hw/watchdog/wdt_aspeed.h |  1 +
  hw/arm/aspeed_ast2600.c          |  2 +
  hw/ssi/aspeed_smc.c              | 84 ++++++++++++++++++++++++++++++--
  hw/watchdog/wdt_aspeed.c         | 20 ++++++--
  hw/ssi/trace-events              |  1 +
  hw/watchdog/trace-events         |  4 ++
  7 files changed, 107 insertions(+), 8 deletions(-)