PINE64
Manual: Howto cross-compile Upstream U-Boot for rock64 - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: ROCK64 (https://forum.pine64.org/forumdisplay.php?fid=85)
+--- Forum: Rock64 Tutorials (https://forum.pine64.org/forumdisplay.php?fid=90)
+--- Thread: Manual: Howto cross-compile Upstream U-Boot for rock64 (/showthread.php?tid=8174)



Manual: Howto cross-compile Upstream U-Boot for rock64 - rock7 - 11-02-2019

Step 1: Get the file bl31.elf
You can build ATF with Upstream arm-trusted-firmware repository to get the file “bl31.elf” (Way 1) or you use the rk322xh_bl31_vXXX.elf file from rockchip rkbin repository (Way 2)

Way 1 (build ATF with Upstream arm-trusted-firmware repository to get “bl31.elf”)
Install the required packages (Debian / Ubuntu):
Code:
sudo apt-get install --no-install-suggests --no-install-recommends device-tree-compiler build-essential gcc make git libssl-dev

To cross-compile:
Code:
sudo apt-get install --no-install-suggests --no-install-recommends cpp-10-aarch64-linux-gnu gcc-10-aarch64-linux-gnu gcc-10-aarch64-linux-gnu-base libasan6-arm64-cross libatomic1-arm64-cross libc6-arm64-cross libgcc-10-dev-arm64-cross libgcc-s1-arm64-cross libgomp1-arm64-cross libitm1-arm64-cross liblsan0-arm64-cross libstdc++6-arm64-cross libtsan0-arm64-cross libubsan1-arm64-cross cpp-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu gcc-10-cross-base

Go into your Download folder and open Terminal there, then run:
Code:
git clone https://github.com/ARM-software/arm-trusted-firmware
cd arm-trusted-firmware

Optional 4:
Verify code archive integrity (see also: https://restic.net/blog/2015-09-16/verifying-code-archive-integrity ).
  • Replace in the following Y.Y with the tag version number

Download pgp-key from the developer (you can find the gpg key ID on https://github.com/ARM-software/arm-trusted-firmware/tags) who has signed the tag, check fingerprints, import key and verify tag: Go into arm-trusted-firmware folder and run the following command and verify the fingerprint:
Code:
git tag --verify vY.Y

Now create a archive that contain the same repository as the release with the tag version, run in arm-trusted-firmware folder the following command:
Code:
git archive --format=tar --prefix=arm-trusted-firmware-Y.Y/ vY.Y | gzip -n > arm-trusted-firmware-Y.Y.tar.gz

Show the sha256 checksum from the archive that contain the repository from the release with the tag version and show sha256 checksum from the same archive https://github.com/ARM-software/arm-trusted-firmware/archiv/vY.Y.tar.gz which belongs to the tag and compare the checksums:
Code:
sha256sum arm-trusted-firmware-Y.Y.tar.gz
Code:
curl -s -L https://github.com/ARM-software/arm-trusted-firmware/archiv/vY.Y.tar.gz | sha256sum

End of the optional section 4

Code:
cd arm-trusted-firmware
make CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3328 DEBUG=1 bl31 ERRATA_A53_836870 ERRATA_A53_1530924

Software Developers Errata Notice: developer.arm.com/documentation/epm048406/2100/

Go into your Download folder and open Terminal, then run:
Code:
git clone git://git.denx.de/u-boot.git
or Download U-Boot source tree from https://ftp.denx.de/pub/u-boot/
(How to verify downloaded file with .sig file: https://stackoverflow.com/questions/15331015/how-to-verify-downloaded-file-with-sig-file )

Search now the “bl31.elf” file in the arm-trusted-firmware build folder and copy it in the U-Boot folder.

Way 2 (use “bl31.elf” file from rockchip rkbin repository)
Go into your Download folder and open Terminal, then run:
Code:
git clone git://git.denx.de/u-boot.git
or Download U-Boot source tree from ftp://ftp.denx.de/pub/u-boot/
(How to verify downloaded file with .sig file: https://stackoverflow.com/questions/15331015/how-to-verify-downloaded-file-with-sig-file )

Go back into your Download folder and open Terminal, then run:
Code:
git clone https://github.com/rockchip-linux/rkbin
cd rkbin

Search the file „rk322xh_bl31_vX.XX.elf“ in the rkbin folder (current version is v1.42, this file is in bin/rk33/) and change the name of this file to „bl31.elf“ and copy it in the U-Boot folder.

Step 2:
Compile U-Boot Install the required packages (for latest Debian):
Code:
sudo apt-get install --no-install-suggests --no-install-recommends bison dh-python flex gcc-10 libexpat1-dev libmpdec3 make mime-support swig4.0 u-boot-tools cpp-10 libpython3.9-stdlib libpython3.9-dev libpython3.9-minimal libpython3.9 python3.9 python3.9-minimal python3-distutils python3-lib2to3 python3-pkg-resources python3-setuptools python-pip-whl python3-pip python3.9-dev device-tree-compiler build-essential git libssl-dev

To cross-compile:
Code:
sudo apt-get install --no-install-suggests --no-install-recommends cpp-10-aarch64-linux-gnu gcc-10-aarch64-linux-gnu gcc-10-aarch64-linux-gnu-base libasan6-arm64-cross libc6-arm64-cross libgcc-10-dev-arm64-cross libgcc-s1-arm64-cross libgomp1-arm64-cross libitm1-arm64-cross liblsan0-arm64-cross libstdc++6-arm64-cross libtsan0-arm64-cross libubsan1-arm64-cross cpp-aarch64-linux-gnu gcc-aarch64-linux-gnu gcc-10-cross-base libatomic1-arm64-cross swig
Code:
cd u-boot
make CROSS_COMPILE=aarch64-linux-gnu- BL31=bl31.elf rock64-rk3328_defconfig
Code:
make CROSS_COMPILE=aarch64-linux-gnu- BL31=bl31.elf all

Flash U-Boot to microSD card Create partition with fdisk:
(replace sda1 with the name of your microSD card with number (you can find it with fdisk -l))
Code:
sudo umount /dev/sda1
(replace sda with the name of your microSD card but now in the following without number (you can find it with fdisk -l))

Code:
sudo fdisk /dev/sda
d
o
n
Enter
Enter
Enter
First sector (2048-62333951, default 2048): 32768
Enter
w
sudo mkfs.ext4 /dev/sda1 (with number!)
Code:
sudo fdisk /dev/sda
p
Quote:At “Boot” must be a * if there is not a * then press “a” and then “w”
Code:
w
End of fdisk instructions.

Now run this command:
Code:
sudo umount /dev/sda1
Quote:Replace sda1 with the name of your microSD (with number at the end)

Open Terminal in the U-Boot folder and flash U-Boot to microSD card with following commands (you can find the name of your microSD card with e.g. gparted, we search for example /dev/sda (without number! not /dev/sda1)):
Code:
sudo dd if=./idbloader.img of=/dev/sda seek=64
sudo dd if=./u-boot.itb of=/dev/sda seek=16384


MIT License: https://avg7.de/forum/sicheres-alpine-linux-betriebs-system-usb-stick-speicherkarte/#kopierrechte
Copyright © 2023 AVG7.de


RE: Manual: Howto cross-compile Upstream U-Boot for rock64 - kuleszdl - 03-20-2020

Thank you for sharing, the guide looks very promising!

Just one question: Does the u-boot obtained in this process also work from SPI flash or only from microsd? I tried flashing the precompiled uboot from ArchLinuxArm, but it fails with loading the ARM trusted firmware as it seems:

Code:
LoadTrustBL
LoadTrustBL error: -1



RE: Manual: Howto cross-compile Upstream U-Boot for rock64 - kuleszdl - 03-21-2020

@rock7 I followed your steps and successfully built everything using the upstream arm-trusted-firmware repository. However, it seems like my u-boot does not recognize sdcards:

Code:
Trying to boot from MMC1
Card did not respond to voltage select!
spl: mmc init failed with error: -95
Trying to boot from MMC2
...
I tried playing around with some of the config options as well as different mainline u-boot versions.
Does booting work for you?


RE: Manual: Howto cross-compile Upstream U-Boot for rock64 - rock7 - 04-15-2020

(03-20-2020, 05:41 PM)kuleszdl Wrote: Thank you for sharing, the guide looks very promising!

Just one question: Does the u-boot obtained in this process also work from SPI flash or only from microsd? I tried flashing the precompiled uboot from ArchLinuxArm, but it fails with loading the ARM trusted firmware as it seems:

Code:
LoadTrustBL
LoadTrustBL error: -1

I haven't tried it yet with SPI flash, you can follow this guide: https://github.com/ayufan-rock64/linux-build/blob/master/recipes/flash-spi.md

(03-21-2020, 12:11 PM)kuleszdl Wrote: @rock7 I followed your steps and successfully built everything using the upstream arm-trusted-firmware repository. However, it seems like my u-boot does not recognize sdcards:

Code:
Trying to boot from MMC1
Card did not respond to voltage select!
spl: mmc init failed with error: -95
Trying to boot from MMC2
...
I tried playing around with some of the config options as well as different mainline u-boot versions.
Does booting work for you?
If this problem occurs, just restart. It rarely happens, I don't know why it happens yet.