Difference between revisions of "U-Boot"

From PINE64
Jump to navigation Jump to search
(fix)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{hint|This page is incomplete, you're welcome to improve it.}}
{{hint|It is helpful to have a debugging serial cable for this.}}
{{note|It is helpful to have a debugging serial cable for this.}}


= Building uboot manually =
== Building U-Boot manually ==


==Prerequisites==
=== Prerequisites ===


These instructions are written with a host Arch Linux desktop system in mind.
These instructions are written with a host Arch Linux desktop system in mind.


This guide will be especially useful if you are looking to overclock the ram on your Pinephone following the information found [https://wiki.pine64.org/index.php?title=Overclocking#DRAM here].
This guide will be especially useful if you are looking to overclock the ram on your PinePhone following the information found [[Overclocking#DRAM|here]].


You must have these packages installed: <code>dtc swig bc aarch64-linux-gnu-gcc</code>
You must have these packages installed: <code>dtc swig bc aarch64-linux-gnu-gcc</code>


If you are using a different system such as Ubuntu, there are plenty of cross compilation instructions available online with which you can grab the needed package names from, however you should be able to follow these instructions with these packages installed: <code>build-essentials bison flex swig gcc-aarch64-linux-gnu</code>
If you are using a different system such as Ubuntu, there are plenty of cross compilation instructions available online with which you can grab the needed package names from, however you should be able to follow these instructions with these packages installed: <code>build-essential bison flex swig gcc-aarch64-linux-gnu</code>


==Compilation==
=== Compilation ===


{{note| This guide is written with the Pinephone in mind. On other devices you will need to set a different platform variable and likely use a different uboot source with patches oriented towards your device.}}
{{hint| This guide is written with the PinePhone in mind. On other devices you will need to set a different platform variable and likely use a different U-Boot source with patches oriented towards your device.}}


Note by default these instructions utilize all of your computers cores to compile thanks to the <code>-j</code> and <code>$(nproc)</code> parameters. If you wish to only use one core to compile, or change the number of cores used for example to only two cores, then you can either completely remove the <code>-j$(nproc)</code> parameter from the make commands, or just take off <code>$(nproc)</code> and add the number of threads you want used in it's place: <code>-j4</code>
Note by default these instructions utilize all of your computers cores to compile thanks to the <code>-j</code> and <code>$(nproc)</code> parameters. If you wish to only use one core to compile, or change the number of cores used for example to only two cores, then you can either completely remove the <code>-j$(nproc)</code> parameter from the make commands, or just take off <code>$(nproc)</code> and add the number of threads you want used in it's place: <code>-j4</code>


First, You need to compile ATF (Arm Trusted Firmware):
First, You need to compile the ATF (Arm Trusted Firmware):
<pre>
 
  git clone https://github.com/crust-firmware/arm-trusted-firmware/
  git clone https://github.com/crust-firmware/arm-trusted-firmware/
  cd arm-trusted-firmware
  cd arm-trusted-firmware
Line 28: Line 27:
  make PLAT=sun50i_a64 -j$(nproc) bl31
  make PLAT=sun50i_a64 -j$(nproc) bl31
  cd ..
  cd ..
</pre>


After ATF is compiled clone u-boot and copy the bl31.bin file into the u-boot directory.
After the ATF is compiled clone u-boot and copy the bl31.bin file into the u-boot directory.
<pre>
git clone https://gitlab.com/pine64-org/u-boot.git
cd arm-trusted-firmware
cp build/sun50i_a64/release/bl31.bin ../u-boot/
cd ..
</pre>


git clone https://gitlab.com/pine64-org/u-boot.git
cd arm-trusted-firmware
cp build/sun50i_a64/release/bl31.bin ../u-boot/
cd ..


{{note| You cannot build crust if you do not have the or1k musl toolchain installed. This toolchain is not usually availible in distribution repositories and will have to be manually installed to the system. The following text will show a simple way to install the toolchain.}}
{{hint| You cannot build [[Crust]] if you do not have the or1k musl toolchain installed. This toolchain is not usually available in distribution repositories and will have to be manually installed to the system. The following text will show a simple way to install the toolchain.}}


Download the toolchain's archive: https://musl.cc/or1k-linux-musl-cross.tgz
Download the toolchain's archive: https://musl.cc/or1k-linux-musl-cross.tgz
Line 48: Line 44:


The final step is to edit your <code>.bashrc</code> and add the following to the end:
The final step is to edit your <code>.bashrc</code> and add the following to the end:
<pre>
 
# Path for or1k toolchain
# Path for or1k toolchain
export PATH="$PATH:/home/USER/Documents/or1k-linux-musl-cross/bin/"
export PATH="$PATH:/home/USER/Documents/or1k-linux-musl-cross/bin/"
#
</pre>


After you've completed that you can close out the terminal and reopen it and proceed to the following instructions.
After you've completed that you can close out the terminal and reopen it and proceed to the following instructions.


git clone https://github.com/crust-firmware/crust
cd crust
export CROSS_COMPILE=or1k-linux-musl-
make pinephone_defconfig
make -j$(nproc) scp
cp build/scp/scp.bin ../u-boot/
cd ..


<pre>
{{hint| If you do not wish to have [[Crust]] in your U-Boot build, then you can skip exporting SCP}}
git clone https://github.com/crust-firmware/crust
cd crust
export CROSS_COMPILE=or1k-linux-musl-
make pinephone_defconfig
make -j$(nproc) scp
cp /build/scp/scp.bin ../u-boot/
cd ..
</pre>
 
{{note| If you do not wish to have crust in your uboot build, then you can skip exporting SCP}}


<pre>
  cd u-boot/
  cd u-boot/
  git checkout crust
  git checkout crust
Line 79: Line 69:
  make pinephone_defconfig
  make pinephone_defconfig
  make all -j$(nproc)
  make all -j$(nproc)
</pre>


== Uboot installation ==
=== U-Boot installation ===


Once successfully compiled you can proceed to flash the device
Once successfully compiled you can proceed to flash the device
Line 88: Line 77:
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/[CHANGE THIS] bs=1024 seek=8
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/[CHANGE THIS] bs=1024 seek=8
</code>
</code>
{{note|If you are compiling uboot in order to overclock your DRAM you can check if it was successful by reading the values of /sys/kernel/debug/clk/clk_summary}}
{{hint|If you are compiling U-Boot in order to overclock your DRAM you can check if it was successful by reading the values of /sys/kernel/debug/clk/clk_summary}}


=Pboot multi-bootloader=
== p-boot multi-bootloader ==


One of the smallest and fastest pinephone bootloaders, it was developed by Ondrej Jirman with the ability of booting multiple distros on the pinephone in mind.
One of the smallest and fastest PinePhone bootloaders, it was developed by Ondrej Jirman with the ability of booting multiple distributions on the PinePhone in mind.


More information can be found [https://xnux.eu/p-boot/ here]
More information can be found [https://xnux.eu/p-boot/ here]


= External Links =
== External Links ==
[https://linux-sunxi.org/Mainline_U-Boot Sunxi Uboot Wiki]
[https://linux-sunxi.org/Mainline_U-Boot Sunxi U-Boot Wiki]
 
[https://raw.githubusercontent.com/u-boot/u-boot/master/board/sunxi/README.sunxi64 U-Boot build instructions]
 
[https://musl.cc/or1k-linux-musl-cross.tgz or1k toolchain download]


[https://raw.githubusercontent.com/u-boot/u-boot/master/board/sunxi/README.sunxi64 Uboot build instructions]


[[Category:PinePhone]]
[[Category:PinePhone]][[Category:Guide]]

Latest revision as of 21:18, 2 April 2023

It is helpful to have a debugging serial cable for this.

Building U-Boot manually

Prerequisites

These instructions are written with a host Arch Linux desktop system in mind.

This guide will be especially useful if you are looking to overclock the ram on your PinePhone following the information found here.

You must have these packages installed: dtc swig bc aarch64-linux-gnu-gcc

If you are using a different system such as Ubuntu, there are plenty of cross compilation instructions available online with which you can grab the needed package names from, however you should be able to follow these instructions with these packages installed: build-essential bison flex swig gcc-aarch64-linux-gnu

Compilation

This guide is written with the PinePhone in mind. On other devices you will need to set a different platform variable and likely use a different U-Boot source with patches oriented towards your device.

Note by default these instructions utilize all of your computers cores to compile thanks to the -j and $(nproc) parameters. If you wish to only use one core to compile, or change the number of cores used for example to only two cores, then you can either completely remove the -j$(nproc) parameter from the make commands, or just take off $(nproc) and add the number of threads you want used in it's place: -j4

First, You need to compile the ATF (Arm Trusted Firmware):

git clone https://github.com/crust-firmware/arm-trusted-firmware/
cd arm-trusted-firmware
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
make PLAT=sun50i_a64 -j$(nproc) bl31
cd ..

After the ATF is compiled clone u-boot and copy the bl31.bin file into the u-boot directory.

git clone https://gitlab.com/pine64-org/u-boot.git
cd arm-trusted-firmware
cp build/sun50i_a64/release/bl31.bin ../u-boot/
cd ..
You cannot build Crust if you do not have the or1k musl toolchain installed. This toolchain is not usually available in distribution repositories and will have to be manually installed to the system. The following text will show a simple way to install the toolchain.

Download the toolchain's archive: https://musl.cc/or1k-linux-musl-cross.tgz

Extract the compressed archive: tar zxvf or1k-linux-musl-cross.tgz

Move the extracted archive to wherever you would like to install the toolchain to. In these instructions it will simply be installed to the users documents folder.

The final step is to edit your .bashrc and add the following to the end:

# Path for or1k toolchain
export PATH="$PATH:/home/USER/Documents/or1k-linux-musl-cross/bin/"

After you've completed that you can close out the terminal and reopen it and proceed to the following instructions.

git clone https://github.com/crust-firmware/crust
cd crust
export CROSS_COMPILE=or1k-linux-musl-
make pinephone_defconfig
make -j$(nproc) scp
cp build/scp/scp.bin ../u-boot/
cd ..
If you do not wish to have Crust in your U-Boot build, then you can skip exporting SCP
cd u-boot/
git checkout crust
export CROSS_COMPILE=aarch64-linux-gnu-
export BL31=bl31.bin
export ARCH=arm64
export SCP=scp.bin
make distclean
make pinephone_defconfig
make all -j$(nproc)

U-Boot installation

Once successfully compiled you can proceed to flash the device

Warning: Replace [CHANGE THIS] with the location of your SD card and make sure you are using the proper location. Failure to do so can result in data loss.

sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/[CHANGE THIS] bs=1024 seek=8

If you are compiling U-Boot in order to overclock your DRAM you can check if it was successful by reading the values of /sys/kernel/debug/clk/clk_summary

p-boot multi-bootloader

One of the smallest and fastest PinePhone bootloaders, it was developed by Ondrej Jirman with the ability of booting multiple distributions on the PinePhone in mind.

More information can be found here

External Links

Sunxi U-Boot Wiki

U-Boot build instructions

or1k toolchain download