Skip to contentSkip to conversation

riscv: Support booting SiFive Unmatched from SPI flash.

PATCH Superseded Thomas Skibo 3 participants 6 messages Nov 24, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover riscv: Support booting SiFive Unmatched from SPI flash.

This patch set adds support for booting the SiFive Unmatched board from SPI flash memory and saving the environment to flash.

Thomas Skibo (2):
riscv: Support booting SiFive Unmatched from SPI.
riscv: Enable SPI flash env for SiFive Unmatched.

 arch/riscv/cpu/fu740/Kconfig                  | 13 +++++++++
 .../dts/hifive-unmatched-a00-u-boot.dtsi      | 11 +++++++
 board/sifive/unmatched/Kconfig                |  1 +
 board/sifive/unmatched/spl.c                  |  3 ++
 configs/sifive_unmatched_defconfig            |  6 ++++
 doc/board/sifive/unmatched.rst                | 29 +++++++++++++++++++
 6 files changed, 63 insertions(+)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 riscv: Support booting SiFive Unmatched from SPI.

Configure SPI flash devices into SPL. Add SPI boot option to spl.c. Document how to format flash for booting.

---
 .../dts/hifive-unmatched-a00-u-boot.dtsi      | 11 +++++++
 board/sifive/unmatched/spl.c                  |  3 ++
 configs/sifive_unmatched_defconfig            |  6 ++++
 doc/board/sifive/unmatched.rst                | 29 +++++++++++++++++++
 4 files changed, 49 insertions(+)
arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi +11 -0
index c5475aa149..1ee8ab1868 100644
@@ -16,6 +16,10 @@
 		u-boot,dm-spl;
 	};
 
+	config {
+		u-boot,spl-payload-offset = <0x105000>; /* loader2 @1044KB */
+	};
+
 	hfclk {
 		u-boot,dm-spl;
 	};
@@ -30,6 +34,13 @@
 	clocks = <&rtcclk>;
 };
 
+&qspi0 {
+	u-boot,dm-spl;
+	flash@0 {
+		u-boot,dm-spl;
+	};
+};
+
 &spi0 {
 	mmc@0 {
 		u-boot,dm-spl;
board/sifive/unmatched/spl.c +3 -0
index d5663274cd..7c0beedc08 100644
@@ -22,6 +22,7 @@
 #define GEM_PHY_RESET	SIFIVE_GENERIC_GPIO_NR(0, 12)
 
 #define MODE_SELECT_REG		0x1000
+#define MODE_SELECT_SPI		0x6
 #define MODE_SELECT_SD		0xb
 #define MODE_SELECT_MASK	GENMASK(3, 0)
 
@@ -123,6 +124,8 @@ u32 spl_boot_device(void)
 	u32 boot_device = mode_select & MODE_SELECT_MASK;
 
 	switch (boot_device) {
+	case MODE_SELECT_SPI:
+		return BOOT_DEVICE_SPI;
 	case MODE_SELECT_SD:
 		return BOOT_DEVICE_MMC1;
 	default:
configs/sifive_unmatched_defconfig +6 -0
index 9cc18b029c..d400ed0b23 100644
@@ -8,6 +8,7 @@ CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="hifive-unmatched-a00"
 CONFIG_SPL_MMC=y
 CONFIG_SPL=y
+CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_AHCI=y
 CONFIG_TARGET_SIFIVE_UNMATCHED=y
@@ -23,17 +24,22 @@ CONFIG_DISPLAY_BOARDINFO=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_ID_EEPROM=y
 CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_DM_RESET=y
+CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_EEPROM=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_PWM=y
 CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
+CONFIG_USE_ENV_SPI_BUS=y
+CONFIG_ENV_SPI_BUS=1
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_SCSI_AHCI=y
 CONFIG_AHCI_PCI=y
 CONFIG_SPL_CLK=y
+CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SYS_I2C_EEPROM_ADDR=0x54
 CONFIG_E1000=y
 CONFIG_NVME=y
doc/board/sifive/unmatched.rst +29 -0
index 6b024f07f6..387785d76b 100644
@@ -534,3 +534,32 @@ Sample boot log from HiFive Unmatched board
 	OpenEmbedded nodistro.0 unmatched ttySIF0
 
 	unmatched login:
+
+
+Booting from SPI
+----------------
+
+Use Building steps from "Booting from uSD using U-Boot SPL" section.
+
+Partition the SPI in Linux via mtdblock.
+
+.. code-block:: none
+
+	sgdisk --clear -a 1 \
+	    --new=1:40:2087     --change-name=1:spl   --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
+	    --new=2:2088:10279  --change-name=2:uboot --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
+	    --new=3:10280:10535 --change-name=3:env   --typecode=3:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \
+	    /dev/mtdblock0
+
+Write U-boot SPL and U-boot to their partitions.
+
+.. code-block:: none
+
+	dd if=u-boot-spl.bin of=/dev/mtdblock0 bs=4096 seek=5 conv=sync
+	dd if=u-boot.itb  of=/dev/mtdblock0 bs=4096 seek=261 conv=sync
+
+Power off the board.
+
+Change DIP switches MSEL[3:0] to 0110.
+
+Power up the board.
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/2] riscv: Support booting SiFive Unmatched from SPI.

Quoted 109 lines · Thomas Skibo

Configure SPI flash devices into SPL. Add SPI boot option to spl.c. Document how to format flash for booting.

---
  .../dts/hifive-unmatched-a00-u-boot.dtsi      | 11 +++++++
  board/sifive/unmatched/spl.c                  |  3 ++
  configs/sifive_unmatched_defconfig            |  6 ++++
  doc/board/sifive/unmatched.rst                | 29 +++++++++++++++++++
  4 files changed, 49 insertions(+)
arch/riscv/dts/hifive-unmatched-a00-u-boot.dtsi +11 -0
index c5475aa149..1ee8ab1868 100644
@@ -16,6 +16,10 @@
  		u-boot,dm-spl;
  	};
 
+	config {
+		u-boot,spl-payload-offset = <0x105000>; /* loader2 @1044KB */
+	};
+
  	hfclk {
  		u-boot,dm-spl;
  	};
@@ -30,6 +34,13 @@
  	clocks = <&rtcclk>;
  };
 
+&qspi0 {
+	u-boot,dm-spl;
+	flash@0 {
+		u-boot,dm-spl;
+	};
+};
+
  &spi0 {
  	mmc@0 {
  		u-boot,dm-spl;
board/sifive/unmatched/spl.c +3 -0
index d5663274cd..7c0beedc08 100644
@@ -22,6 +22,7 @@
  #define GEM_PHY_RESET	SIFIVE_GENERIC_GPIO_NR(0, 12)
 
  #define MODE_SELECT_REG		0x1000
+#define MODE_SELECT_SPI		0x6
  #define MODE_SELECT_SD		0xb
  #define MODE_SELECT_MASK	GENMASK(3, 0)
 
@@ -123,6 +124,8 @@ u32 spl_boot_device(void)
  	u32 boot_device = mode_select & MODE_SELECT_MASK;
 
  	switch (boot_device) {
+	case MODE_SELECT_SPI:
+		return BOOT_DEVICE_SPI;
  	case MODE_SELECT_SD:
  		return BOOT_DEVICE_MMC1;
  	default:
configs/sifive_unmatched_defconfig +6 -0
index 9cc18b029c..d400ed0b23 100644
@@ -8,6 +8,7 @@ CONFIG_SPL_DM_SPI=y
  CONFIG_DEFAULT_DEVICE_TREE="hifive-unmatched-a00"
  CONFIG_SPL_MMC=y
  CONFIG_SPL=y
+CONFIG_SPL_SPI_FLASH_SUPPORT=y
  CONFIG_SPL_SPI=y
  CONFIG_AHCI=y
  CONFIG_TARGET_SIFIVE_UNMATCHED=y
@@ -23,17 +24,22 @@ CONFIG_DISPLAY_BOARDINFO=y
  CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_ID_EEPROM=y
  CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL_DM_SPI_FLASH=y
  CONFIG_SPL_DM_RESET=y
+CONFIG_SPL_SPI_LOAD=y
  CONFIG_CMD_EEPROM=y
  CONFIG_CMD_MEMINFO=y
  CONFIG_CMD_PWM=y
  CONFIG_CMD_GPT_RENAME=y
  CONFIG_CMD_PCI=y
  CONFIG_CMD_USB=y
+CONFIG_USE_ENV_SPI_BUS=y
+CONFIG_ENV_SPI_BUS=1
  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
  CONFIG_SCSI_AHCI=y
  CONFIG_AHCI_PCI=y
  CONFIG_SPL_CLK=y
+CONFIG_SPI_FLASH_ISSI=y
  CONFIG_SYS_I2C_EEPROM_ADDR=0x54
  CONFIG_E1000=y
  CONFIG_NVME=y
doc/board/sifive/unmatched.rst +5 -0
index 6b024f07f6..387785d76b 100644
@@ -534,3 +534,32 @@ Sample boot log from HiFive Unmatched board
  	OpenEmbedded nodistro.0 unmatched ttySIF0
 
  	unmatched login:
+
+
+Booting from SPI
+----------------
+

doc/board/sifive/unmatched.rst Sample boot log from HiFive Unmatched board · line 551

Quoted 10 lines
doc/board/sifive/unmatched.rst +10 -0
+Use Building steps from "Booting from uSD using U-Boot SPL" section.
+
+Partition the SPI in Linux via mtdblock.
+
+.. code-block:: none
+
+	sgdisk --clear -a 1 \
+	    --new=1:40:2087     --change-name=1:spl   --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
+	    --new=2:2088:10279  --change-name=2:uboot --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
+	    --new=3:10280:10535 --change-name=3:env   --typecode=3:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \

nit: Please use hexcodes as printed with sgdisk -L. And also document what the type is. Documentation is for us humans after all :)

--Sean

Quoted 15 lines
doc/board/sifive/unmatched.rst +14 -0
+	    /dev/mtdblock0
+
+Write U-boot SPL and U-boot to their partitions.
+
+.. code-block:: none
+
+	dd if=u-boot-spl.bin of=/dev/mtdblock0 bs=4096 seek=5 conv=sync
+	dd if=u-boot.itb  of=/dev/mtdblock0 bs=4096 seek=261 conv=sync
+
+Power off the board.
+
+Change DIP switches MSEL[3:0] to 0110.
+
+Power up the board.
#3 lore raw

Re: [PATCH v2 1/2] riscv: Support booting SiFive Unmatched from SPI.

Quoted 23 lines · Sean Anderson
Quoted 8 lines · Thomas Skibo
doc/board/sifive/unmatched.rst +8 -0
+
+
+Booting from SPI
+----------------
+
+Use Building steps from "Booting from uSD using U-Boot SPL" section.
+
+Partition the SPI in Linux via mtdblock.

doc/board/sifive/unmatched.rst Sample boot log from HiFive Unmatched board

Quoted 10 lines
doc/board/sifive/unmatched.rst +7 -3
+
+.. code-block:: none
+
+    sgdisk --clear -a 1 \
+        --new=1:40:2087     --change-name=1:spl   
--typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
+        --new=2:2088:10279  --change-name=2:uboot 
--typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
+        --new=3:10280:10535 --change-name=3:env   
--typecode=3:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \

nit: Please use hexcodes as printed with sgdisk -L. And also document what the type is. Documentation is for us humans after all :)

Quoted 2 lines

--Sean

The first two partitions' typecodes are unique to the SiFive chip so they don't have a short hexcode. The third partition, storage for the environment, is hexcode 8300 which is a Linux filesystem. I wonder if there is better partition type for the environment.

I can change the typecode for the third partition and add a note about what the other partitions are.

-Thomas

#4 lore raw

Re: [PATCH v2 1/2] riscv: Support booting SiFive Unmatched from SPI.

Quoted 25 lines · Thomas Skibo
Quoted 23 lines · Sean Anderson
Quoted 8 lines · Thomas Skibo
doc/board/sifive/unmatched.rst +8 -0
+
+
+Booting from SPI
+----------------
+
+Use Building steps from "Booting from uSD using U-Boot SPL" section.
+
+Partition the SPI in Linux via mtdblock.

doc/board/sifive/unmatched.rst Sample boot log from HiFive Unmatched board

Quoted 10 lines
doc/board/sifive/unmatched.rst +7 -3
+
+.. code-block:: none
+
+    sgdisk --clear -a 1 \
+        --new=1:40:2087     --change-name=1:spl
--typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
+        --new=2:2088:10279  --change-name=2:uboot
--typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
+        --new=3:10280:10535 --change-name=3:env
--typecode=3:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \

nit: Please use hexcodes as printed with sgdisk -L. And also document what the type is. Documentation is for us humans after all :)

Quoted 5 lines
Quoted 2 lines

--Sean

The first two partitions' typecodes are unique to the SiFive chip so they don't have a short hexcode. The third partition, storage for the

That's correct. The 1st two are SiFive boards specific. From util-linux:

/* HiFive bootloaders */ DEF_GUID("5B193300-FC78-40CD-8002-E86C45580B47", N_("HiFive FSBL")), DEF_GUID("2E54B353-1271-4842-806F-E436D6AF6985", N_("HiFive BBL")),

Quoted 2 lines

environment, is hexcode 8300 which is a Linux filesystem. I wonder if there is better partition type for the environment.

Shouldn't this be?

"u-boot-env" = PARTITION_U_BOOT_ENVIRONMENT

                   (3DE21764-95BD-54BD-A5C3-4ABE786F38A8)

Taken from doc/README.gpt

See:
https://github.com/u-boot/u-boot/commit/c0364ce1c6957c5295e933b95802e6966e00b08f

david

Quoted 6 lines

I can change the typecode for the third partition and add a note about what the other partitions are.

-Thomas

#5 lore raw

PATCH v2 2/2 riscv: Enable SPI flash env for SiFive Unmatched.

In reply to Thomas Skibo

Enable saving environment to SPI flash memory on SiFive Unmatched.

---
 arch/riscv/cpu/fu740/Kconfig   | 13 +++++++++++++
 board/sifive/unmatched/Kconfig |  1 +
 2 files changed, 14 insertions(+)
arch/riscv/cpu/fu740/Kconfig +13 -0
index 049a0a0584..3e0c1fddc8 100644
@@ -40,3 +40,16 @@ config SIFIVE_FU740
 	imply DM_I2C
 	imply SYS_I2C_OCORES
 	imply SPL_I2C
+
+if ENV_IS_IN_SPI_FLASH
+
+config ENV_OFFSET
+	default 0x505000
+
+config ENV_SIZE
+	default 0x20000
+
+config ENV_SECT_SIZE
+	default 0x10000
+
+endif # ENV_IS_IN_SPI_FLASH
board/sifive/unmatched/Kconfig +1 -0
index fb2c1fbb58..fe213fd504 100644
@@ -26,6 +26,7 @@ config SPL_OPENSBI_LOAD_ADDR
 config BOARD_SPECIFIC_OPTIONS # dummy
 	def_bool y
 	select SIFIVE_FU740
+	select ENV_IS_IN_SPI_FLASH
 	select SUPPORT_SPL
 	select RESET_SIFIVE
 	select BINMAN
Signature · 1 line
2.25.1