Compile U-Boot to Create Boot Files

This section provides instructions to compile U-Boot to create two boot files: the SPL firmware image (u-boot-spl.bin.normal.out) and the main firmware payload image (visionfive2_fw_payload.img).

Install Compiler

To install the RISC-V Linux compiler:
  1. Execute the following commands to install the riscv64-linux-gnu-gcc compiler from Ubuntu packages.
    
    sudo apt update
    sudo apt upgrade
    sudo apt install gcc-riscv64-linux-gnu
  2. Execute the following command to check the version of the riscv64-linux-gnu-gcc.
    riscv64-linux-gnu-gcc -v
    The output is as follows:
    Figure 1. gcc Version

Compile U-Boot

Follow the steps below to compile U-Boot for VisionFive 2.
  1. Locate your desired directory to store the U-Boot files. For example, the home directory.
    cd ~ # <U-Boot directory>
  2. Download the source code for U-Boot compilation.
    git clone https://github.com/starfive-tech/u-boot.git
  3. Switch to the code branch by executing the following command:
    cd u-boot
    git checkout -b JH7110_VisionFive2_devel origin/JH7110_VisionFive2_devel
    git pull
  4. Type the following to compile U-Boot under the U-Boot directory.
    make <Configuration_File> ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
    make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-

    where, Configuration_File is starfive_visionfive2_defconfig.

    The following 3 files are generated in the U-Boot directory after the U-Boot compilation:
    • u-boot.bin: To be used for OpenSBI compilation
    • arch/riscv/dts/starfive_visionfive2.dtb: VisionFive 2 device tree file, to be used for OpenSBI compilation
    • spl/u-boot-spl.bin: U-Boot Secondary Program Loader file, to be used for SPL file creation

Compile OpenSBI

OpenSBI stands for Open-source Supervisor Binary Interface and it is an open-source implementation of the RISC-V Supervisor Binary Interface. It is a RISC-V-specific runtime service provider and it is typically used in boot stage following ROM and LOADER. A typical boot flow is as follows:
Figure 2. Typical Boot Flow
To compile OpenSBI for VisionFive 2:
  1. Locate your desired directory to store the OpenSBI files. For example, the home directory.
    cd ~ # <OpenSBI directory>
  2. Download the source code for OpenSBI compilation.
    git clone https://github.com/starfive-tech/u-boot.git
  3. Change to the OpenSBI directory. Type the following to compile OpenSBI.
    cd <OpenSBI directory>
    make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=${U_BOOT_PATH}/u-boot.bin FW_FDT_PATH=${U_BOOT_PATH}/arch/riscv/dts/starfive_visionfive2.dtb FW_TEXT_START=0x40000000

    After the OpenSBI compilation, the fw_payload.bin file is generated in the <OpenSBI directory>/build/platform/generic/firmware directory, and the size is larger than 2 M.

Create SPL Firmware Image

Use the spl_tool to generate the SPL header information and the SPL firmware image (u-boot-spl.bin.normal.out).
  1. Locate your desired directory to store the tools files. For example, the home directory.
    cd ~ # <Tools directory>
  2. Download the tools source code.
    git clone https://github.com/starfive-tech/Tools
  3. Switch to the code branch by executing the following command:
    cd Tools
    git checkout master
    git pull
  4. Run the following to generate SPL tool files under the spl_tool directory:
    cd spl_tool/
    make
  5. Run the following to generate the SPL file:
    ./spl_tool -c -f ${U_BOOT_PATH}/spl/u-boot-spl.bin

    A new file named u-boot-spl.bin.normal.out is generated under {U_BOOT_PATH}/spl To flash this file, see Update SPL and U-Boot of Flash.

    Figure 3. Example Output

Create Main Firmware Payload Image

To create the firmware payload image file for VisionFive 2:
  1. Change to the <Tools directory>/uboot_its directory.
    cd <Tools directory>/uboot_its
  2. Copy the fw_payload.bin file from the <opensbi directoy>/build/platform/generic/firmware directory to the <Tools directory>/uboot_its path.
    cp ${OPENSBI_PATH}/build/platform/generic/firmware/fw_payload.bin ./
  3. Run the following to create the fw_payload file under the uboot_its directory.
    ${U_BOOT_PATH}/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware visionfive2_fw_payload.img

    A new file named visionfive2_fw_payload.img is generated. To flash this file, see Update SPL and U-Boot of Flash.