Difference between revisions of "User:RemDogKap/SandBox/Build U-Boot and OpenSBI From Source"

From PINE64
Jump to navigation Jump to search
(set up compilation environment and build u-boot sections written)
m (Removed placeholder text)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
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==
==Preparing the Build Environment==
Line 14: Line 12:
Using built-in specs.
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc
COLLECT_GCC=riscv64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/riscv64-linux-gnu/10/lto-wrapper
COLLECT_LTO_WRAPPER=usr/lib/gcc-cross/riscv64-linux-gnu/10/lto-wrapper
Target: riscv64-linux-gnu
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
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
Line 32: Line 30:
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-new-directory-example">
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-new-directory-example">
  $ mkdir ~/Star64-Firmware
  $ mkdir ~/Star64-Firmware
  $ cd ~/Star64-Firmware
  $ cd ~/Star64-Firmware/
</div>
</div>
Clone the StarFive Tools GitHub repository. This will be used to create the <code>.bin.normal.out</code> SPL image and provide the <code>.its</code> FIT image tree source file which provides the configuration for the <code>.img</code> U-Boot image file.
$ git clone --depth 1 https://github.com/starfive-tech/Tools
Compile the SPL Tool used to create the SPL image in the <code><working_directory>/Tools/spl_tool/</code> directory using <code>make</code>.
$ make -C Tools/spl_tool/
==U-Boot==
==U-Boot==


Line 39: Line 42:
  $ git clone --depth 1 -b Star64 <nowiki>https://github.com/Fishwaldo/u-boot.git</nowiki>
  $ git clone --depth 1 -b Star64 <nowiki>https://github.com/Fishwaldo/u-boot.git</nowiki>
Enter the U-Boot directory.
Enter the U-Boot directory.
  $ cd u-boot
  $ cd u-boot/
Select the U-Boot configuration for the Star64, marking the architecture as RISC-V and using the cross-compiler installed earlier.
Select the U-Boot configuration for the Star64, marking the architecture as RISC-V (<code>ARCH=riscv</code>) and using the cross-compiler installed earlier(<code>CROSS_COMPILE=riscv64-linux-gnu-</code>).
  $ make pine64_star64_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
  $ make pine64_star64_defconfig ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
Finally, compile U-Boot.  
Finally, compile U-Boot.  
  $ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
  $ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-
This should create three files.  
This should create three files.  
# The U-Boot binary, later packaged as an OpenSBI payload, located at <code>/u-boot/u-boot.bin</code>.  
# The U-Boot binary, later packaged as an OpenSBI payload, located at <code><working_directory>/u-boot/u-boot.bin</code>.  
# 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 <code>/u-boot/arch/riscv/dts/pine64_star64.dtb</code>.
# 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 <code><working_directory>/u-boot/arch/riscv/dts/pine64_star64.dtb</code>.
# The U-Boot secondary program loader which will later be packaged into the <code>u-boot-spl.bin.normal.out</code> file and is located at <code>/u-boot/spl/u-boot-spl.bin</code>.
# The U-Boot secondary program loader which will later be packaged into the <code>u-boot-spl.bin.normal.out</code> file and is located at <code><working_directory>/u-boot/spl/u-boot-spl.bin</code>.
==
==OpenSBI==
Return to the directory where the files for this build are stored. In this case it is the Linux home directory. Unless you have since changed directories,
$ cd ..
should return to to the directory before the U-Boot section.
 
Clone the OpenSBI U-Boot repository and enter its directory. The entire history is not needed (<code>--depth 1</code>).
$ git clone --depth 1 <nowiki>https://github.com/riscv/opensbi.git</nowiki>
$ cd opensbi/
Compile OpenSBI using <code>make</code>. Make sure to set
# the architecture as RISC-V (<code>ARCH=riscv</code>)
# the compiler as the cross-compiler installed earlier (<code>CROSS_COMPILE=riscv64-linux-gnu-</code>)
# the platform as generic (<code>PLATFORM=generic</code>)
# the OpenSBI payload path as the path to the <code>u-boot.bin</code> file created in the [[#U-Boot|U-Boot]] step (<code>FW_PAYLOAD_PATH=<working_directory>/u-boot/u-boot.bin</code>)
# the flattened device tree (device tree blob) as the <code>pine64_star64.dtb</code> file created in the [[#U-Boot|U-Boot]] step (<code>FW_FDT_PATH=<working_directory>/u-boot/arch/riscv/dts/pine64_star64.dtb</code>)
# <code>FW_TEXT_START</code> as <code>0x40000000</code> (<code>FW_TEXT_START=0x40000000</code>).
$ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=<working_directory>/u-boot/u-boot.bin FW_FDT_PATH=<working_directory>/u-boot/arch/riscv/dts/pine64_star64.dtb FW_TEXT_START=0x40000000
Make sure to replace <code><working_directory></code> with the directory created or chosen in [[#Preparing_the_Build_Environment|Preparing the Build Environment]].
<span class="mw-customtoggle-compile-opensbi-example" style="text-decoration:underline;color:#0645ad">Example</span>
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-compile-opensbi-example">
$ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=~/u-boot/u-boot.bin FW_FDT_PATH=~/u-boot/arch/riscv/dts/pine64_star64.dtb FW_TEXT_START=0x40000000
</div>
This should create one file, <code>fw_payload.bin</code>, which contains OpenSBI with U-Boot as the payload. The file is located at <code>opensbi/build/platform/generic/firmware/fw_payload.bin</code>.
 
==Creating the SPL File==
Go to the directory the SPL Tool compiled earlier is located in. If these instructions were followed exactly the following should work:
$ cd ../Tools/spl_tool/
Use the SPL Tool to create the <code>u-boot-spl.bin.normal.out</code> SPL image.
$ ./spl_tool -c -f <working_directory>/u-boot/spl/u-boot-spl.bin
Make sure to replace <code><working_directory></code> with the directory created or chosen in [[#Preparing_the_Build_Environment|Preparing the Build Environment]].
<span class="mw-customtoggle-spl-tool-example" style="text-decoration:underline;color:#0645ad">Example</span>
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-spl-tool-example">
$ ./spl_tool -c -f ~/u-boot/spl/u-boot-spl.bin
</div>
This should produce a <code>u-boot-spl.bin.normal.out</code> file located at <code><working_directory>/u-boot/spl/u-boot-spl.bin.normal.out</code>
==Creating the fw_payload File==
Return to the directory where the files for this build are stored. In this case it is the Linux home directory. Unless you have since changed directories,
$ cd ..
should work.


Enter the <code><working_directory>/Tools/uboot_its/</code> directory which holds the <code>.its</code> FIT image tree source file which provides the configuration for the <code>.img</code> U-Boot image file.
$ cd Tools/uboot_its/
The process of making the U-Boot image requires the <code>fw_payload.bin</code> created earlier so copy that to the current directory.
$ cp <working_directory>/opensbi/build/platform/generic/firmware/fw_payload.bin ./
Make sure to replace <code><working_directory></code> with the directory created or chosen in [[#Preparing_the_Build_Environment|Preparing the Build Environment]].
<span class="mw-customtoggle-fw_payload-cp-example" style="text-decoration:underline;color:#0645ad">Example</span>
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-fw_payload-cp-example">
$ cp ~/opensbi/build/platform/generic/firmware/fw_payload.bin ./
</div>
Make the <code>star64_fw_payload.img</code> U-Boot image file using the U-Boot <code>mkimage</code> tool. The <code>mkimage</code> tool is located in the <code><working_directory>/u-boot/tools/</code> directory but requires the <code>visionfive2-uboot-fit-image.its</code> file which is located in <code><working_directory>/Tools/uboot_its/</code> so should be executed in the <code>uboot_its</code> directory.
$ <working_directory>/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware star64_fw_payload.img
Make sure to replace <code><working_directory></code> with the directory created or chosen in [[#Preparing_the_Build_Environment|Preparing the Build Environment]].
<span class="mw-customtoggle-mkimage-example" style="text-decoration:underline;color:#0645ad">Example</span>
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-mkimage-example">
$ ~/u-boot/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware star64_fw_payload.img
</div>
There is currently no <code>.its</code> file specifically for the Star64 so the VisionFive2's <code>.its</code> file is used instead as they share a processor.
This should produce a file called <code>star64_fw_payload.img</code> in the <code><working_directory>/Tools/uboot_its/</code> directory
==Credits==
==Credits==
https://doc-en.rvspace.org/VisionFive2/SWTRM/VisionFive2_SW_TRM/compiling_u-boot_and_kernel%20-%20vf2.html
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
https://wiki.pine64.org/wiki/User:Vitali/Create_a_bootable_Debian/Linux_SDCard_for_the_Pine64/Star64_from_scratch

Latest revision as of 03:01, 29 October 2023


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/

Clone the StarFive Tools GitHub repository. This will be used to create the .bin.normal.out SPL image and provide the .its FIT image tree source file which provides the configuration for the .img U-Boot image file.

$ git clone --depth 1 https://github.com/starfive-tech/Tools

Compile the SPL Tool used to create the SPL image in the <working_directory>/Tools/spl_tool/ directory using make.

$ make -C Tools/spl_tool/

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 (ARCH=riscv) and using the cross-compiler installed earlier(CROSS_COMPILE=riscv64-linux-gnu-).

$ 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 <working_directory>/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 <working_directory>/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 <working_directory>/u-boot/spl/u-boot-spl.bin.

OpenSBI

Return to the directory where the files for this build are stored. In this case it is the Linux home directory. Unless you have since changed directories,

$ cd ..

should return to to the directory before the U-Boot section.

Clone the OpenSBI U-Boot repository and enter its directory. The entire history is not needed (--depth 1).

$ git clone --depth 1 https://github.com/riscv/opensbi.git
$ cd opensbi/

Compile OpenSBI using make. Make sure to set

  1. the architecture as RISC-V (ARCH=riscv)
  2. the compiler as the cross-compiler installed earlier (CROSS_COMPILE=riscv64-linux-gnu-)
  3. the platform as generic (PLATFORM=generic)
  4. the OpenSBI payload path as the path to the u-boot.bin file created in the U-Boot step (FW_PAYLOAD_PATH=<working_directory>/u-boot/u-boot.bin)
  5. the flattened device tree (device tree blob) as the pine64_star64.dtb file created in the U-Boot step (FW_FDT_PATH=<working_directory>/u-boot/arch/riscv/dts/pine64_star64.dtb)
  6. FW_TEXT_START as 0x40000000 (FW_TEXT_START=0x40000000).
$ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=<working_directory>/u-boot/u-boot.bin FW_FDT_PATH=<working_directory>/u-boot/arch/riscv/dts/pine64_star64.dtb FW_TEXT_START=0x40000000

Make sure to replace <working_directory> with the directory created or chosen in Preparing the Build Environment. Example

$ make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PAYLOAD_PATH=~/u-boot/u-boot.bin FW_FDT_PATH=~/u-boot/arch/riscv/dts/pine64_star64.dtb FW_TEXT_START=0x40000000

This should create one file, fw_payload.bin, which contains OpenSBI with U-Boot as the payload. The file is located at opensbi/build/platform/generic/firmware/fw_payload.bin.

Creating the SPL File

Go to the directory the SPL Tool compiled earlier is located in. If these instructions were followed exactly the following should work:

$ cd ../Tools/spl_tool/

Use the SPL Tool to create the u-boot-spl.bin.normal.out SPL image.

$ ./spl_tool -c -f <working_directory>/u-boot/spl/u-boot-spl.bin

Make sure to replace <working_directory> with the directory created or chosen in Preparing the Build Environment. Example

$ ./spl_tool -c -f ~/u-boot/spl/u-boot-spl.bin

This should produce a u-boot-spl.bin.normal.out file located at <working_directory>/u-boot/spl/u-boot-spl.bin.normal.out

Creating the fw_payload File

Return to the directory where the files for this build are stored. In this case it is the Linux home directory. Unless you have since changed directories,

$ cd ..

should work.

Enter the <working_directory>/Tools/uboot_its/ directory which holds the .its FIT image tree source file which provides the configuration for the .img U-Boot image file.

$ cd Tools/uboot_its/

The process of making the U-Boot image requires the fw_payload.bin created earlier so copy that to the current directory.

$ cp <working_directory>/opensbi/build/platform/generic/firmware/fw_payload.bin ./

Make sure to replace <working_directory> with the directory created or chosen in Preparing the Build Environment. Example

$ cp ~/opensbi/build/platform/generic/firmware/fw_payload.bin ./

Make the star64_fw_payload.img U-Boot image file using the U-Boot mkimage tool. The mkimage tool is located in the <working_directory>/u-boot/tools/ directory but requires the visionfive2-uboot-fit-image.its file which is located in <working_directory>/Tools/uboot_its/ so should be executed in the uboot_its directory.

$ <working_directory>/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware star64_fw_payload.img

Make sure to replace <working_directory> with the directory created or chosen in Preparing the Build Environment. Example

$ ~/u-boot/tools/mkimage -f visionfive2-uboot-fit-image.its -A riscv -O u-boot -T firmware star64_fw_payload.img

There is currently no .its file specifically for the Star64 so the VisionFive2's .its file is used instead as they share a processor.

This should produce a file called star64_fw_payload.img in the <working_directory>/Tools/uboot_its/ directory

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