User:Brendlefly62/Rockchip RK3399 Asus Tinker Board 2 S/build install kernel

From Gentoo Wiki
Jump to:navigation Jump to:search

Build your own kernel

Currently, there is no upstream support in the Linux kernel, nor in u-boot upstream projects. So the "completely from sources" method described further below is not recommended. However, there is community support for the Tinkerboard 2/2s 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 configure the kernel with Linux "menuconfig" --

user $ ./ kernel-config SHARE_LOG='yes' ARTIFACT_IGNORE_CACHE='yes' BOARD=tinkerboard-2 BRANCH=current BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy
[🌿] Log uploaded, share URL: [ ]

Then, run this command to actually build a thusly-configured kernel --

user $ ./ kernel SHARE_LOG='yes' ARTIFACT_IGNORE_CACHE='yes' BOARD=tinkerboard-2 BRANCH=current BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy
lots of impressive pretty output
[✨] Repeat Build Options [ ./ kernel-config ARTIFACT_IGNORE_CACHE=yes BOARD=tinkerboard-2 BRANCH=current BUILD_DESKTOP=no BUILD_MINIMAL=yes RELEASE=jammy SHARE_LOG=yes ]
[🌱] Cleaning up [ please wait for cleanups to finish ]
[🌿] ANSI log file built; inspect it by running: [ less -RS output/logs/log-uboot-6449d7f7-7556-4099-b562-7bd379b9b1b5.log.ans ]
[🌱] SHARE_LOG=yes, uploading log [ uploading logs ]
[🌿] Log uploaded, share URL: [ ]

Once that is complete, examine the new contents in the "armbian/build/output" folder, and copy the package containing the kernel, config, and system map to a development workstation where they can be extracted and employed in the system-build.

user $ $
### --- to (re)build just the kernel do this ---
$ cd armbian/build
# must be separate - configure the kernel first, then build it (see above)
# now inspect the output to see what has been produced
$ cd output
# use "lr" to date-order the listing of contents of each subdirectory.  For my run, only the debs folder had new contents - copy to host-share folder
$  cp debs/linux-image-current-rockchip64_24.5.0-trunk_arm64__6.6.30-S5697-D440d-P5d41-Ce2d0H5c21-HK01ba-Vc222-Bf15a-R448a.deb /media/host-share/
$  cp debs/linux-headers-current-rockchip64_24.5.0-trunk_arm64__6.6.30-S5697-D440d-P5d41-Ce2d0H5c21-HK01ba-Vc222-Bf15a-R448a.deb /media/host-share/
$  cp debs/linux-libc-dev-current-rockchip64_24.5.0-trunk_arm64__6.6.30-S5697-D440d-P5d41-Ce2d0H5c21-HK01ba-Vc222-Bf15a-R448a.deb /media/host-share/
$  cp debs/linux-dtb-current-rockchip64_24.5.0-trunk_arm64__6.6.30-S5697-D440d-P5d41-Ce2d0H5c21-HK01ba-Vc222-Bf15a-R448a.deb /media/host-share/ 

Now go to windows host and copy these contents over to your development workstation, so they can be further copied into the new system (/boot device)

From-Source Build Prerequisites

Without patches specifically associated with this board, the resulting kernel may not work!

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 Tinkerboard 2 S 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 to identify the version number, and then using wget to retrieve only the version needed

root #tar xvpf linux-6.1.66.tar.xz

Configure the kernel

Once the sources are retrieved, the next step is configuration. As of this writing, there is no publicly available rk3399-tinker-2_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=rk3399-tinker-2-s --

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_rk3399-tinker-2-s_project/build/rk3399-tinker-2-s/ 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} prepare
root #eval ${make_model} oldconfig
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


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