aspeed/smc: Improve support for the alternate boot function
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 0x1e78504CThanks
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
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
@@ -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
@@ -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
Re: [PATCH 1/4] aspeed/wdt: Add trace events
Quoted 1 line · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>
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@@ -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@@ -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%"PRIx64Signature · 1 line
2.31.1
Re: [PATCH 1/4] aspeed/wdt: Add trace events
In reply to Cédric Le Goaterhw/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
Signed-off-by Cédric Le Goater <[email protected]>--- 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:
PATCH 2/4 aspeed/smc: Dump address offset in trace events
In reply to Cédric Le GoaterThe 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
@@ -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
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.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 34 lines
--- hw/ssi/aspeed_smc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/ssi/aspeed_smc.c +3
-3@@ -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
Re: [PATCH 2/4] aspeed/smc: Dump address offset in trace events
In reply to Cédric Le GoaterQuoted 6 lines · Cédric Le Goater
The register index is currently printed and this is confusing.
Signed-off-by Cédric Le Goater <[email protected]>--- hw/ssi/aspeed_smc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
PATCH 3/4 aspeed/wdt: Add an alias for the MMIO region
In reply to Cédric Le GoaterInitialize 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
@@ -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
@@ -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
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_inithandler because we will want to link this region in the FMC object before the WDT object is realized.Cc Peter Delevoryas <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- 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@@ -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?
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_inithandler because we will want to link this region in the FMC object before the WDT object is realized.Cc Peter Delevoryas <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- 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@@ -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()ininit(), the region is available for linking beforerealize(), 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.
PATCH 4/4 aspeed/smc: Improve support for the alternate boot function
In reply to Cédric Le GoaterMap 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
@@ -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
@@ -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
@@ -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
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 0x1e78504CThanks
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(-)