User:Brendlefly62/Rockchip RK3588S Rock 5c/Build-Install-Kernel

From Gentoo Wiki
Jump to:navigation Jump to:search

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.

Tip
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

Note
* 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) --
KERNEL NLS Codepage settings (device mapper and crypt target may depend on)
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 #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

Warning
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 #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
Tip
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-'
will cross-compile for aarch64-unknown-linux-gnu, arm64, turning off disttcc features, allowing up to 16 compile jobs to be run in parallel, and it will output to the build directory instead of the sources directory

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...