Kernel Development
Using bsp
bsp is a set of tools provided by Radxa to quickly build U-Boot Kernels. It is very easy to build your own U-Boot and Kernel with bsp.
The following shows you how to build a kernel with bsp using Radxa ROCK 5B as an example.
bsp environment configuration
The following is the recommended environment for bsp.
Hardware: x86_64 PC recommended
System: Ubuntu 22.04 or Debian 12
Install dependencies
sudo apt update
sudo apt install -y git qemu-user-static binfmt-support
# Podman (recommended)
sudo apt install -y podman podman-docker
sudo touch /etc/containers/nodocker
# Docker
# sudo apt install docker.io
# Optional dependencies for minor features
sudo apt install -y systemd-container
Getting the code
bsp uses the git submodule. Therefore, use the following command to get the code:
git clone --recurse-submodules https://github.com/radxa-repo/bsp.git
Understanding bsp usage
Once you have the bsp code on your machine, you can run bsp to see the built-in help:
cd bsp
./bsp
Build the kernel
Running ./bsp will show you all the arguments and their explanations, and the command bsp [options] <linux|u-boot> <profile> [product] will be available at the prompt.
Taking Radxa ROCK 5B as an example, the linux profile is "rk2410". The following are profiles for other products:
| product | profile | product | profile | product | profile | product | profile |
|---|---|---|---|---|---|---|---|
| rock-4se | rockchip | radxa-cm3-io | rk356x | radxa-zero | stable | rock-5a | rk2410 |
| rock-pi-4a-plus | rockchip | radxa-cm3-rpi-cm4-io | rk356x | radxa-zero-2pro | stable | rock-5b | rk2410 |
| rock-pi-4b-plus | rockchip | radxa-cm3-sodimm-io | rk356x | rock-s0 | stable | rock-5b-plus | rk2410 |
| rock-4c-plus | rockchip | radxa-cm3i-io | rk356x | rock-pi-s | stable | rock-5c | rk2410 |
| rock-pi-4a | rockchip | radxa-cm3j-rpi-cm4-io | rk356x | rock-pi-n10 | stable | rock-5d | rk2410 |
| rock-pi-4b | rockchip | radxa-e23 | rk356x | rock-pi-e | stable | rock-5t | rk2410 |
| rock-pi-4c | rockchip | radxa-e25 | rk356x | rock-5-itx | rk2410 | ||
| rock-4-core-io | rockchip | radxa-zero3 | rk356x | radxa-e52c | rk2410 | ||
| rock-3a | rk356x | radxa-e54c | rk2410 | ||||
| rock-3b | rk356x | radxa-nx5-io | rk2410 | ||||
| rock-3c | rk356x | radxa-cm4-rpi-cm4-io | rk2410 | ||||
| rock-2 | rk356x | radxa-cm5-io | rk2410 | ||||
| radxa-cm5-rpi-cm4-io | rk2410 | ||||||
| radxa-rk3576 | rk2410 |
If the product model is not found in the table, select the corresponding option based on your product's SoC model.
Example: Radxa CM4 / NX4 and ROCK 4D use the Rockchip RK3576 SoC. According to the table, select rk2410 as the profile parameter for radxa-rk3576.
Then fill in the profile parameter of the bsp command with the product's corresponding profile: rk2410 to pull and configure the code, for example:
./bsp linux rk2410 --no-build
# `--no-build` only configure the code without compile
The path to the kernel source code is located in .src/linux in the bsp directory, and the kernel can be built again after modifying the kernel source code:
cd bsp
./bsp --no-prepare-source linux rk2410 -r 999
# Parameter description:
# `--no-prepare-source` # This parameter is not needed for first time compilation, it is added to compile with local modifications, if this parameter is not added, the latest code will be synchronized from the Radxa kernel repository and overwrite the local modifications.
# `-r 999` # Specify the kernel version as 999 for priority use.
After compilation, a number of deb packages will be generated in the current directory, you only need to install the following two deb packages
The software package file name will change according to the parameters of propile and -r
linux-headers-6.1.84-999-rk2410_6.1.84-999_arm64.deb
linux-image-6.1.84-999-rk2410_6.1.84-999_arm64.deb
Copy the above two deb packages to the board and install them with the dpkg command to complete the kernel installation
sudo dpkg -i linux-headers-6.1.84-999-rk2410_6.1.84-999_arm64.deb
sudo dpkg -i linux-image-6.1.84-999-rk2410_6.1.84-999_arm64.deb
sudo reboot
After the reboot is complete, you can check if the installation was successful by checking the version number of the currently booted kernel with uname -a.
Build an out-of-tree kernel module
If you only need to verify a custom driver, you do not need to rebuild the entire kernel. First use bsp to fetch and configure the kernel source for the target board, then create a minimal Makefile in the driver directory:
obj-m += my_driver.o
Put my_driver.c and Makefile in the same directory, then run the following commands in the host bsp build environment:
cd /path/to/bsp
./bsp linux rk2410 --no-build
cd /path/to/your-driver
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
-C /path/to/bsp/.src/linux M=$PWD modules
After the build completes, my_driver.ko will be generated in the driver directory. Copy it to the board and use insmod to load it temporarily for verification:
scp my_driver.ko user@board:/tmp/
ssh user@board
sudo insmod /tmp/my_driver.ko
You can also generate and install the linux-headers package using the steps above, then build the module directly on the board:
make -C /lib/modules/$(uname -r)/build M=$PWD modules
The kernel running on the board must exactly match the kernel and headers used to build the module. Otherwise, loading the module may fail because of a version magic mismatch. If you modify the kernel source under bsp/.src/linux, keep the --no-prepare-source option when rebuilding; otherwise, bsp may synchronize the remote source and overwrite your local changes.
Compile manually
bsp is the only compilation method currently being maintained, and it makes additional changes to the source code when compiling.
If you want to develop based on our officially released software, you should at least use bsp to download and configure the code.
If you want to build with a custom make command, please refer to the Prepare working tree section to configure the code.