diff mbox series

[RFC,5/5] doc: describe Milk-V Mars board

Message ID 20240303130122.29983-6-heinrich.schuchardt@canonical.com
State RFC
Delegated to: Andes
Headers show
Series riscv: add support for Milk-V Mars board | expand

Commit Message

Heinrich Schuchardt March 3, 2024, 1:01 p.m. UTC
Add instructions to build U-Boot for the Milk-V Mars board

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 doc/board/starfive/index.rst       |  1 +
 doc/board/starfive/milk-v_mars.rst | 93 ++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)
 create mode 100644 doc/board/starfive/milk-v_mars.rst

Comments

E Shattow March 7, 2024, 11:20 p.m. UTC | #1
On Sun, Mar 3, 2024 at 5:02 AM Heinrich Schuchardt <
heinrich.schuchardt@canonical.com> wrote:
...

> +The board provides the DIP switches MSEL[1:0] to select the boot device
> out of
> +SPI flash, eMMC, SD-card, UART. To select booting from SD-card set the DIP
> +switches MSEL[1:0] to 10.
>

This does not match the [Milk-V Mars vendor documentation](
https://milkv.io/docs/mars/getting-started/bootloader). Maybe you have a
different board revision?
Heinrich Schuchardt March 8, 2024, 2:37 a.m. UTC | #2
On 3/8/24 00:20, E Shattow wrote:
> 
> On Sun, Mar 3, 2024 at 5:02 AM Heinrich Schuchardt 
> <heinrich.schuchardt@canonical.com 
> <mailto:heinrich.schuchardt@canonical.com>> wrote:
> ...
> 
>     +The board provides the DIP switches MSEL[1:0] to select the boot
>     device out of
>     +SPI flash, eMMC, SD-card, UART. To select booting from SD-card set
>     the DIP
>     +switches MSEL[1:0] to 10.
> 
> 
> This does not match the [Milk-V Mars vendor 
> documentation](https://milkv.io/docs/mars/getting-started/bootloader 
> <https://milkv.io/docs/mars/getting-started/bootloader>). Maybe you have 
> a different board revision?

Thank you for reviewing.

My board revision is V1.21 according to the silk screen.

The Milk-V Mars has DIP switches for the boot selection as shown in
https://gist.github.com/xypron/e28f95b1ed6911aeb9699ba63ae1a885

If you look at the photo 
https://milkv.io/assets/images/mars-icon-04-e8814f18158a0e9d4387f4fa330693f1.webp 
in the https://milkv.io/mars page, it also shows DIP switches (in the 
SPI-Flash position) on a rev 1.2 board.

Did you see a board without DIP switches being sold?

The silk screen markings on the board and the switch don't match.
The same confusion exists on the VisionFive2.

So maybe I should better write in a table:

SPI-Flash:
GPIO0=L
GPIO1=L

SD-Card:
GPIO0=H
GPIO1=L

eMMC:
GPIO0=L
GPIO1=H

UART:
GPIO0=H
GPIO1=H

Best regards

Heinrich
E Shattow March 8, 2024, 9:48 p.m. UTC | #3
Yes this reference to GPIO high/low states is clearer to understand. Have
you tested the DIP switch functionality to confirm?; It is not shown in the
MilkV documentation or outdated schematics and I don't have a Mars to test.
I did find function descriptions from what is likely cut-and-paste of
VisionFive2 board reference.

Ref:
https://github.com/milkv-mars/mars-files/blob/main/Mars_hardware_schematics/Mars_V1.11_20230821.pdf
Sheet 7 of 22 JH7110 GPIOs
There is a schematic for SW2 (bootloader button?) that lists an inset table:
* - GPIO_1
  - GPIO_0
  - Boot
* - 0
  - 0
  - Flash
* - 0
  - 1
  - SD
* - 1
  - 0
  - eMMC
* - 1
  - 1
  - UART

That circuit on SW2 appears to pull high both RGPIO_1 and RGPIO_0 with
transistors. Again, no DIP switch as this is an earlier revision.

Ref:
https://doc-en.rvspace.org/VisionFive2/Developer_Guide/JH7110_Boot_UG.pdf
page 9 table 1-4:
RGPIO1=0x0 RGPIO0=0x0 Boot Source: Quad SPI NOR flash memory, Read SPL from
Sector 0.
RGPIO1=0x1 RGPIO0=0x1 Boot Source: UART0, (description of UART Xmodem
function).

Following in the same document on page 13 figure 2-1 Boot Flow:
JH7110 supports the following boot devices.
QSPI Flash (For SPL + OpenSBI + U-Boot) + NVMe/SD Card/eMMC (For Kernel + Fi
le System and later)
Note: System will detect in sequence whether it can boot from the following
device sequence: NVMe > SD > eMMC. For example, if the boot program is found
on the SD, eMMC will be ignored.

Again in this document Figure 4-2 on page 17 is a visual listing of the DIP
switch positions for QSPI, SDIO, eMMC, and UART boot modes, of the
VisionFive2 board.

The only consistent physical interface over VisionFive2, Mars, Star64, Mars
CM all is RGPIO1=L RGPIO0=L SPI and RGPIO1=H RGPIO1=H UART; either by DIP
switch or pushbutton attached circuit. So, I question our assumptions about
what the actual behavior is for RGPIO1=H RGPIO0=L pairing and RGPIO1=L
RGPIO0=H, and in what circumstance would there be followed a device
sequence as suggested by the JH7110 reference. Why does the StarFive
documentation list a JH7110 boot device sequence if there is also these H+L
or L+H pairings to choose the device?

On Thu, Mar 7, 2024 at 6:37 PM Heinrich Schuchardt <
heinrich.schuchardt@canonical.com> wrote:

> On 3/8/24 00:20, E Shattow wrote:
> >
> > On Sun, Mar 3, 2024 at 5:02 AM Heinrich Schuchardt
> > <heinrich.schuchardt@canonical.com
> > <mailto:heinrich.schuchardt@canonical.com>> wrote:
> > ...
> >
> >     +The board provides the DIP switches MSEL[1:0] to select the boot
> >     device out of
> >     +SPI flash, eMMC, SD-card, UART. To select booting from SD-card set
> >     the DIP
> >     +switches MSEL[1:0] to 10.
> >
> >
> > This does not match the [Milk-V Mars vendor
> > documentation](https://milkv.io/docs/mars/getting-started/bootloader
> > <https://milkv.io/docs/mars/getting-started/bootloader>). Maybe you
> have
> > a different board revision?
>
> Thank you for reviewing.
>
> My board revision is V1.21 according to the silk screen.
>
> The Milk-V Mars has DIP switches for the boot selection as shown in
> https://gist.github.com/xypron/e28f95b1ed6911aeb9699ba63ae1a885
>
> If you look at the photo
>
> https://milkv.io/assets/images/mars-icon-04-e8814f18158a0e9d4387f4fa330693f1.webp
> in the https://milkv.io/mars page, it also shows DIP switches (in the
> SPI-Flash position) on a rev 1.2 board.
>
> Did you see a board without DIP switches being sold?
>
> The silk screen markings on the board and the switch don't match.
> The same confusion exists on the VisionFive2.
>
> So maybe I should better write in a table:
>
> SPI-Flash:
> GPIO0=L
> GPIO1=L
>
> SD-Card:
> GPIO0=H
> GPIO1=L
>
> eMMC:
> GPIO0=L
> GPIO1=H
>
> UART:
> GPIO0=H
> GPIO1=H
>
> Best regards
>
> Heinrich
>
Heinrich Schuchardt March 8, 2024, 10:49 p.m. UTC | #4
On 3/8/24 22:48, E Shattow wrote:
> Yes this reference to GPIO high/low states is clearer to understand. 
> Have you tested the DIP switch functionality to confirm?; It is not 
> shown in the MilkV documentation or outdated schematics and I don't have 
> a Mars to test. I did find function descriptions from what is likely 
> cut-and-paste of VisionFive2 board reference.
> 
> Ref: 
> https://github.com/milkv-mars/mars-files/blob/main/Mars_hardware_schematics/Mars_V1.11_20230821.pdf <https://github.com/milkv-mars/mars-files/blob/main/Mars_hardware_schematics/Mars_V1.11_20230821.pdf> Sheet 7 of 22 JH7110 GPIOs
> There is a schematic for SW2 (bootloader button?) that lists an inset table:
> * - GPIO_1
>    - GPIO_0
>    - Boot
> * - 0
>    - 0
>    - Flash
> * - 0
>    - 1
>    - SD
> * - 1
>    - 0
>    - eMMC
> * - 1
>    - 1
>    - UART
> 
> That circuit on SW2 appears to pull high both RGPIO_1 and RGPIO_0 with 
> transistors. Again, no DIP switch as this is an earlier revision.
> 
> Ref: 
> https://doc-en.rvspace.org/VisionFive2/Developer_Guide/JH7110_Boot_UG.pdf <https://doc-en.rvspace.org/VisionFive2/Developer_Guide/JH7110_Boot_UG.pdf>  page 9 table 1-4:
> RGPIO1=0x0 RGPIO0=0x0 Boot Source: Quad SPI NOR flash memory, Read SPL 
> from Sector 0.
> RGPIO1=0x1 RGPIO0=0x1 Boot Source: UART0, (description of UART Xmodem 
> function).
> 
> Following in the same document on page 13 figure 2-1 Boot Flow:
> JH7110supportsthefollowingbootdevices.
> QSPIFlash(ForSPL + OpenSBI + 
> U-Boot)+NVMe/SDCard/eMMC(ForKernel+FileSystemandlater)
> Note: 
> System will detect in sequence whether it can boot from the following 
> device sequence: NVMe > SD > eMMC.
> For example,if the boot program is found on the SD, eMMC will be ignored.

The GPIOs select from where U-Boot SPL is loaded. Currently U-Boot SPL 
loads main U-Boot from the same device. But you could change it to scan 
multiple devices for main U-Boot.

Once you have successfully loaded main U-Boot, main U-Boot will scan the 
different boot devices. This includes NVME, eMMC, SD, USB, Network.

Currently upstream U-Boot development is moving from hard coded 
sequences in board files to configurable boot sequences.

> 
> Again in this document Figure 4-2 on page 17 is a visual listing of the 
> DIP switch positions for QSPI, SDIO, eMMC, and UART boot modes, of the 
> VisionFive2 board.

These are just the same switches as on the Milk-V.

> 
> The only consistent physical interface over VisionFive2, Mars, Star64, 
> Mars CM all is RGPIO1=L RGPIO0=L SPI and RGPIO1=H RGPIO1=H UART; either 
> by DIP switch or pushbutton attached circuit. So, I question our 
> assumptions about what the actual behavior is for RGPIO1=H RGPIO0=L 
> pairing and RGPIO1=L RGPIO0=H, and in what circumstance would there be 
> followed a device sequence as suggested by the JH7110 reference. Why 
> does the StarFive documentation list a JH7110 boot device sequence if 
> there is also these H+L or L+H pairings to choose the device?

As said the device sequence including NVMe is not realized by the code 
loading U-Boot SPL. It is realized in main U-Boot.

Best regards

Heinrich

> 
> On Thu, Mar 7, 2024 at 6:37 PM Heinrich Schuchardt 
> <heinrich.schuchardt@canonical.com 
> <mailto:heinrich.schuchardt@canonical.com>> wrote:
> 
>     On 3/8/24 00:20, E Shattow wrote:
>      >
>      > On Sun, Mar 3, 2024 at 5:02 AM Heinrich Schuchardt
>      > <heinrich.schuchardt@canonical.com
>     <mailto:heinrich.schuchardt@canonical.com>
>      > <mailto:heinrich.schuchardt@canonical.com
>     <mailto:heinrich.schuchardt@canonical.com>>> wrote:
>      > ...
>      >
>      >     +The board provides the DIP switches MSEL[1:0] to select the boot
>      >     device out of
>      >     +SPI flash, eMMC, SD-card, UART. To select booting from
>     SD-card set
>      >     the DIP
>      >     +switches MSEL[1:0] to 10.
>      >
>      >
>      > This does not match the [Milk-V Mars vendor
>      >
>     documentation](https://milkv.io/docs/mars/getting-started/bootloader
>     <https://milkv.io/docs/mars/getting-started/bootloader>
>      > <https://milkv.io/docs/mars/getting-started/bootloader
>     <https://milkv.io/docs/mars/getting-started/bootloader>>). Maybe you
>     have
>      > a different board revision?
> 
>     Thank you for reviewing.
> 
>     My board revision is V1.21 according to the silk screen.
> 
>     The Milk-V Mars has DIP switches for the boot selection as shown in
>     https://gist.github.com/xypron/e28f95b1ed6911aeb9699ba63ae1a885
>     <https://gist.github.com/xypron/e28f95b1ed6911aeb9699ba63ae1a885>
> 
>     If you look at the photo
>     https://milkv.io/assets/images/mars-icon-04-e8814f18158a0e9d4387f4fa330693f1.webp <https://milkv.io/assets/images/mars-icon-04-e8814f18158a0e9d4387f4fa330693f1.webp>
>     in the https://milkv.io/mars <https://milkv.io/mars> page, it also
>     shows DIP switches (in the
>     SPI-Flash position) on a rev 1.2 board.
> 
>     Did you see a board without DIP switches being sold?
> 
>     The silk screen markings on the board and the switch don't match.
>     The same confusion exists on the VisionFive2.
> 
>     So maybe I should better write in a table:
> 
>     SPI-Flash:
>     GPIO0=L
>     GPIO1=L
> 
>     SD-Card:
>     GPIO0=H
>     GPIO1=L
> 
>     eMMC:
>     GPIO0=L
>     GPIO1=H
> 
>     UART:
>     GPIO0=H
>     GPIO1=H
> 
>     Best regards
> 
>     Heinrich
>
diff mbox series

Patch

diff --git a/doc/board/starfive/index.rst b/doc/board/starfive/index.rst
index 0c52dc7b095..2762bf74c11 100644
--- a/doc/board/starfive/index.rst
+++ b/doc/board/starfive/index.rst
@@ -6,4 +6,5 @@  StarFive
 .. toctree::
    :maxdepth: 1
 
+   milk-v_mars.rst
    visionfive2
diff --git a/doc/board/starfive/milk-v_mars.rst b/doc/board/starfive/milk-v_mars.rst
new file mode 100644
index 00000000000..9cfd5d7bddd
--- /dev/null
+++ b/doc/board/starfive/milk-v_mars.rst
@@ -0,0 +1,93 @@ 
+.. SPDX-License-Identifier: GPL-2.0+
+
+Milk-V Mars
+===========
+
+U-Boot for the Milk-V Mars uses the same U-Boot binaries as the VisionFive 2
+board. In U-Boot SPL the actual board is detected and the device-tree patched
+accordingly.
+
+Building
+~~~~~~~~
+
+1. Add the RISC-V toolchain to your PATH.
+2. Setup ARCH & cross compilation environment variable:
+
+.. code-block:: none
+
+   export CROSS_COMPILE=<riscv64 toolchain prefix>
+
+The M-mode software OpenSBI provides the supervisor binary interface (SBI) and
+is responsible for the switch to S-Mode. It is a prerequisite to build U-Boot.
+Support for the JH7110 was introduced in OpenSBI 1.2. It is recommended to use
+a current release.
+
+.. code-block:: console
+
+	git clone https://github.com/riscv/opensbi.git
+	cd opensbi
+	make PLATFORM=generic FW_TEXT_START=0x40000000 FW_OPTIONS=0
+
+Now build the U-Boot SPL and U-Boot proper.
+
+.. code-block:: console
+
+	cd <U-Boot-dir>
+	make starfive_visionfive2_defconfig
+	make OPENSBI=$(opensbi_dir)/build/platform/generic/firmware/fw_dynamic.bin
+
+This will generate the U-Boot SPL image (spl/u-boot-spl.bin.normal.out) as well
+as the FIT image (u-boot.itb) with OpenSBI and U-Boot.
+
+Boot source selection
+~~~~~~~~~~~~~~~~~~~~~
+
+The board provides the DIP switches MSEL[1:0] to select the boot device out of
+SPI flash, eMMC, SD-card, UART. To select booting from SD-card set the DIP
+switches MSEL[1:0] to 10.
+
+Preparing the SD-Card
+~~~~~~~~~~~~~~~~~~~~~
+
+The device firmware loads U-Boot SPL (u-boot-spl.bin.normal.out) from the
+partition with type GUID 2E54B353-1271-4842-806F-E436D6AF6985. You are free
+to choose any partition number.
+
+With the default configuration U-Boot SPL loads the U-Boot FIT image
+(u-boot.itb) from partition 2 (CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=0x2).
+When formatting it is recommended to use GUID
+BC13C2FF-59E6-4262-A352-B275FD6F7172 for this partition.
+
+The FIT image (u-boot.itb) is a combination of OpenSBI's fw_dynamic.bin,
+u-boot-nodtb.bin and the device tree blob.
+
+Format the SD card (make sure the disk has GPT, otherwise use gdisk to switch)
+
+.. code-block:: bash
+
+	sudo sgdisk --clear \
+	  --set-alignment=2 \
+	  --new=1:4096:8191 --change-name=1:spl --typecode=1:2E54B353-1271-4842-806F-E436D6AF6985\
+	  --new=2:8192:16383 --change-name=2:uboot --typecode=2:BC13C2FF-59E6-4262-A352-B275FD6F7172  \
+	  --new=3:16384:1654784 --change-name=3:system --typecode=3:EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 \
+	  /dev/sdb
+
+Copy U-Boot to the SD card
+
+.. code-block:: bash
+
+	sudo dd if=u-boot-spl.bin.normal.out of=/dev/sdb1
+	sudo dd if=u-boot.itb of=/dev/sdb2
+
+	sudo mount /dev/sdb3 /mnt/
+	sudo cp u-boot-spl.bin.normal.out /mnt/
+	sudo cp u-boot.itb /mnt/
+	sudo cp Image.gz /mnt/
+	sudo cp initramfs.cpio.gz /mnt/
+	sudo cp jh7110-starfive-visionfive-2.dtb /mnt/
+	sudo umount /mnt
+
+Booting
+~~~~~~~
+
+Once you plugin the sdcard and power up, you should see the U-Boot prompt.