User:PeterL/Rockpro64

From Gentoo Wiki
Jump to:navigation Jump to:search

Hardware

Board

PINE64 ROCKPro64 — a Rockchip RK3399 (ARMv8-A, Cortex-A72/A53 big.LITTLE) based, exceptionally libre software friendly SBC.

Serial comms

I'm using a C232HD DDHSP-0 - FTDI based USB -> Serial (3.3v) connector

Connected GND (black) to pin 6 and (yellow) Rx (i.e. RockPro64 Tx) to pin 8. RockPro64 Wiki

This is just to monitor when things go wrong.

Note: If build of Das U-boot is successful, it should be possible to use Monitor and Keyboard if U-Boot fails to boot the kernel.

To talk to U-boot using the serial interface, also connect pin 10 to Tx (Orange), but only after powered up and starting of U-boot as there seems to be an issue if connected before.

USB to serial adapter — details the process of enabling support for USB to serial (RS-232, RS-422, RS-485 etc) adapters in the Linux kernel.

Build Environment

Creating Gentoo env on Arch Linux

Skip this section if not relevant to you..

Laptop has Arch Linux installed - coming from Arch Linux..

Create a chroot gentoo env

root #mkdir /mnt/gentoo
root #cd /mnt/gentoo
root #tar -xpf ~/Download/stage3-amd64-20120621.tar.bz2
root #cd usr
root #tar -xpf ~/Download/portage-latest.tar.xz
root #cp /etc/resolv.conf /mnt/gentoo/etc/

Mount necessary partitions for Gentoo chroot env, only do this once after each laptop restart

root #mount -types proc /proc /mnt/gentoo/proc
root #mount --rbind /sys /mnt/gentoo/sys
root #mount --make-rslave /mnt/gentoo/sys
root #mount --rbind /dev /mnt/gentoo/dev
root #mount --make-rslave /mnt/gentoo/dev
root #mount --bind /run /mnt/gentoo/run
root #mount --make-slave /mnt/gentoo/run

Chroot into Gentoo env, each time I need to switch to Gentoo env

root #chroot /mnt/gentoo /bin/bash

First time do this...

root #source /etc/profile
root #export PS1="(chroot) ${PS1}"
root #cd ~

Then create a .bashrc with the above commands to avoid repeating next time

Once only - set up portage - standard stuff..

root #mkdir /etc/portage/repos.conf
root #cp /usr/share/portage/config/repos.conf /mnt/rpi/etc/portage/repos.conf/gentoo.conf
root #emerge-websync
root #eselect profile list/set
root #eselect locale list/set

Setup cross-compiler in chroot Gentoo env on Arch Linux

Cross build environment — provides instructions on creating a cross build environment using crossdev.

root #emerge --ask sys-devel/crossdev

Create a separate ebuild repositry as per link above, reminds below..

root #mkdir -p /var/db/repos/crossdev/{profiles,metadata}
root #echo 'crossdev' > /var/db/repos/crossdev/profiles/repo_name
root #echo 'masters = gentoo' > /var/db/repos/crossdev/metadata/layout.conf
root #chown -R portage:portage /var/db/repos/crossdev
root #vim /etc/portage/repos.conf/crossdev.conf

Alternative (need to check this out)?

root #eselect repository create crossdev


Build Arm64 tool chain

root #crossdev -t aarch64-unknown-linux-gnu

Create a user in chroot env

RockPro64 installation steps

From the factory nothing stored in SPI flash. I don't have eMMC, just a 32G SD-Card..

Step 1 build das U-boot

Useful links:


Install Software required for building U-boot

Device tree compiler

root #emerge --ask sys-apps/dtc

Das U-Boot tools

root #emerge --ask dev-embedded/u-boot-tools

Kernel sources

root #emerge --ask sys-kernel/gentoo-sources

Das U-Boot

Arm trusted firmware (ATF)

Build

user $cd arm-trusted-firmware
user $make CROSS_COMPILE=aarch64-unknown-linux-gnu- PLAT=rk3399
user $export BL31=path/to/arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf
user $cd ..
user $cd u_boot
user $make CROSS_COMPILE=aarch64-unknown-linux-gnu- rockpro64-rk3399_defconfig
user $make CROSS_COMPILE=aarch64-unknown-linux-gnu- menuconfig
user $make CROSS_COMPILE=aarch64-unknown-linux-gnu-

Das U-Boot menuconfig is like kernel menuconfig, so you can modify the build config.

ideas I want to try are:

  • Changing location of U-Boot / ATF as it needs to be at offset 16384 x block size in SD-Card which seems lot of space wasted at start of SD-CARD?
  • Remove Network bootloading functionality (don't need this)


Result should be two files idbloader.img & u_boot.itb

Item Contents SD location
idbloader.img TPL & SPL LBA 64
u_boot_itb U-Boot & ATF LBA 16384

see Boot Sequence for details of boot sequence, but in summary ROM code -> TPL -> Rom Code -> SPL -> ATF -> U-Boot

For future reference a defconfig can be saved like so

user $cd u_boot
user $make CROSS_COMPILE=aarch64-unknown-linux-gnu- savedefconfig
user $cp defconfig my_rockpro64-rk3399_defconfig

My latest defconfig can downloaded from guthub using

Step 2 Format SD-Card

Format the SD-CARD with GPT (see Handbook:AMD64/Installation/Disks), but importantly, allowing enough freespace after the GPT before the first partition for U-Boot images.

dev names are those seen when mounted on rockpro64. For MMC devices, eMMC = 0, SD-CARD = 1

Device on RockPro64 mount point Start Sectors Type Comment
/dev/mmcblk1p1 /boot 32768 376832 EFI System Must start after the u_boot.itb
/dev/mmcblk1p2 / 409600 45146112 Linux filesystem Standard Rootfs, aligned for best SD performance
/dev/mmcblk1p3 N/A 45555712 16778207 Linux Swap 8G of Swap

Note: device name depends on the host PC; for me they are sdbX on my laptop

Note: Normal GPT block ends at LBA 63 so avoid exceeding this.

Use dd to place idloader.img & u_boot.itb at the necessary sector/Block address like so.

root #dd if=xxx of=/dev/mmcblk0 seek=yyy

xxx is the image, yyy is 64 or 16384

Create the other filesystems in the normal way, use FAT 32 for the boot to comply to EFI. I used ext4 for the Root, but pick your favourite.

Step 3 Install stage3

Get stage3 for the Arm64 "stage3-arm64-openrc-xxx.tar.bz2

Mount sd card root parition and untar stage3, standard stuff (see elsewhere for details)..::

root #mount /dev/sdb2 /mnt/rockpro
root #mount /dev/sdb1 /mnt/rockpro/boot
root #tar -xpf stage3-xxx -C /mnt/rockpro

Get portage portage-latest.tar.bz2

unzip, standard stuff (see elsewhere for details)..::

root #tar -xpf portage-latest.tar.bz2 -C /mnt/rockpro/usr
root #mkdir /mnt/rockpro/etc/portage/repos.conf
root #cp /mnt/rpi/usr/share/portage/config/repos.conf /mnt/rpi/etc/portage/repos.conf/gentoo

Step 4 Build Kernel

First get latest standard kernel source like so:

root #emerge --ask sys-kernel/gentoo-sources

Obtain a kernel build configuration for the rockpro64 platform. I originally started with a known working distro see RockPro64 Wiki

My latest config can be downloaded from

and is called rockpro64_linux_config. Make a Symlink

user $ln -s /usr/src/linux-5.16.16-gentoo /usr/src/linux

. The exact path depends on the version of linux source installed.

Copy the default config to "/usr/src/linux/arch/arm64/configs".

change to directory of the kernel sources "/usr/src/linux" and run the usually commands to cross-compile the kernel like so:

user $make ARCH=arm64 rockpro64_linux_defconfig
user $make ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- oldconfig
user $make ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu- menuconfig
user $make ARCH=arm64 CROSS_COMPILE=armv6j-unknown-linux-gnu-

where menuconfig can be used to tweak the build configuration.

The configuration can be saved for future reference like so

user $make CROSS_COMPILE=aarch64-unknown-linux-gnu- savedefconfig
user $cp defconfig my_rockpro64_linux_defconfig

Step 5 Install kernel & U-boot script

  • TODO: Copy dtb and kernel to boot parition

The following boot.cmd file was created

FILE boot.cmd
setenv rootdev "/dev/mmcblk1p2"
setenv rootfstype "ext4"
setenv console "console=tty1 console=ttyS2,1500000"

setenv bootargs "root=${rootdev} rootwait rootfstype=${rootfstype} ${console}"

load ${devtype} ${devnum} ${kernel_addr_r} kernel.img
load ${devtype} ${devnum} ${fdt_addr_r} rk3399-rockpro64.dtb

booti ${kernel_addr_r} - ${fdt_addr_r}

Note: Change where applicable. e.g. if kernel image or root filesystem is different or kernel cmdline is different

Use mkimage from u-boot-tools to compile to a script for Das U-Boot

user $mkimage -C none -A arm -T script -d boot.cmd boot.scr

Copy boot.scr to the boot partition of sd-card.

Step 6 Boot the board

  • TODO: issues see, plus solutions...

RockPro64 Additional software, etc

  • TODO: