This is a page about the Rockchip RK3399 based ROCK Pi 4; ROCK-Pi-4.
Availability
Boards:
- ROCK PI 4 MODEL A 2GB at Digi-Key
- ROCK PI 4 MODEL B 1GB at Digi-Key
- ROCK PI 4 MODEL B 2GB at Digi-Key
- ROCK PI 4 MODEL B 4GB at Digi-Key
- HEATSINK FOR ROCK PI 4 at Digi-Key
Notes
Baud Rate 1500000
Vendor Documentation
- ROCK Pi 4: https://wiki.radxa.com/Rockpi4
Basic Requirements
- Running a recent supported release of Debian, Fedora or Ubuntu on a x86 64bit based PC; without OS Virtualization Software.
- Many of the listed commands assume /bin/bash as the default shell.
- ARM Cross Compiler – Linaro: https://www.linaro.org
- Linaro Toolchain Binaries: https://www.linaro.org/downloads/
- Bootloader
- Das U-Boot – the Universal Boot Loader: http://www.denx.de/wiki/U-Boot
- Source: https://github.com/u-boot/u-boot/
- Linux Kernel
- Linus’s Mainline tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
- arm64 based rootfs
- Debian: https://www.debian.org
ARM Cross Compiler: GCC
This is a pre-built (64bit) version of GCC that runs on generic linux, sorry (32bit) x86 users, it’s time to upgrade…
Download/Extract:
#user@localhost:~$
wget -c https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz
tar xf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz
export CC=`pwd`/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
Test Cross Compiler:
#user@localhost:~$
${CC}gcc --version
#Test Output:
aarch64-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ARM Secondary Cross Compiler: GCC
This is a pre-built (64bit) version of GCC that runs on generic linux, sorry (32bit) x86 users, it’s time to upgrade…
Download/Extract:
#user@localhost:~$
wget -c https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-arm-eabi.tar.xz
tar xf gcc-arm-8.3-2019.03-x86_64-arm-eabi.tar.xz
export M0_CROSS_COMPILE=`pwd`/gcc-arm-8.3-2019.03-x86_64-arm-eabi/bin/arm-eabi-
Test Secondary Cross Compiler:
#user@localhost:~$
${M0_CROSS_COMPILE}gcc --version
#Test Output:
arm-eabi-gcc (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Bootloader: Trusted Firmware A (TF-A)
Trusted Firmware A (TF-A): https://developer.trustedfirmware.org/dashboard/view/6/
Download:
#user@localhost:~$
git clone https://github.com/ARM-software/arm-trusted-firmware --depth=1
cd arm-trusted-firmware/
Configure and Build:
#user@localhost:~/arm-trusted-firmware$
make CROSS_COMPILE=${CC} realclean
make CROSS_COMPILE=${CC} PLAT=rk3399
Export BL31.elf:
#user@localhost:~/arm-trusted-firmware$
export BL31=`pwd`/build/rk3399/release/bl31/bl31.elf
Bootloader: U-Boot
Das U-Boot – the Universal Boot Loader: http://www.denx.de/wiki/U-Boot
Depending on your Linux Distrubution, you will also need a host gcc and other tools, so with Debian/Ubuntu start with installing the build-essential meta package.
Download:
#user@localhost:~$
git clone -b v2020.04-rc1 https://github.com/u-boot/u-boot --depth=1
cd u-boot/
Configure and Build:
#user@localhost:~/u-boot$
make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} rock-pi-4-rk3399_defconfig
make ARCH=arm CROSS_COMPILE=${CC}
Linux Kernel
This script will build the kernel, modules, device tree binaries and copy them to the deploy directory.
Download:
#user@localhost:~$
git clone https://github.com/RobertCNelson/rockchip-linux-dev ./kernelbuildscripts
cd kernelbuildscripts/
For v5.4.x (Longterm 5.4.x):
#user@localhost:~/kernelbuildscripts$
git checkout origin/v5.4.x -b tmp
Build:
#user@localhost:~/kernelbuildscripts$
./build_kernel.sh
Root File System
Debian 11
User | Password |
---|---|
debian | temppwd |
root | root |
Download:
#user@localhost:~$
wget -c https://rcn-ee.com/rootfs/eewiki/minfs/debian-11.3-minimal-arm64-2022-04-15.tar.xz
Verify:
#user@localhost:~$
sha256sum debian-11.3-minimal-arm64-2022-04-15.tar.xz
#sha256sum output:
f071f93722ea9916e5adde0a51c232fb40b74b4c0adc3d623beb991ad24055cf debian-11.3-minimal-arm64-2022-04-15.tar.xz
Extract:
#user@localhost:~$
tar xf debian-11.3-minimal-arm64-2022-04-15.tar.xz
Setup microSD card
We need to access the External Drive to be utilized by the target device. Run lsblk to help figure out what linux device has been reserved for your External Drive.
#Example: for DISK=/dev/sdX
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 465.3G 0 part / <- Development Machine Root Partition
sdb 8:16 1 962M 0 disk <- microSD/USB Storage Device
└─sdb1 8:17 1 961M 0 part <- microSD/USB Storage Partition
#Thus you would use:
export DISK=/dev/sdb
#Example: for DISK=/dev/mmcblkX
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 465.3G 0 part / <- Development Machine Root Partition
mmcblk0 179:0 0 962M 0 disk <- microSD/USB Storage Device
└─mmcblk0p1 179:1 0 961M 0 part <- microSD/USB Storage Partition
#Thus you would use:
export DISK=/dev/mmcblk0
Erase partition table/labels on microSD card:
sudo dd if=/dev/zero of=${DISK} bs=1M count=20
Install Bootloader:
#user@localhost:~$
sudo dd if=./idbloader.img of=${DISK} seek=64
sudo dd if=./u-boot.itb of=${DISK} seek=16384
Create Partition Layout:
With util-linux v2.26, sfdisk was rewritten and is now based on libfdisk.
#Check the version of sfdisk installed on your pc is atleast 2.26.x or newer.
sudo sfdisk --version
#Example Output
sfdisk from util-linux 2.27.1
#sfdisk >= 2.26.x
sudo sfdisk ${DISK} <<-__EOF__
16M,,L,*
__EOF__
Format Partition:
for: DISK=/dev/mmcblkX
sudo mkfs.ext4 -L rootfs ${DISK}p1
for: DISK=/dev/sdX
sudo mkfs.ext4 -L rootfs ${DISK}1
Mount Partition:
On most systems these partitions may be auto-mounted…
sudo mkdir -p /media/rootfs/
for: DISK=/dev/mmcblkX
sudo mount ${DISK}p1 /media/rootfs/
for: DISK=/dev/sdX
sudo mount ${DISK}1 /media/rootfs/
Install Kernel and Root File System
To help new users, since the kernel version can change on a daily basis. The kernel building scripts listed on this page will now give you a hint of what kernel version was built.
-----------------------------
Script Complete
eewiki.net: [user@localhost:~$ export kernel_version=5.X.Y-Z]
-----------------------------
Copy and paste that “export kernel_version=5.X.Y-Z” exactly as shown in your own build/desktop environment and hit enter to create an environment variable to be used later.
export kernel_version=5.X.Y-Z
Copy Root File System
#user@localhost:~$
sudo tar xfvp ./debian-*-*-arm64-*/arm64-rootfs-*.tar -C /media/rootfs/
sync
Setup extlinux.conf
#user@localhost:~$
sudo mkdir -p /media/rootfs/boot/extlinux/
sudo sh -c "echo 'label Linux ${kernel_version}' > /media/rootfs/boot/extlinux/extlinux.conf"
sudo sh -c "echo ' kernel /boot/vmlinuz-${kernel_version}' >> /media/rootfs/boot/extlinux/extlinux.conf"
sudo sh -c "echo ' append root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait quiet' >> /media/rootfs/boot/extlinux/extlinux.conf"
sudo sh -c "echo ' fdtdir /boot/dtbs/${kernel_version}/' >> /media/rootfs/boot/extlinux/extlinux.conf"
Copy Kernel Image
Kernel Image:
#user@localhost:~$
sudo cp -v ./kernelbuildscripts/deploy/${kernel_version}.Image /media/rootfs/boot/vmlinuz-${kernel_version}
Copy Kernel Device Tree Binaries
#user@localhost:~$
sudo mkdir -p /media/rootfs/boot/dtbs/${kernel_version}/
sudo tar xfv ./kernelbuildscripts/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/
Copy Kernel Modules
#user@localhost:~$
sudo tar xfv ./kernelbuildscripts/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/
File Systems Table (/etc/fstab)
#user@localhost:~/$
sudo sh -c "echo '/dev/mmcblk1p1 / auto errors=remount-ro 0 1' >> /media/rootfs/etc/fstab"
Remove microSD/SD card
sync
sudo umount /media/rootfs
Comments
Any questions or comments please go to our TechForum: TechForum