User:RemDogKap/SandBox/Build U-Boot and OpenSBI From Source

From PINE64
< User:RemDogKap‎ | SandBox
Revision as of 23:02, 25 June 2023 by RemDogKap (talk | contribs) (set up compilation environment and build u-boot sections written)
Jump to navigation Jump to search

Placeholder intro and explanation, I'm tired don't want to write now, contributions welcome

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

  • Must use linux, can use wsl

Preparing the Build Environment

Fist, install the cross-compiler and if not already installed, git.

$ sudo apt update && sudo apt install gcc-riscv64-linux-gnu git

[Optional] Check the version of the riscv64-linux-gnu-gcc compiler.

$ riscv64-linux-gnu-gcc -v

The output should looks something like:

Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/riscv64-linux-gnu/10/lto-wrapper
Target: riscv64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.2.1-6' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64imafdc --with-abi=lp64d --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=riscv64-linux-gnu --program-prefix=riscv64-linux-gnu- --includedir=/usr/riscv64-linux-gnu/include --with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20210110 (Debian 10.2.1-6)

Create or enter the directory where the files used in this guide will be stored. This tutorial will be using the Linux home directory.

Home Directory Example

$ cd ~

New Directory Example

$ mkdir ~/Star64-Firmware
$ cd ~/Star64-Firmware

U-Boot

Clone the U-Boot GitHub repository. The entire history is not needed (--depth 1) and we want the Star64 branch (-b Star64).

$ git clone --depth 1 -b Star64 https://github.com/Fishwaldo/u-boot.git

Enter the U-Boot directory.

$ cd u-boot

Select the U-Boot configuration for the Star64, marking the architecture as RISC-V and using the cross-compiler installed earlier.

$ make pine64_star64_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-

Finally, compile U-Boot.

$ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-

This should create three files.

  1. The U-Boot binary, later packaged as an OpenSBI payload, located at /u-boot/u-boot.bin.
  2. The device tree blob (binary), which contains information on the characteristics of the device and is passed to the operating system instead of hard-coding device configurations into the operating system, and is located at /u-boot/arch/riscv/dts/pine64_star64.dtb.
  3. The U-Boot secondary program loader which will later be packaged into the u-boot-spl.bin.normal.out file and is located at /u-boot/spl/u-boot-spl.bin.

==

Credits

https://doc-en.rvspace.org/VisionFive2/SWTRM/VisionFive2_SW_TRM/compiling_u-boot_and_kernel%20-%20vf2.html

https://wiki.pine64.org/wiki/User:Vitali/Create_a_bootable_Debian/Linux_SDCard_for_the_Pine64/Star64_from_scratch