Rockpi4/dev/Debian
ROCK Pi 4 > Development > Build Debian
Contents
- 1 Rockchip Debian SDK
- 2 build deban11 armhf image with a existed image
- 2.1 Flash a debian11 arm64 image to a sd card or a emmc module
- 2.2 Insert the SD card or emmc that has been burned into the image to the local computer and mount it
- 2.3 Go to the root file system, back up the boot directory, delete and replace the root file system, and restore the boot directory to the root file system
- 2.4 Umount the sd card or the emmc, then boot up
- 2.5 After the system start, Check whether rootfs is armhf (32-bit)
- 2.6 Check whether the tool is 32-bit. If not, uninstall the tool and reinstall it
- 3 FAQs
- 4 Troubleshooting
Rockchip Debian SDK
Below is the instructions of how to build image for ROCK Pi 4 on a HOST PC.
Get the source code
You need Git to get multiple git repositories to build the image.
Install Git if you don't have it.
sudo apt-get update sudo apt-get install git
Clone the source code
git clone -b master https://github.com/radxa/rockchip-bsp.git cd rockchip-bsp git submodule init git submodule update
You will get
build kernel README.md rkbin rootfs u-boot
Directories usage introductions:
- build:
- Some script files and configuration files for building u-boot, kernel and rootfs.
- kernel:
- kernel source code, current version is 4.4
- rkbin:
- Prebuilt Rockchip binaries, include first stage loader and ATF(Arm Trustzone Firmware).
- rootfs:
- Bootstrap a Debian based rootfs, support architechture armhf and arm64, support Debian Jessie, Stretch and Buster.
- u-boot:
- u-boot as the second stage bootloader
Update the source code
The rockchip-bsp will be updated all the time, so you can update the source before building the system image.
cd rockchip-bsp git checkout master git fetch origin git rebase origin/master git submodule update
Install toolchain from Linaro
wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz -C /usr/local/ export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- export PATH=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:$PATH
Check if Linaro toolchain is the default choice:
which aarch64-linux-gnu-gcc /usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
Install other build tools
sudo apt-get install gcc-aarch64-linux-gnu device-tree-compiler libncurses5 libncurses5-dev build-essential libssl-dev mtools sudo apt-get install bc python dosfstools
If it appears that it cannot be installed. You can try the following method
sudo apt-get install aptitude sudo aptitude install bc python dosfstools
Build u-boot
./build/mk-uboot.sh rk3399-rock-pi-4b #For ROCK Pi 4 Mode B
The generated images will be copied to out/u-boot folder
ls out/u-boot/ idbloader.img rk3399_loader_v1.12.112.bin trust.img uboot.img
Build kernel
Build kernel with default rockchip_linux_defconfig
./build/mk-kernel.sh rk3399-rock-pi-4b #For ROCK Pi 4 Mode B
Change kernel config(optional)
Optionally, if you want to change the default kernel config
cd kernel export ARCH=arm64 export CROSS_COMPILE=aarch64-linux-gnu- make rockchip_linux_defconfig make menuconfig make savedefconfig cp defconfig arch/arm64/configs/rockchip_linux_defconfig cd .. ./build/mk-kernel.sh rk3399-rock-pi-4b #For ROCK Pi 4 Mode B
You will get the kernel image and dtb file
ls out/kernel/ Image rk3399-rock-pi-4b.dtb
Make rootfs image
Check out the rootfs source. The repository is https://github.com/radxa/rk-rootfs-build.git and the branch is debian.
To build 32bit rootfs:
export ARCH=armhf
To build 64bit rootfs:
export ARCH=arm64
Building a base debian system by ubuntu-build-service from linaro.
cd rootfs sudo apt-get install binfmt-support qemu-user-static cpio gdisk sudo dpkg -i ubuntu-build-service/packages/* # ignore the broken dependencies, we will fix it next step sudo apt-get install -f RELEASE=buster TARGET=desktop ARCH=arm64 ./mk-base-debian.sh
This will bootstrap a Debian Buster image, you will get a rootfs tarball named linaro-buster-alip-xxxx.tar.gz.
Building the rk-debian rootfs.
RELEASE=buster ARCH=arm64 ./mk-rootfs.sh
Creating the ext4 image(linaro-rootfs.img):
./mk-image.sh
Combine everything into one image
build/mk-image.sh -c rk3399 -b rk3399-rock-pi-4b -t system -r rootfs/linaro-rootfs.img
This will combine u-boot, kernel and rootfs into one image and generate GPT partition table. Output is
out/system.img
Flash the image
For normal users, follow instructions here. You will need the generated out/system.img only.
For developers, flash from USB OTG port, follow instructions here. You will need the flash helper rk3399_loader_xxx.bin and generated out/system.img files.
build deban11 armhf image with a existed image
Flash a debian11 arm64 image to a sd card or a emmc module
Insert the SD card or emmc that has been burned into the image to the local computer and mount it
``` sudo blkid /dev/sdb2 /dev/sdb2: LABEL="rootfs" UUID="8bf96d05-7c97-42fc-863c-95e3e7603ef4" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="rootfs" PARTUUID="474d4c1f-53da-447c-bab4-334abe0d5753" nasca@nasca-H4:~$ sudo blkid /dev/sdb1 /dev/sdb1: LABEL_FATBOOT="config" LABEL="config" UUID="4AD5-9369" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="config" PARTUUID="8d24a074-ea49-4d24-a17c-82dd88776fa2"
lsblk
... ... sdb 8:16 1 29.3G 0 disk ├─sdb1 8:17 1 16M 0 part └─sdb2 8:18 1 5.1G 0 part
sudo mount /dev/sdb2 /data2 cd /data2
```
Go to the root file system, back up the boot directory, delete and replace the root file system, and restore the boot directory to the root file system
``` radxa@radxa:/data2$ sudo cp -r ./boot ~/ radxa@radxa:/data2$ sudo rm -rf * radxa@radxa:/data2$ sudo cp -av ~/pro/rootfs/* ./ radxa@radxa:/data2$ sudo cp -av ~/boot/* ./boot/
radxa@radxa:/data2$ sudo cat ./etc/fstab
- UNCONFIGURED FSTAB FOR BASE SYSTEM
//Replace the uuid in the preceding section radxa@radxa:/data2$ sudo cat ./etc/fstab
- UNCONFIGURED FSTAB FOR BASE SYSTEM
UUID=8bf96d05-7c97-42fc-863c-95e3e7603ef4 / ext4 defaults 0 1 UUID=4AD5-9369 /config vfat defaults,x-systemd.automount 0 2
```
Umount the sd card or the emmc, then boot up
``` radxa@radxa:/data2$ cd radxa@radxa:~$ sudo umount /data2 ```
After the system start, Check whether rootfs is armhf (32-bit)
``` radxa@rock-4c-plus:~$ sudo apt-get install file -y Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed:
libmagic-mgc libmagic1
The following NEW packages will be installed:
file libmagic-mgc libmagic1
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 458 kB of archives. After this operation, 7003 kB of additional disk space will be used. Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main armhf libmagic-mgc armhf 1:5.39-3 [273 kB] Get:2 http://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main armhf libmagic1 armhf 1:5.39-3 [117 kB] Get:3 http://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main armhf file armhf 1:5.39-3 [68.1 kB] Fetched 458 kB in 1s (453 kB/s) Selecting previously unselected package libmagic-mgc. (Reading database ... 17491 files and directories currently installed.) Preparing to unpack .../libmagic-mgc_1%3a5.39-3_armhf.deb ... Unpacking libmagic-mgc (1:5.39-3) ... Selecting previously unselected package libmagic1:armhf. Preparing to unpack .../libmagic1_1%3a5.39-3_armhf.deb ... Unpacking libmagic1:armhf (1:5.39-3) ... Selecting previously unselected package file. Preparing to unpack .../file_1%3a5.39-3_armhf.deb ... Unpacking file (1:5.39-3) ... Setting up libmagic-mgc (1:5.39-3) ... Setting up libmagic1:armhf (1:5.39-3) ... Setting up file (1:5.39-3) ... Processing triggers for libc-bin (2.31-13+deb11u5) ...
radxa@rock-4c-plus:~$ file /bin/ls /bin/ls: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, Buildd radxa@rock-4c-plus:~$ ```
Check whether the tool is 32-bit. If not, uninstall the tool and reinstall it
FAQs
1.For system image built from rockchip-bsp, what is the user name and password?
The user name is linaro and the password is linaro.
2.How to build on RK3399 Fuhai u-boot and kernel?
U-boot:
./build/mk-uboot.sh rk3399-fuhai
Kernel:
./build/mk-kernel.sh rk3399-fuhai
Troubleshooting
Check ROCK Pi 4 FAQs first, if it doesn't help, start a new post on the forum https://forum.radxa.com/c/dev