Compiling 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 1. Typical Boot Flow
pir

Follow the steps below to compile OpenSBI for VisionFive.

  1. Locate to your desired directory to store the OpenSBI files. For example, the home directory.
    cd ~ # home directory
  2. Download the source code for OpenSBI compilation.
    git clone https://github.com/riscv/opensbi.git
  3. Inside opensbi directory, type the following to compile openSBI.
    cd opensbi
    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}/u-boot.dtb
    
    Tip:

    Modify the {U-BOOT_PATH} to the path of u-boot from before.

    Result:

    After compilation, the file fw_payload.bin will be generated in the directory opensbi/build/platform/generic/firmware and the size is larger than 2M.

    Figure 2. Example Output
    fwbin.jpg
  4. Navigate to the directory containing fw_payload.bin.
    cd opensbi/build/platform/generic/firmware
  5. Copy the file fw_payload.bin to a different location.
    cp fw_payload.bin ~/Desktop/payload/
  6. Navigate to the location where fw_payload.bin is copied and execute the following to install an image conversion tool.
    cd ~/Desktop/payload/
    sudo apt install subversion
    svn export https://github.com/starfive-tech/freelight-u-sdk.git/branches/starfive/fsz.sh
    Tip:

    Here is the source code.

  7. Change the user rights of the tool.
    chmod 777 fsz.sh
  8. Convert the file from fw_payload.bin to fw_payload.bin.out.
    ./fsz.sh fw_payload.bin fw_payload.bin.out

    Figure -

    Figure 3. Example Output
    compiling_opensbi_step8_output.png
    Tip:

    You will see a new file named fw_payload.bin.out generated. Refer to Appendix B: Updating Firmware and u-boot section in VisionFive Single Board Computer Quick Start Guide to flash u-boot.