Skip to contentSkip to conversation

AE350 support SMP boot from flash

PATCH New Andes 3 participants 11 messages May 9, 2019 RISC-V

lore
Share & tools
lore

Andes

author
#0 lore raw

v5 cover AE350 support SMP boot from flash

From: Rick Chen <[email protected]>

In current RISC-V SMP flow, AE350 will encounter the the write failure problem since hart_lottery and available_harts_lock was not in ram address but in flash address when booing from flash.

This patch can help to fix the failure problem when AE350 was booting from flash by disabling this two features.

Changes in v5:
- New patch

	[PATCH v5 6/6] riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS
	It will fix Travis failure item :
	https://travis-ci.org/rickchen36/u-boot-riscv/jobs/529605196

Changes in v4:
- Use CONFIG_OF_SEPARATE instead of CONFIG_OF_BOARD in ae350_rv32_xip_defconfig and ae350_rv64_xip_defconfig.
- Remove prior_stage_fdt_address in board_fdt_blob_setup.
- Modify CONFIG_SYS_FDT_BASE as flash address.

Changes in v3:
- Modify CONFIG_XIP descriptions
- Use #ifdef CONFIG_OF_PRIOR_STAGE to replace # if CONFIG_IS_ENABLED(OF_PRIOR_STAGE)
- Recovery some blank lines
- Add CONFIG_SF_DEFAULT_MODE=0x0 in ae350_rv32_xip_defconfig and ae350_rv64_xip_defconfig
- #ifdef CONFIG_OF_PRIOR_STAGE shall also surround SREG s1, 0(t0)
- Modify CONFIG_SYS_FDT_BASE from 0x000f0000 as 0x800f0000 in ax25-ae350.h

Changes in v2:
- Fix some typos
- Also surround the declaration of prior_stage_fdt_address in arch/riscv/cpu/cpu.c with OF_PRIOR_STAGE
- Use CONFIP_XIP to replace CONFIG_HART_LOTTERY and CONFIG_AVAILABLE_HARTS

Rick Chen (6):
riscv: Introduce CONFIG_XIP to support booting from flash
riscv: configs: Support AE350 SMP booting from flash flow
riscv: prior_stage_fdt_address should only be used when OF_PRIOR_STAGE
is enabled
riscv: configs: AE350 will use CONFIG_OF_PRIOR_STAGE when boots from
ram
riscv: configs: AE350 will use CONFIG_OF_SEPARATE when boots from
flash
riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS

 arch/riscv/Kconfig                      |  7 ++++++
 arch/riscv/cpu/cpu.c                    |  4 ++++
 arch/riscv/cpu/start.S                  |  8 +++++++
 arch/riscv/include/asm/global_data.h    |  2 ++
 arch/riscv/lib/asm-offsets.c            |  2 ++
 arch/riscv/lib/smp.c                    |  2 ++
 board/AndesTech/ax25-ae350/MAINTAINERS  |  2 ++
 board/AndesTech/ax25-ae350/ax25-ae350.c |  4 ----
 configs/ae350_rv32_defconfig            |  2 +-
 configs/ae350_rv32_xip_defconfig        | 37 ++++++++++++++++++++++++++++++++
 configs/ae350_rv64_defconfig            |  2 +-
 configs/ae350_rv64_xip_defconfig        | 38 +++++++++++++++++++++++++++++++++
 include/configs/ax25-ae350.h            |  2 +-
 13 files changed, 105 insertions(+), 7 deletions(-)
 create mode 100644 configs/ae350_rv32_xip_defconfig
 create mode 100644 configs/ae350_rv64_xip_defconfig
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v5 1/6 riscv: Introduce CONFIG_XIP to support booting from flash

From: Rick Chen <[email protected]>

When U-Boot boots from flash, during the boot process, hart_lottery and available_harts_lock variable addresses point to flash which is not writable. This causes boot failures on AE350. Introduce a config option CONFIG_XIP to support such configuration.

---
 arch/riscv/Kconfig                   | 7 +++++++
 arch/riscv/cpu/cpu.c                 | 2 ++
 arch/riscv/cpu/start.S               | 6 ++++++
 arch/riscv/include/asm/global_data.h | 2 ++
 arch/riscv/lib/asm-offsets.c         | 2 ++
 arch/riscv/lib/smp.c                 | 2 ++
 6 files changed, 21 insertions(+)
arch/riscv/Kconfig +7 -0
index ae8ff7b..362f3cd 100644
@@ -162,6 +162,13 @@ config SBI_IPI
 	default y if RISCV_SMODE
 	depends on SMP
 
+config XIP
+	bool "XIP mode"
+	help
+	  XIP (eXecute In Place) is a method for executing code directly
+	  from a NOR flash memory without copying the code to ram.
+	  Say yes here if U-Boot boots from flash directly.
+
 config STACK_SIZE_SHIFT
 	int
 	default 13
arch/riscv/cpu/cpu.c +2 -0
index c32de8a..0cfd7d6 100644
@@ -16,6 +16,7 @@
  * before the bss section is available.
  */
 phys_addr_t prior_stage_fdt_address __attribute__((section(".data")));
+#ifndef CONFIG_XIP
 u32 hart_lottery __attribute__((section(".data"))) = 0;
 
 /*
@@ -23,6 +24,7 @@ u32 hart_lottery __attribute__((section(".data"))) = 0;
  * finished initialization of global data.
  */
 u32 available_harts_lock = 1;
+#endif
 
 static inline bool supports_extension(char ext)
 {
arch/riscv/cpu/start.S +6 -0
index a4433fb..3402d09 100644
@@ -98,6 +98,7 @@ call_board_init_f_0:
 	mv	sp, a0
 #endif
 
+#ifndef CONFIG_XIP
 	/*
 	 * Pick hart to initialize global data and run U-Boot. The other harts
 	 * wait for initialization to complete.
@@ -106,6 +107,9 @@ call_board_init_f_0:
 	li	s2, 1
 	amoswap.w s2, t1, 0(t0)
 	bnez	s2, wait_for_gd_init
+#else
+	bnez	tp, secondary_hart_loop
+#endif
 
 	la	t0, prior_stage_fdt_address
 	SREG	s1, 0(t0)
@@ -115,6 +119,7 @@ call_board_init_f_0:
 	/* save the boot hart id to global_data */
 	SREG	tp, GD_BOOT_HART(gp)
 
+#ifndef CONFIG_XIP
 	la	t0, available_harts_lock
 	fence	rw, w
 	amoswap.w zero, zero, 0(t0)
@@ -141,6 +146,7 @@ wait_for_gd_init:
 	 * secondary_hart_loop.
 	 */
 	bnez	s2, secondary_hart_loop
+#endif
 
 	/* Enable cache */
 	jal	icache_enable
arch/riscv/include/asm/global_data.h +2 -0
index dffcd45..b74bd7e 100644
@@ -27,7 +27,9 @@ struct arch_global_data {
 #ifdef CONFIG_SMP
 	struct ipi_data ipi[CONFIG_NR_CPUS];
 #endif
+#ifndef CONFIG_XIP
 	ulong available_harts;
+#endif
 };
 
 #include <asm-generic/global_data.h>
arch/riscv/lib/asm-offsets.c +2 -0
index f998402..4fa4fd3 100644
@@ -14,7 +14,9 @@
 int main(void)
 {
 	DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart));
+#ifndef CONFIG_XIP
 	DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t, arch.available_harts));
+#endif
 
 	return 0;
 }
arch/riscv/lib/smp.c +2 -0
index caa292c..cc66f15 100644
@@ -63,9 +63,11 @@ static int send_ipi_many(struct ipi_data *ipi)
 			continue;
 		}
 
+#ifndef CONFIG_XIP
 		/* skip if hart is not available */
 		if (!(gd->arch.available_harts & (1 << reg)))
 			continue;
+#endif
 
 		gd->arch.ipi[reg].addr = ipi->addr;
 		gd->arch.ipi[reg].arg0 = ipi->arg0;
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v5 2/6 riscv: configs: Support AE350 SMP booting from flash flow

In reply to Andes

From: Rick Chen <[email protected]>

Add two defconfigs to support AE350 SMP booting from flash.

---
 configs/ae350_rv32_xip_defconfig | 37 +++++++++++++++++++++++++++++++++++++
 configs/ae350_rv64_xip_defconfig | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 configs/ae350_rv32_xip_defconfig
 create mode 100644 configs/ae350_rv64_xip_defconfig
configs/ae350_rv32_xip_defconfig new file +37 -0
new file mode 100644
index 0000000..76534f2
@@ -0,0 +1,37 @@
+CONFIG_RISCV=y
+CONFIG_SYS_TEXT_BASE=0x80000000
+CONFIG_XIP=y
+CONFIG_TARGET_AX25_AE350=y
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_NR_DRAM_BANKS=2
+CONFIG_FIT=y
+CONFIG_BOOTDELAY=3
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SYS_PROMPT="RISC-V # "
+CONFIG_CMD_IMLS=y
+CONFIG_CMD_MMC=y
+CONFIG_CMD_SF=y
+CONFIG_CMD_SF_TEST=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_BOOTP_PREFER_SERVERIP=y
+CONFIG_CMD_CACHE=y
+CONFIG_OF_BOARD=y
+CONFIG_DEFAULT_DEVICE_TREE="ae350_32"
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_MMC=y
+CONFIG_FTSDC010=y
+CONFIG_FTSDC010_SDIO=y
+CONFIG_MTD_NOR_FLASH=y
+CONFIG_FLASH_CFI_DRIVER=y
+CONFIG_CFI_FLASH=y
+CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
+CONFIG_SYS_FLASH_CFI=y
+CONFIG_SPI_FLASH=y
+CONFIG_SF_DEFAULT_MODE=0x0
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_FTMAC100=y
+CONFIG_BAUDRATE=38400
+CONFIG_SYS_NS16550=y
+CONFIG_SPI=y
+CONFIG_ATCSPI200_SPI=y
configs/ae350_rv64_xip_defconfig new file +38 -0
new file mode 100644
index 0000000..f7f2925
@@ -0,0 +1,38 @@
+CONFIG_RISCV=y
+CONFIG_SYS_TEXT_BASE=0x80000000
+CONFIG_XIP=y
+CONFIG_TARGET_AX25_AE350=y
+CONFIG_ARCH_RV64I=y
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_NR_DRAM_BANKS=2
+CONFIG_FIT=y
+CONFIG_BOOTDELAY=3
+CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_SYS_PROMPT="RISC-V # "
+CONFIG_CMD_IMLS=y
+CONFIG_CMD_MMC=y
+CONFIG_CMD_SF=y
+CONFIG_CMD_SF_TEST=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_BOOTP_PREFER_SERVERIP=y
+CONFIG_CMD_CACHE=y
+CONFIG_OF_BOARD=y
+CONFIG_DEFAULT_DEVICE_TREE="ae350_64"
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_MMC=y
+CONFIG_FTSDC010=y
+CONFIG_FTSDC010_SDIO=y
+CONFIG_MTD_NOR_FLASH=y
+CONFIG_FLASH_CFI_DRIVER=y
+CONFIG_CFI_FLASH=y
+CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y
+CONFIG_SYS_FLASH_CFI=y
+CONFIG_SPI_FLASH=y
+CONFIG_SF_DEFAULT_MODE=0x0
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_FTMAC100=y
+CONFIG_BAUDRATE=38400
+CONFIG_SYS_NS16550=y
+CONFIG_SPI=y
+CONFIG_ATCSPI200_SPI=y
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v5 3/6 riscv: prior_stage_fdt_address should only be used when OF_PRIOR_STAGE is enabled

In reply to Andes

From: Rick Chen <[email protected]>

This patch will fix prior_stage_fdt_address write failure problem, when AE350 boots from flash.

When AE350 boots from flash, prior_stage_fdt_address will be flash address, we shall avoid it to be written.

---
 arch/riscv/cpu/cpu.c   | 2 ++
 arch/riscv/cpu/start.S | 2 ++
 2 files changed, 4 insertions(+)
arch/riscv/cpu/cpu.c +2 -0
index 0cfd7d6..e9a8b43 100644
@@ -15,7 +15,9 @@
  * The variables here must be stored in the data section since they are used
  * before the bss section is available.
  */
+#ifdef CONFIG_OF_PRIOR_STAGE
 phys_addr_t prior_stage_fdt_address __attribute__((section(".data")));
+#endif
 #ifndef CONFIG_XIP
 u32 hart_lottery __attribute__((section(".data"))) = 0;
 
arch/riscv/cpu/start.S +2 -0
index 3402d09..60ac8c6 100644
@@ -111,8 +111,10 @@ call_board_init_f_0:
 	bnez	tp, secondary_hart_loop
 #endif
 
+#ifdef CONFIG_OF_PRIOR_STAGE
 	la	t0, prior_stage_fdt_address
 	SREG	s1, 0(t0)
+#endif
 
 	jal	board_init_f_init_reserve
 
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v5 4/6 riscv: configs: AE350 will use CONFIG_OF_PRIOR_STAGE when boots from ram

In reply to Andes

From: Rick Chen <[email protected]>

When AE350 boots from ram, use CONFIG_OF_PRIOR_STAGE instead of CONFIG_OF_BOARD.

---
 configs/ae350_rv32_defconfig | 2 +-
 configs/ae350_rv64_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
configs/ae350_rv32_defconfig +1 -1
index f029455..71d2716 100644
@@ -14,7 +14,7 @@ CONFIG_CMD_SF_TEST=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
-CONFIG_OF_BOARD=y
+CONFIG_OF_PRIOR_STAGE=y
 CONFIG_DEFAULT_DEVICE_TREE="ae350_32"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_RANDOM_ETHADDR=y
configs/ae350_rv64_defconfig +1 -1
index 98635a2..9bf1737 100644
@@ -15,7 +15,7 @@ CONFIG_CMD_SF_TEST=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
-CONFIG_OF_BOARD=y
+CONFIG_OF_PRIOR_STAGE=y
 CONFIG_DEFAULT_DEVICE_TREE="ae350_64"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_RANDOM_ETHADDR=y
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v5 5/6 riscv: configs: AE350 will use CONFIG_OF_SEPARATE when boots from flash

In reply to Andes

From: Rick Chen <[email protected]>

When AE350 boots from flash, use CONFIG_OF_SEPARATE instead of CONFIG_OF_BOARD.

Also remove unused code about prior_stage_fdt_address. And modify CONFIG_SYS_FDT_BASE as flash address.

---
 board/AndesTech/ax25-ae350/ax25-ae350.c | 4 ----
 configs/ae350_rv32_xip_defconfig        | 2 +-
 configs/ae350_rv64_xip_defconfig        | 2 +-
 include/configs/ax25-ae350.h            | 2 +-
 4 files changed, 3 insertions(+), 7 deletions(-)
board/AndesTech/ax25-ae350/ax25-ae350.c +0 -4
index d343453..3d65ce7 100644
@@ -67,10 +67,6 @@ ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
 
 void *board_fdt_blob_setup(void)
 {
-	void **ptr = (void *)&prior_stage_fdt_address;
-	if (fdt_magic(*ptr) == FDT_MAGIC)
-			return (void *)*ptr;
-
 	return (void *)CONFIG_SYS_FDT_BASE;
 }
 
configs/ae350_rv32_xip_defconfig +1 -1
index 76534f2..07f1ecc 100644
@@ -15,7 +15,7 @@ CONFIG_CMD_SF_TEST=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
-CONFIG_OF_BOARD=y
+CONFIG_OF_SEPARATE=y
 CONFIG_DEFAULT_DEVICE_TREE="ae350_32"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_RANDOM_ETHADDR=y
configs/ae350_rv64_xip_defconfig +1 -1
index f7f2925..28afd81 100644
@@ -16,7 +16,7 @@ CONFIG_CMD_SF_TEST=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_PREFER_SERVERIP=y
 CONFIG_CMD_CACHE=y
-CONFIG_OF_BOARD=y
+CONFIG_OF_SEPARATE=y
 CONFIG_DEFAULT_DEVICE_TREE="ae350_64"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_NET_RANDOM_ETHADDR=y
include/configs/ax25-ae350.h +1 -1
index 395f3a4..a4037f3 100644
@@ -40,7 +40,7 @@
 #define CONFIG_SYS_MALLOC_LEN   (512 << 10)
 
 /* DT blob (fdt) address */
-#define CONFIG_SYS_FDT_BASE		0x000f0000
+#define CONFIG_SYS_FDT_BASE		0x800f0000
 
 /*
  * Physical Memory Map
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v5 6/6 riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS

In reply to Andes

From: Rick Chen <[email protected]>

This patch will fix Travis failure item as below:
https://travis-ci.org/rickchen36/u-boot-riscv/jobs/529605196

Check for configs without MAINTAINERS entry

Cc Greentime Hu <[email protected]>
---
 board/AndesTech/ax25-ae350/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
board/AndesTech/ax25-ae350/MAINTAINERS +2 -0
index b0a99e4..feed5d1 100644
@@ -5,3 +5,5 @@ F:	board/AndesTech/ax25-ae350/
 F:	include/configs/ax25-ae350.h
 F:	configs/ae350_rv32_defconfig
 F:	configs/ae350_rv64_defconfig
+F:	configs/ae350_rv32_xip_defconfig
+F:	configs/ae350_rv64_xip_defconfig
Signature · 1 line
2.7.4
#7 lore raw

PATCH v5 6/6 riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS

Hi Rick,

Quoted 6 lines · Andes

From: Rick Chen <[email protected]>

This patch will fix Travis failure item as below:
https://travis-ci.org/rickchen36/u-boot-riscv/jobs/529605196

Quoted 8 lines

Check for configs without MAINTAINERS entry

Cc Greentime Hu <[email protected]>
---
 board/AndesTech/ax25-ae350/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

Please squash this one into "[PATCH v5 2/6] riscv: configs: Support AE350 SMP booting from flash flow", as they are from the same patch series, and not applied yet as of today.

Regards,
Bin

#8 lore raw

PATCH v5 6/6 riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS

Hi Bin

Bin Meng <[email protected]> 於 2019年5月9日 週四 上午9:32寫道:

Quoted 19 lines

Hi Rick,

Quoted 6 lines · Andes

From: Rick Chen <[email protected]>

This patch will fix Travis failure item as below:
https://travis-ci.org/rickchen36/u-boot-riscv/jobs/529605196

Quoted 8 lines

Check for configs without MAINTAINERS entry

Cc Greentime Hu <[email protected]>
---
 board/AndesTech/ax25-ae350/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
Quoted 4 lines

Please squash this one into "[PATCH v5 2/6] riscv: configs: Support AE350 SMP booting from flash flow", as they are from the same patch series, and not applied yet as of today.

OK. I will squash into [PATCH v5 2/6].

After that shall I prepare v6 for review, or I can just apply into u-boot-riscv tree ?

Thanks
Rick

Quoted 2 lines

Regards,
Bin

#9 lore raw

PATCH v5 6/6 riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS

Hi Rick,

Quoted 28 lines · Rick Chen

Hi Bin

Bin Meng <[email protected]> 於 2019年5月9日 週四 上午9:32寫道:

Quoted 19 lines

Hi Rick,

Quoted 6 lines · Andes

From: Rick Chen <[email protected]>

This patch will fix Travis failure item as below:
https://travis-ci.org/rickchen36/u-boot-riscv/jobs/529605196

Quoted 8 lines

Check for configs without MAINTAINERS entry

Cc Greentime Hu <[email protected]>
---
 board/AndesTech/ax25-ae350/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
Quoted 4 lines

Please squash this one into "[PATCH v5 2/6] riscv: configs: Support AE350 SMP booting from flash flow", as they are from the same patch series, and not applied yet as of today.

Quoted 4 lines

OK. I will squash into [PATCH v5 2/6].

After that shall I prepare v6 for review, or I can just apply into u-boot-riscv tree ?

I think you can just do the squash and apply into u-boot-riscv tree to save some traffic :).

Regards,
Bin

#10 lore raw

PATCH v5 6/6 riscv: configs: add ae350_rv[32|64]_xip_defconfig to MAINTAINERS

Hi Bin

Bin Meng <[email protected]> 於 2019年5月9日 週四 上午10:21寫道:

Quoted 32 lines

Hi Rick,

Quoted 28 lines · Rick Chen

Hi Bin

Bin Meng <[email protected]> 於 2019年5月9日 週四 上午9:32寫道:

Quoted 23 lines

Hi Rick,

Quoted 6 lines · Andes

From: Rick Chen <[email protected]>

This patch will fix Travis failure item as below:
https://travis-ci.org/rickchen36/u-boot-riscv/jobs/529605196

Quoted 8 lines

Check for configs without MAINTAINERS entry

Cc Greentime Hu <[email protected]>
---
 board/AndesTech/ax25-ae350/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

Please squash this one into "[PATCH v5 2/6] riscv: configs: Support AE350 SMP booting from flash flow", as they are from the same patch series, and not applied yet as of today.

Quoted 8 lines
Quoted 4 lines

OK. I will squash into [PATCH v5 2/6].

After that shall I prepare v6 for review, or I can just apply into u-boot-riscv tree ?

I think you can just do the squash and apply into u-boot-riscv tree to save some traffic :).

OK

Thanks
Rick

Quoted 2 lines

Regards,
Bin