diff mbox series

[1/5] sifive: fu540: Add Booting from SPI

Message ID 20200420140514.25847-2-jagan@amarulasolutions.com
State New
Headers show
Series riscv: sifive/fu540: Booting from SPI | expand

Commit Message

Jagan Teki April 20, 2020, 2:05 p.m. UTC
U-Boot SPL 2020.04-rc4-g0b8ed9b8b6 (Apr 20 2020 - 18:31:50 +0530)
Trying to boot from MMC1

U-Boot 2020.04-rc4-g0b8ed9b8b6 (Apr 20 2020 - 18:31:50 +0530)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
MMC:   spi at 10050000:mmc at 0: 0
Loading Environment from SPI Flash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
*** Warning - bad CRC, using default environment

In:    serial at 10010000
Out:   serial at 10010000
Err:   serial at 10010000
Net:   eth0: ethernet at 10090000
Hit any key to stop autoboot:  0

Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
 .../dts/hifive-unleashed-a00-u-boot.dtsi      | 12 ++++++
 board/sifive/fu540/fu540.c                    |  3 ++
 configs/sifive_fu540_spi_defconfig            | 26 +++++++++++
 doc/board/sifive/fu540.rst                    | 43 +++++++++++++++++++
 4 files changed, 84 insertions(+)
 create mode 100644 configs/sifive_fu540_spi_defconfig

Comments

Bin Meng April 20, 2020, 2:24 p.m. UTC | #1
Hi Jagan,

On Mon, Apr 20, 2020 at 10:05 PM Jagan Teki <jagan at amarulasolutions.com> wrote:
>
> U-Boot SPL 2020.04-rc4-g0b8ed9b8b6 (Apr 20 2020 - 18:31:50 +0530)
> Trying to boot from MMC1

This log seems to be SD boot, not SPI boot

>
> U-Boot 2020.04-rc4-g0b8ed9b8b6 (Apr 20 2020 - 18:31:50 +0530)
>
> CPU:   rv64imafdc
> Model: SiFive HiFive Unleashed A00
> DRAM:  8 GiB
> MMC:   spi at 10050000:mmc at 0: 0
> Loading Environment from SPI Flash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
> *** Warning - bad CRC, using default environment
>
> In:    serial at 10010000
> Out:   serial at 10010000
> Err:   serial at 10010000
> Net:   eth0: ethernet at 10090000
> Hit any key to stop autoboot:  0
>
> Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
> ---
>  .../dts/hifive-unleashed-a00-u-boot.dtsi      | 12 ++++++
>  board/sifive/fu540/fu540.c                    |  3 ++
>  configs/sifive_fu540_spi_defconfig            | 26 +++++++++++
>  doc/board/sifive/fu540.rst                    | 43 +++++++++++++++++++
>  4 files changed, 84 insertions(+)
>  create mode 100644 configs/sifive_fu540_spi_defconfig
>
> diff --git a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> index 0162f59f60..f5a208398f 100644
> --- a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> +++ b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> @@ -12,6 +12,10 @@
>                 spi2 = &qspi2;
>         };
>
> +       config {
> +               u-boot,spl-payload-offset = <0x105000>; /* @ 1044KB */

Can we add some comments about how this is chosen?

> +       };
> +
>         hfclk {
>                 u-boot,dm-spl;
>         };
> @@ -21,6 +25,14 @@
>         };
>  };
>
> +&qspi0 {
> +       u-boot,dm-spl;
> +
> +       flash at 0 {
> +               u-boot,dm-spl;
> +       };
> +};
> +
>  &qspi2 {
>         mmc at 0 {
>                 u-boot,dm-spl;
> diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
> index 131fee8898..84dd20e29d 100644
> --- a/board/sifive/fu540/fu540.c
> +++ b/board/sifive/fu540/fu540.c
> @@ -129,6 +129,9 @@ void board_boot_order(u32 *spl_boot_list)
>         u32 boot_devices[] = {
>  #ifdef CONFIG_SPL_MMC_SUPPORT
>                 BOOT_DEVICE_MMC1,
> +#endif
> +#ifdef CONFIG_SPL_SPI_LOAD
> +               BOOT_DEVICE_SPI,
>  #endif
>         };
>
> diff --git a/configs/sifive_fu540_spi_defconfig b/configs/sifive_fu540_spi_defconfig
> new file mode 100644
> index 0000000000..24d0a9338e
> --- /dev/null
> +++ b/configs/sifive_fu540_spi_defconfig
> @@ -0,0 +1,26 @@
> +CONFIG_RISCV=y
> +CONFIG_ENV_SIZE=0x20000
> +CONFIG_NR_DRAM_BANKS=1
> +CONFIG_TARGET_SIFIVE_FU540=y
> +CONFIG_ARCH_RV64I=y
> +CONFIG_RISCV_SMODE=y
> +CONFIG_DISTRO_DEFAULTS=y
> +CONFIG_FIT=y
> +CONFIG_MISC_INIT_R=y
> +CONFIG_DISPLAY_CPUINFO=y
> +CONFIG_DISPLAY_BOARDINFO=y
> +CONFIG_DEFAULT_DEVICE_TREE="hifive-unleashed-a00"
> +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> +CONFIG_DM_MTD=y
> +CONFIG_SPL_SEPARATE_BSS=y
> +CONFIG_SPL=y
> +CONFIG_SPL_DM_SEQ_ALIAS=y
> +CONFIG_SPL_DM_SPI=y
> +CONFIG_SPL_SPI_FLASH_SUPPORT=y
> +CONFIG_SPL_SPI_SUPPORT=y
> +CONFIG_SPL_SPI_LOAD=y
> +CONFIG_SPL_YMODEM_SUPPORT=y
> +CONFIG_SPL_CLK=y
> +CONFIG_SPL_GPIO_SUPPORT=y
> +CONFIG_SYS_MALLOC_F_LEN=0x3000
> +CONFIG_SIFIVE_FU540_DDR=y

These config options should be ordered by "make savedefconfg"

> diff --git a/doc/board/sifive/fu540.rst b/doc/board/sifive/fu540.rst
> index 691ef232e2..14323e0985 100644
> --- a/doc/board/sifive/fu540.rst
> +++ b/doc/board/sifive/fu540.rst
> @@ -391,3 +391,46 @@ Program the SD card
>  Change DIP switches MSEL[3:0] are set to 1011
>
>  Insert the SD card and power up the board.
> +
> +Booting from SPI
> +----------------
> +
> +Use steps from "Building" section for building the U-Boot
> +
> +.. code-block:: none
> +
> +   export ARCH=riscv
> +   export CROSS_COMPILE=<riscv64 toolchain prefix>
> +   make sifive_fu540_spi_defconfig
> +   make
> +
> +Partition the SPI in Linux via mtdblock. (Require to boot
> +the board in SD boot mode by enabling MTD block in Linux)
> +
> +.. code-block:: none
> +
> +  # sgdisk --clear \
> +  > --set-alignment=2 \
> +  > --new=1:40:2087 --change-name=1:loader1 --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
> +  > --new=2:2088:10279 --change-name=2:loader2 --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
> +  > --new=3:10536:65494 --change-name=3:rootfs --typecode=3:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \
> +  > /dev/mtdblock0
> +
> +Program the SPI (Require to boot the board in SD boot mode)
> +on U-Boot proper.
> +
> +.. code-block:: none
> +
> +  sf erase 0x5000 0x100000
> +  tftpboot $kernel_addr_r u-boot-spl.bin
> +  sf write $kernel_addr_r 0x5000 $filesize
> +
> +  sf erase 0x105000 0x100000
> +  tftpboot $kernel_addr_r u-boot.itb
> +  sf write $kernel_addr_r 0x105000 $filesize
> +
> +Power off the board
> +
> +Change DIP switches MSEL[3:0] are set to 0110
> +
> +Power up the board.
> --

Looks good otherwise:
Reviewed-by: Bin Meng <bmeng.cn at gmail.com>

Regards,
Bin
Jagan Teki April 20, 2020, 2:28 p.m. UTC | #2
On Mon, Apr 20, 2020 at 7:54 PM Bin Meng <bmeng.cn at gmail.com> wrote:
>
> Hi Jagan,
>
> On Mon, Apr 20, 2020 at 10:05 PM Jagan Teki <jagan at amarulasolutions.com> wrote:
> >
> > U-Boot SPL 2020.04-rc4-g0b8ed9b8b6 (Apr 20 2020 - 18:31:50 +0530)
> > Trying to boot from MMC1
>
> This log seems to be SD boot, not SPI boot

Wrong log added, my bad.

>
> >
> > U-Boot 2020.04-rc4-g0b8ed9b8b6 (Apr 20 2020 - 18:31:50 +0530)
> >
> > CPU:   rv64imafdc
> > Model: SiFive HiFive Unleashed A00
> > DRAM:  8 GiB
> > MMC:   spi at 10050000:mmc at 0: 0
> > Loading Environment from SPI Flash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
> > *** Warning - bad CRC, using default environment
> >
> > In:    serial at 10010000
> > Out:   serial at 10010000
> > Err:   serial at 10010000
> > Net:   eth0: ethernet at 10090000
> > Hit any key to stop autoboot:  0
> >
> > Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
> > ---
> >  .../dts/hifive-unleashed-a00-u-boot.dtsi      | 12 ++++++
> >  board/sifive/fu540/fu540.c                    |  3 ++
> >  configs/sifive_fu540_spi_defconfig            | 26 +++++++++++
> >  doc/board/sifive/fu540.rst                    | 43 +++++++++++++++++++
> >  4 files changed, 84 insertions(+)
> >  create mode 100644 configs/sifive_fu540_spi_defconfig
> >
> > diff --git a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > index 0162f59f60..f5a208398f 100644
> > --- a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > +++ b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
> > @@ -12,6 +12,10 @@
> >                 spi2 = &qspi2;
> >         };
> >
> > +       config {
> > +               u-boot,spl-payload-offset = <0x105000>; /* @ 1044KB */
>
> Can we add some comments about how this is chosen?

Yes on the doc file of loader2 sector start. Yes will make it more
verbose if it isn't sufficient.

>
> > +       };
> > +
> >         hfclk {
> >                 u-boot,dm-spl;
> >         };
> > @@ -21,6 +25,14 @@
> >         };
> >  };
> >
> > +&qspi0 {
> > +       u-boot,dm-spl;
> > +
> > +       flash at 0 {
> > +               u-boot,dm-spl;
> > +       };
> > +};
> > +
> >  &qspi2 {
> >         mmc at 0 {
> >                 u-boot,dm-spl;
> > diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
> > index 131fee8898..84dd20e29d 100644
> > --- a/board/sifive/fu540/fu540.c
> > +++ b/board/sifive/fu540/fu540.c
> > @@ -129,6 +129,9 @@ void board_boot_order(u32 *spl_boot_list)
> >         u32 boot_devices[] = {
> >  #ifdef CONFIG_SPL_MMC_SUPPORT
> >                 BOOT_DEVICE_MMC1,
> > +#endif
> > +#ifdef CONFIG_SPL_SPI_LOAD
> > +               BOOT_DEVICE_SPI,
> >  #endif
> >         };
> >
> > diff --git a/configs/sifive_fu540_spi_defconfig b/configs/sifive_fu540_spi_defconfig
> > new file mode 100644
> > index 0000000000..24d0a9338e
> > --- /dev/null
> > +++ b/configs/sifive_fu540_spi_defconfig
> > @@ -0,0 +1,26 @@
> > +CONFIG_RISCV=y
> > +CONFIG_ENV_SIZE=0x20000
> > +CONFIG_NR_DRAM_BANKS=1
> > +CONFIG_TARGET_SIFIVE_FU540=y
> > +CONFIG_ARCH_RV64I=y
> > +CONFIG_RISCV_SMODE=y
> > +CONFIG_DISTRO_DEFAULTS=y
> > +CONFIG_FIT=y
> > +CONFIG_MISC_INIT_R=y
> > +CONFIG_DISPLAY_CPUINFO=y
> > +CONFIG_DISPLAY_BOARDINFO=y
> > +CONFIG_DEFAULT_DEVICE_TREE="hifive-unleashed-a00"
> > +CONFIG_SYS_RELOC_GD_ENV_ADDR=y
> > +CONFIG_DM_MTD=y
> > +CONFIG_SPL_SEPARATE_BSS=y
> > +CONFIG_SPL=y
> > +CONFIG_SPL_DM_SEQ_ALIAS=y
> > +CONFIG_SPL_DM_SPI=y
> > +CONFIG_SPL_SPI_FLASH_SUPPORT=y
> > +CONFIG_SPL_SPI_SUPPORT=y
> > +CONFIG_SPL_SPI_LOAD=y
> > +CONFIG_SPL_YMODEM_SUPPORT=y
> > +CONFIG_SPL_CLK=y
> > +CONFIG_SPL_GPIO_SUPPORT=y
> > +CONFIG_SYS_MALLOC_F_LEN=0x3000
> > +CONFIG_SIFIVE_FU540_DDR=y
>
> These config options should be ordered by "make savedefconfg"

Yes, I just sent it as the first series. Hoping to reuse existing
defconfig if we have any way to detect the boot mode at runtime like
reading MSEL.

Jagan.
diff mbox series

Patch

diff --git a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
index 0162f59f60..f5a208398f 100644
--- a/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
+++ b/arch/riscv/dts/hifive-unleashed-a00-u-boot.dtsi
@@ -12,6 +12,10 @@ 
 		spi2 = &qspi2;
 	};
 
+	config {
+		u-boot,spl-payload-offset = <0x105000>; /* @ 1044KB */
+	};
+
 	hfclk {
 		u-boot,dm-spl;
 	};
@@ -21,6 +25,14 @@ 
 	};
 };
 
+&qspi0 {
+	u-boot,dm-spl;
+
+	flash at 0 {
+		u-boot,dm-spl;
+	};
+};
+
 &qspi2 {
 	mmc at 0 {
 		u-boot,dm-spl;
diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c
index 131fee8898..84dd20e29d 100644
--- a/board/sifive/fu540/fu540.c
+++ b/board/sifive/fu540/fu540.c
@@ -129,6 +129,9 @@  void board_boot_order(u32 *spl_boot_list)
 	u32 boot_devices[] = {
 #ifdef CONFIG_SPL_MMC_SUPPORT
 		BOOT_DEVICE_MMC1,
+#endif
+#ifdef CONFIG_SPL_SPI_LOAD
+		BOOT_DEVICE_SPI,
 #endif
 	};
 
diff --git a/configs/sifive_fu540_spi_defconfig b/configs/sifive_fu540_spi_defconfig
new file mode 100644
index 0000000000..24d0a9338e
--- /dev/null
+++ b/configs/sifive_fu540_spi_defconfig
@@ -0,0 +1,26 @@ 
+CONFIG_RISCV=y
+CONFIG_ENV_SIZE=0x20000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_TARGET_SIFIVE_FU540=y
+CONFIG_ARCH_RV64I=y
+CONFIG_RISCV_SMODE=y
+CONFIG_DISTRO_DEFAULTS=y
+CONFIG_FIT=y
+CONFIG_MISC_INIT_R=y
+CONFIG_DISPLAY_CPUINFO=y
+CONFIG_DISPLAY_BOARDINFO=y
+CONFIG_DEFAULT_DEVICE_TREE="hifive-unleashed-a00"
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_DM_MTD=y
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL=y
+CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_SPL_DM_SPI=y
+CONFIG_SPL_SPI_FLASH_SUPPORT=y
+CONFIG_SPL_SPI_SUPPORT=y
+CONFIG_SPL_SPI_LOAD=y
+CONFIG_SPL_YMODEM_SUPPORT=y
+CONFIG_SPL_CLK=y
+CONFIG_SPL_GPIO_SUPPORT=y
+CONFIG_SYS_MALLOC_F_LEN=0x3000
+CONFIG_SIFIVE_FU540_DDR=y
diff --git a/doc/board/sifive/fu540.rst b/doc/board/sifive/fu540.rst
index 691ef232e2..14323e0985 100644
--- a/doc/board/sifive/fu540.rst
+++ b/doc/board/sifive/fu540.rst
@@ -391,3 +391,46 @@  Program the SD card
 Change DIP switches MSEL[3:0] are set to 1011
 
 Insert the SD card and power up the board.
+
+Booting from SPI
+----------------
+
+Use steps from "Building" section for building the U-Boot
+
+.. code-block:: none
+
+   export ARCH=riscv
+   export CROSS_COMPILE=<riscv64 toolchain prefix>
+   make sifive_fu540_spi_defconfig
+   make
+
+Partition the SPI in Linux via mtdblock. (Require to boot
+the board in SD boot mode by enabling MTD block in Linux)
+
+.. code-block:: none
+
+  # sgdisk --clear \
+  > --set-alignment=2 \
+  > --new=1:40:2087 --change-name=1:loader1 --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
+  > --new=2:2088:10279 --change-name=2:loader2 --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
+  > --new=3:10536:65494 --change-name=3:rootfs --typecode=3:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \
+  > /dev/mtdblock0
+
+Program the SPI (Require to boot the board in SD boot mode)
+on U-Boot proper.
+
+.. code-block:: none
+
+  sf erase 0x5000 0x100000
+  tftpboot $kernel_addr_r u-boot-spl.bin
+  sf write $kernel_addr_r 0x5000 $filesize
+
+  sf erase 0x105000 0x100000
+  tftpboot $kernel_addr_r u-boot.itb
+  sf write $kernel_addr_r 0x105000 $filesize
+
+Power off the board
+
+Change DIP switches MSEL[3:0] are set to 0110
+
+Power up the board.