User:Brendlefly62/Rockchip RK3588S Rock 5c/Build-Install-Kernel
Build your own kernel
Currently, there IS upstream support for this board in Linux kernel and u-boot sources developed by Radxa, but they are not up to date, and may not be fully functional. To avoid frustration, the "completely from sources" method described further below is not recommended. However, there is mainstream support for the Rock 5c in Armbian, and it is relatively easy to use the Armbian build tools to build just the kernel, using a method very similar to that described for building u-boot, above. Of course, the same tool can be used to create an image for a fully working system, and the root filesystem can then be replaced to produce a working Gentoo system. See above.
Armbian's build script is supported by its developers only on Ubuntu. If an Ubuntu system is not available, it is easy to generate one in a Virtualbox Vm, as described [in this youtube video].
To use Armbian's build script to build just the kernel, first follow this basic outline to create a fresh workspace --
Use armbian/build
Start fresh
user $
cd ~/armbian
user $
sudo rm -r build/ ### start fresh
user $
git clone --depth=1 --branch=main https://github.com/armbian/build
If you already have a working system, you can use that current system's running config as a kernel-seed --
Use a kernel "seed"
user $
mv /media/host-share/${board}/<current-running-config> .
user $
cd build/
user $
mkdir userpatches
user $
board=rock-5c
user $
branch=edge ### as of 8/10/2024 this will produce kernel version 6.10.3
user $
# if updating kernel for a working system, copy the working kernel's config (as a "seed") into Armbian's "build/userpatches/" directory
user $
cp ../<current-running-config> userpatches/linux-rk35xx-edge.config
Note that the name "linux-rk35xx-edge.config" reflects the branch chosen, it will be different if the branch is "current" or "vendor" or "main" for example.
Now configure the kernel with Linux "menuconfig" using the "seed" as a start point --
Prepare to Configure the kernel
* Custom initramfs and DM Crypt settings may be needed
- If you are building the system with a custom initramfs that employs luks encryption and lvm volumes to assemble the rootfs, then please pay attention to the associated kernel configuration requirements explained in these Gentoo wiki articles -- DM_Crypt, Custom Initramfs.
- Additionally, the defconfig for Rock 5c seems to start with native language setting configured for chinese, so that should be changed if another lanuage is preferred (for example) --
File Systems ---> DOS/FAT/EXFAT/NT Filesystems ---> <*> MSDOS fs support Search for <code>CONFIG_MSDOS_FS</code> to find this item. <*> VFAT (Windows-95) support Search for <code>CONFIG_VFAT_FS</code> to find this item. (437) Default Codepage for FAT Search for <code>CONFIG_FAT_DEFAULT_CODEPAGE</code> to find this item. (iso8859-1) Default iocharset for FAT Search for <code>CONFIG_FAT_DEFAULT_IOCHARSET</code> to find this item. -*- Native Language Support Search for <code>CONFIG_NLS</code> to find this item. ---> (utf9) Default NLS Option Search for <code>CONFIG_NLS_DEFAULT</code> to find this item. <*> Codepage 437(United States, Canada) Search for <code>CONFIG_NLS_CODEPAGE_437</code> to find this item. <*> ASCII (United States) Search for <code>CONFIG_NLS_ASCII</code> to find this item. <*> NLS ISO 8859-1 (Latin 1; Western European Languages Search for <code>CONFIG_NLS_ISO8859_1</code> to find this item. <*> NLS UTF-8 Search for <code>CONFIG_NLS_UTF8</code> to find this item.(See also DM_Crypt, Custom Initramfs)
Configure the Kernel
Apply settings needed, such as noted above, when the interactive menuconfig interface appears after running this command --
user $
./compile.sh kernel-config SHARE_LOG='yes' ARTIFACT_IGNORE_CACHE='yes' BOARD=$board BRANCH=$branch BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy
[πΏ] Applying cmdline param [ 'BUILD_MINIMAL': '(unset)' --> 'yes' early ] [πΏ] Applying cmdline param [ 'ARTIFACT_IGNORE_CACHE': '(unset)' --> 'yes' early ] [πΏ] Applying cmdline param [ 'BUILD_DESKTOP': '(unset)' --> 'no' early ] [πΏ] Applying cmdline param [ 'BRANCH': '(unset)' --> 'edge' early ] [πΏ] Applying cmdline param [ 'BOARD': '(unset)' --> 'rock-5c' early ] [πΏ] Applying cmdline param [ 'RELEASE': '(unset)' --> 'jammy' early ] [πΏ] Applying cmdline param [ 'SHARE_LOG': '(unset)' --> 'no' early ] ... [π±] Downloading required [ ORAS tooling ] ... [π±] Starting single build process [ rock-5c ] [π±] Checking [ basic host setup ] [π±] Build host OS release [ jammy ] [π±] Build host architecture [ amd64 ] ... [π] Stopping after configuring kernel [π±] Runtime [ 11:30 min ] [β¨] Repeat Build Options [ ./compile.sh kernel-config ARTIFACT_IGNORE_CACHE=yes BOARD=rock-5c BRANCH=edge BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy SHARE_LOG=no ] [π±] Cleaning up [ please wait for cleanups to finish ] ...
Now, copy the config file generated by this process so you can use it as a start point for future builds --
user $
cp -av output/config/linux-rockchip-rk3588-6.10.config userpatches/
user $
cp output/config/linux-rockchip-rk3588-6.10.config ../rock-5c-config/linux-rockchip-rk3588-6.10.3
Build the Kernel
user $
./compile.sh kernel SHARE_LOG='no' ARTIFACT_IGNORE_CACHE='yes' BRANCH=${branch} BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy BOARD=${board}
... ... lots of impressive, pretty output like above, and below ... ... [π±] shellcheck found no problems in package scripts [ shellchecked 2 scripts in 'linux-dtb-edge-rockchip-rk3588' ] [π±] Building package, this might take a while.. [ linux-dtb-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb ] [π¨] dpkg-deb: building package 'linux-dtb-edge-rockchip-rk3588' in '/home/joe/armbian/build/output/packages-hashed/global/linux-dtb-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb'. [π±] Packaging linux-headers [ rockchip-rk3588 linux-rockchip-rk3588-6.10 ] [π¨] '/home/joe/armbian/build/.tmp/work-0145f146-dff5-4a6a-847b-6430f783080a/deb-k-linux-headers-edge-rockchip-rk3588-LIn0Y/lib/modules/6.10.3-edge-rockchip-rk3588/build' -> '/usr/src/linux-headers-6.10.3-edge-rockchip-rk3588' [π¨] '/home/joe/armbian/build/cache/sources/linux-kernel-worktree/6.10__rockchip-rk3588__arm64/.config' -> '/home/joe/armbian/build/.tmp/work-0145f146-dff5-4a6a-847b-6430f783080a/deb-k-linux-headers-edge-rockchip-rk3588-LIn0Y/usr/src/linux-headers-6.10.3-edge-rockchip-rk3588/.config' [π¨] '/home/joe/armbian/build/cache/sources/linux-kernel-worktree/6.10__rockchip-rk3588__arm64/scripts/module.lds' -> '/home/joe/armbian/build/.tmp/work-0145f146-dff5-4a6a-847b-6430f783080a/deb-k-linux-headers-edge-rockchip-rk3588-LIn0Y/usr/src/linux-headers-6.10.3-edge-rockchip-rk3588/scripts/module.lds' [π±] shellcheck found no problems in package scripts [ shellchecked 3 scripts in 'linux-headers-edge-rockchip-rk3588' ] [π±] Building package, this might take a while.. [ linux-headers-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb ] [π¨] dpkg-deb: building package 'linux-headers-edge-rockchip-rk3588' in '/home/joe/armbian/build/output/packages-hashed/global/linux-headers-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb'. [π±] Packaging linux-libc-dev [ rockchip-rk3588 linux-rockchip-rk3588-6.10 ] [π±] shellcheck found no problems in package scripts [ no scripts found for 'linux-libc-dev-edge-rockchip-rk3588' ] [π±] Building package, this might take a while.. [ linux-libc-dev-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb ] [π¨] dpkg-deb: building package 'linux-libc-dev-edge-rockchip-rk3588' in '/home/joe/armbian/build/output/packages-hashed/global/linux-libc-dev-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb'. [π±] Kernel packaged in [ 9 seconds - 6.10.3-rockchip-rk3588 ] [π±] Kernel build finished [ 6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a ] [π±] Created deb-tar artifact [ deb-tar: /home/joe/armbian/build/output/packages-hashed/kernel-rockchip-rk3588-edge_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.tar ] [π±] Reversioning package [ re-version 'kernel-rockchip-rk3588-edge(deb-tar)::6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a' to '24.8.0-trunk' ] [π¨] removed '/home/joe/armbian/build/output/packages-hashed/global/linux-image-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb' [π¨] removed '/home/joe/armbian/build/output/packages-hashed/global/linux-headers-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb' [π¨] removed '/home/joe/armbian/build/output/packages-hashed/global/linux-libc-dev-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb' [π¨] removed '/home/joe/armbian/build/output/packages-hashed/global/linux-dtb-edge-rockchip-rk3588_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.deb' [π±] Runtime [ 16:12 min ] [β¨] Repeat Build Options [ ./compile.sh kernel ARTIFACT_IGNORE_CACHE=yes BOARD=rock-5c BRANCH=edge BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy SHARE_LOG=no ] [π±] Cleaning up [ please wait for cleanups to finish ] [πΏ] ANSI log file built; inspect it by running: [ less -RS output/logs/log-kernel-0145f146-dff5-4a6a-847b-6430f783080a.log.ans ] [πΏ] Share log manually (or SHARE_LOG=yes): [ curl --data-binary @output/logs/log-kernel-0145f146-dff5-4a6a-847b-6430f783080a.log.ans https://paste.armbian.com/log ]
Observe the Output
user $
tree output/
output/ βββ config β βββ linux-rockchip-rk3588-6.10.config β βββ linux-rockchip-rk3588-6.10.defconfig βββ debs β βββ linux-dtb-edge-rockchip-rk3588_24.8.0-trunk_arm64__6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a.deb β βββ linux-headers-edge-rockchip-rk3588_24.8.0-trunk_arm64__6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a.deb β βββ linux-image-edge-rockchip-rk3588_24.8.0-trunk_arm64__6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a.deb β βββ linux-libc-dev-edge-rockchip-rk3588_24.8.0-trunk_arm64__6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a.deb βββ info βββ logs β βββ archive β β βββ log-kernel-config-69d65f1a-c9ce-4608-a208-fdad8a9a00dc.log.ans.zst β β βββ log-kernel-config-69d65f1a-c9ce-4608-a208-fdad8a9a00dc.log.zst β β βββ summary-kernel-config-69d65f1a-c9ce-4608-a208-fdad8a9a00dc.md.zst β βββ log-kernel-0145f146-dff5-4a6a-847b-6430f783080a.log β βββ log-kernel-0145f146-dff5-4a6a-847b-6430f783080a.log.ans β βββ summary-kernel-0145f146-dff5-4a6a-847b-6430f783080a.md βββ packages-hashed βββ global βββ kernel-rockchip-rk3588-edge_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.tar
Note that this output includes several .deb archives under a "debs" directory, but all of those archives are also archived in the single tarball in the "packages-hashed" directory at the bottom of the list ( kernel-rockchip-rk3588-edge_6.10.3-Sd29d-D53de-P8ad7-Cbb61H5c21-HK01ba-Vc222-B3cfd-R448a_arm64.tar in this example ). That is the only file we really need, to deploy the entire kernel and associated .dtb file, overlays, and modules.
Deploy the output tarball
user $
file=$(find output/packages-hashed/ -iname 'kernel-rockchip-rk3588-edge_*')
user $
echo $file
user $
newversion=$(echo $(basename ${file}) | sed 's/kernel-rockchip-rk3588-edge_//' | cut -d'-' -f1)
user $
echo $newversion
user $
board="rk3588s-rock-5c"
user $
cp ${file} /media/host-share/${board}/linux-${board}_armbian_kernel_image-${newversion}.tar
user $
# or scp directly to a web-server
user $
scp ${file} raspi56406:/var/www/localhost/htdocs/rockchip-kernels/
Further deploy the output tarball
Now further deploy the new kernel into the new system (/boot device) ...
rock5c6403 #
mkdir scratchpad
rock5c6403 #
cd scratchpad
rock5c6403 #
board="rk3588s-rock-5c"
rock5c6403 #
board="<as above>"
rock5c6403 #
wget https://raspi56406.brendler/rockchip-kernels/linux-${board}_armbian_kernel_image-${newversion}.tar
rock5c6403 #
S=$(pwd); T=$(pwd)
rock5c6403 #
mkdir ${T}/scratch
rock5c6403 #
tar xvpf linux-${board}_armbian_kernel_image-${newversion}.tar
rock5c6403 #
dpkg-deb -x /home/joe/scratch/global/linux-image*.deb ${T}/scratch/
Verify and Install Kernel and Modules
rock5c6403 #
tree -L 3 ${T}/scratch/
/home/joe/scratch/scratch/ |-- boot | |-- System.map-6.10.3-edge-rockchip-rk3588 | |-- config-6.10.3-edge-rockchip-rk3588 | `-- vmlinuz-6.10.3-edge-rockchip-rk3588 |-- etc | `-- kernel | |-- postinst.d | |-- postrm.d | |-- preinst.d | `-- prerm.d |-- lib | `-- modules | `-- 6.10.3-edge-rockchip-rk3588 `-- usr |-- lib | `-- linux-image-6.10.3-edge-rockchip-rk3588 `-- share `-- doc
rock5c6403 #
cp -av ${T}/scratch/boot/* /boot/
rock5c6403 #
cp -av ${T}/scratch/lib/modules/6.10.3-edge-rockchip-rk3588 /lib/modules/
Build a kernel from sources
Without patches specifically associated with this board, the resulting kernel may not work!
Build Prerequisites
For the more adventurous builder a "completely from sources" build might be possible, if the defconfig or a working kernel seed and board-specific patches can be found. (Maybe as used by community contributors to Armbian), then the linux kernel for the Rock 5c can be built on an ARM64 device or cross-compiled on a PC. Assuming the latter, git and crossdev are needed:
- git, to check out the sources
- crossdev, since an arm64 (aarch64) toolchains is required
Make sure these are installed:
root #
emerge --ask --update dev-vcs/git sys-devel/crossdev
Please review the crossdev article if crossdev is not already set up.
Install the 64-bit cross-compiler toolchain:
root #
crossdev --target aarch64-unknown-linux-gnu
See the crossdev article regarding possible need to specify versions of components of the toolchain using -g, -b, -k, and -l options
Get the sources
Create a build directory
user $
cd /home/joe/
user $
mkdir -p My_${model}_project/build/${model}
Identify and populate a sources directory
root #
cd /usr/aarch64-unknown-linux-gnu/usr/src/
and retrieve sources for an appropriate version of the kernel. If this is the first custom kernel build for this board, it is probably wise to build the same version (or only a minor upgrade to a version) known to work in other distributions (e.g. Armbian or Debian). This retrieval can be done either by cloning the entire linux kernel repository and browsing it
root #
git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
root #
cd linux
root #
git branch --list --remotes
root #
git branch --show-current
root #
git checkout linux-<new_LTS_version>.y
or by browsing https://cdn.kernel.org/pub/linux/kernel/ to identify the version number, and then using wget to retrieve only the version needed
root #
tar xvpf linux-6.10.3.tar.xz
Configure the kernel
Once the sources are retrieved, the next step is configuration. As of this writing, there is no publicly available rk3588s-rock-5cb_defconfig. It would be possible to get one from files used to run armbian/build ([[1]], [[2]]), but if that software has already been used to generate a working kernel, it will be more efficient to use that running kernel's configuration as a "seed" for making a new one. For example, where model=rk3588s-rock-5c
--
root #
cd ~/My_${model}project/build/${model}/
root #
ln -snf /usr/aarch64-unknown-linux-gnu/usr/src/linux-<version> linux
root #
cd ../../
root #
cp kernelconfigs/<my_seed_config> build/<model>/.config
This procedure involves cross-compiling in a build directory, so lengthy command line operations can be simplified by exporting variables, or by assigning much of the repeated text to a single bash variable ${make_model}. This article will demonstrate the latter. For example --
root #
make_model='MAKEOPTS="-j16 -l4" FEATURES=" -userpriv -distcc -distcc-pump" make O=/home/joe/My_rk3588s-rock-5c_project/build/rk3588s-rock-5c/ ARCH=arm64 CROSS_COMPILE=aarch64-unknown-linux-gnu-'
Save a copy of the initial .config file, and then run make commands mrproper, prepare, oldconfig, and menuconfig; and then save a copy of the new .config file
root #
backup_config
root #
eval ${make_model} mrproper
root #
cp -v ${config_dir}/.config.bak ${model_config}
root #
eval ${make_model} oldconfig
root #
eval ${make_model} prepare
root #
eval ${make_model} menuconfig
root #
save_new_config
make targets prepare and oldconfig may generate interactive configuration questions on STDOUT that must be answered to complete configuration. When done, don't forget to save a copy of the new configuration file
Compile
Using the same "make_model" bash variable defined above, continue and build the kernel image, modules, and device tree binary blob files
root #
eval ${make_model} ${image}
root #
eval ${make_model} modules
root #
eval ${make_model} dtbs
Create a staging directory
This is a location in which to stage the kernel image, modules, and .dtb files needed on the target system, copy those files and build a tarball to facilitate transfer and installation on the target system
root #
cd ~/My_${model}project/build/${model}/
root #
distrib_dir=/home/joe/My_${model}_project/build/${model}/tmp/distrib
root #
mkdir -p ${distrib_dir}/{boot,lib}
root #
kernel_distrib_dir=${distrib_dir}/boot
Clean distrib_dir structure if repeating this procedure
root #
for x in $distrib_dir $kernel_distrib_dir; do [ [ -d $x ] ] && find $x -maxdepth 1 -type f -iname '*' -delete; done
root #
[ [ -d $lib_dir ] ] && find $lib_dir -mindepth 1 -iname '*' -delete
Stage the kernel and modules
root #
cp -av arch/arm64/boot/Image ${kernel_distrib_dir}/vmlinuz
root #
eval ${make_model} INSTALL_MOD_PATH=${distrib_dir} modules_install
Fix the "build" and "source" symlinks
root #
cd ${distrib_dir}/lib/modules/<version_number>
root #
rm -v build 2>/dev/null
root #
ln -snfv /usr/src/linux build
root #
rm -v source 2>/dev/null
root #
ln -snfv /usr/src/linux source
root #
cd ~/My_${model}project/build/${model}/
Stage the dtb files (and overlays)
root #
eval ${make_model} INSTALL_DTBS_PATH=${kernel_distrib_dir}/dts/ dtbs_install
root #
# copy the one dtb file we need up to boot
root #
cp -av ${kernel_distrib_dir}/dts/rockchip/${model}.dtb ${kernel_distrib_dir}/
Make tarball
root #
cd $distrib_dir
root #
tar --exclude lib/modules/<version_number>/source/ --exclude lib/firmware -cvjf linux-${model}-<version_number>_kernel_image.tar.bz2 boot lib
root #
cd ~/My_${model}project/build/${model}/
Deploy new kernel, modules, dtb
Now copy the tarball ${distrib_dir}/vmlinuz-<version_number>.tar.bz2 to the target system, either by
- mounting the target system storage device on the development platform and copying to its root / directory, or
- copying it to other removeable media to transfer to the / directory on the target system, or
- copying with scp, etc. to the / directory on the target system
Then un-archive contents from the tarball
root #
cd /mnt/gentoo/
root #
tar xvjf linux-${model}-<version_number>_kernel_image.tar.bz2
Inspect contents of target system /lib/modules/<version_number> and /boot/. Ensure the kernel and dtb files are named as the boot.scr script will expect (rename or edit joetooEnv.txt, if not).
Reboot! Observe u-boot console output...