Building a Linux 5 kernel

I’ve been playing around with my board and I saw that there’s quite a bit of updated support for the Rock 960 in Linux 5 (including support for user leds etc). But, it looks like the only kernel that’s officially available is 4.4. Is there a recommended way to build mainline Linux? I’ve tried in the past to upgrade the kernel on the board (i.e. building on the Rock960 itself), but I couldn’t get it to boot into the new system, it’d keep loading 4.4.

I’ve had a look at this: Custom kernel compilation

Thanks!

Hi,

To build mainline kernel, you can just follow the link you posted:

Build the kernel:

make ARCH=arm64 menuconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 12 Image dtbs

arch/arm64/boot/Image and arch/arm64/boot/dts/rockchip/rk3399-rock960.dtb is what you get.

To update the kernel for current image, make sure /dev/mmcblkp4 is mounted on /boot

copy arch/arm64/boot/Image to /boot/Image-5.0 and arch/arm64/boot/dts/rockchip/rk3399-rock960.dtb to /boot/rk3399-rock960.dtb.

Edit /boot/extlinux/extlinux.conf, add an entry on the top.

label kernel-mainline
    kernel /Image-5.0
    fdt /rk3399-rock960.dtb
    append  earlycon=uart8250,mmio32,0xff130000 rw root=PARTUUID=b921b045-1d rootwait rootfstype=ext4 init=/sbin/init

Then reboot, u-boot will load the kernel in the first entry by default.

3 Likes

Great, thanks for the confirmation. I did try something similar before (I think with a 4.21 branch), but I was having trouble generating the dtb file. I’ll give that a go tomorrow and update!

Can I just copy the config file from the rockchip repository? Or if I start from scratch, is there anything I should enable that isn’t by default?

Hi,

I don’t know if you succeed to build and boot from a linux 5 kernel with your ROCK960 BUT for me, it does not boot… I am interested in your defconfig and dts files…

Anyway, if your are willing to have LED support with a linux 4.4 kernel, you just have to use my rk3399-rock960.dts file below after having renamed your current dts file to rk3399-rock960.dtsi…

It’s widely inspired by from @96rocks android dts file BUT with some modifications… It should work OOTB, if not, check your defconfig file for LED support…

Green LEDs are labelled from 0 to 3 : 0 is the one which is the closest from the SBC PCB edge (hearbeat), 1 and 2 are emmc / sdcard, 3 is panic, yellow and blue are for wifi and bluetooth respectively.

Regards

→ rk3399-rock960.dts

 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
 * Copyright (c) 2018 Linaro Ltd.
 */

/dts-v1/;
#include "rk3399-rock960.dtsi"

/ {
	model = "96boards Rock960";
	compatible = "vamrs,rock960", "rockchip,rk3399";

	chosen {
		stdout-path = "serial2:1500000n8";
	};

	leds {
		compatible = "gpio-leds";
		status = "okay";

		green@0 {
			label = "rock960:green:user0";
			linux,default-trigger = "heartbeat";
			gpios = <&gpio4 18 GPIO_ACTIVE_HIGH>;
		};
		green@1 {
			label = "rock960:green:user1";
			linux,default-trigger = "mmc0";
			gpios = <&gpio4 28 GPIO_ACTIVE_HIGH>;
		};
		green@2 {
			label = "rock960:green:user2";
			linux,default-trigger = "mmc1";
			gpios = <&gpio4 22 GPIO_ACTIVE_HIGH>;
		};
		green@3 {
			label = "rock960:green:user3";
			linux,default-trigger = "none";
			gpios = <&gpio4 24 GPIO_ACTIVE_HIGH>;
		};
		yellow {
			label = "rock960:yellow:wifi";
			linux,default-trigger = "rfkill2";
			default-state = "on";
			gpios = <&gpio4 29 GPIO_ACTIVE_HIGH>;
		};
		blue {
			label = "rock960:blue:bluetooth";
			linux,default-trigger = "rfkill1";
			default-state = "on";
			gpios = <&gpio4 30 GPIO_ACTIVE_HIGH>;
		};
	};
};

I’ve not tried to build Linux 5 yet. I’ve been working on a Docker container that will build a Rock960 image. Once I’ve got that reliably working and I’ve figured out what extra things I want compiled in, I’m going to give it a go. :slight_smile:

I might add your .dts as a build step though, if I don’t get it working otherwise.

OK, good luck with your project.

Are there any updated instructions for this? I’ve tried building 5.4 as a warmup, but my rock960a won’t boot with Image and rk3399-rock960.dtb copied post-build. I’m using http://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz as toolchain, is it too “new”? Are the above suggested contents of /boot/extlinux/extlinux.conf still valid?

I’m also wondering if the other supporting files like u-boot.itb, idbloader.img, etc are also needed.

As I suspected, the suggested /boot/extlinux/extlinux.conf contents in the comment above do not work, at least not in Ubuntu on Rock960 A. The updated 5.8 kernel Image and rk3399-rock960.dtb boot successfully when the corresponding selection block uses the pre-existing kernel command line options, in my case:

label kernel-5.8
    kernel /Image-5.8
    fdt /rk3399-rock960.dtb
    append earlyprintk console=ttyFIQ0,1500000n8 rw init=/sbin/init root=PARTUUID=b921b045-1d rootwait rootfstype=ext4

Maybe the new uart8250 reference trips it up. With the old command line options the green LED blinking as heartbeat indicates successful update but the debug serial and wifi no longer work.

Also, contrary to the suggestion above I would suggest to initially put the block last in extlinux.conf, and only make it default (first) when you’re satisfied with your configuration.

Who here was able to enable wifi and serial debug console for their (Ubuntu) kernel 5.x update, for example 5.8? Are there any modifications needed for this in rock960’s https://github.com/96rocks/kernel/blob/release-4.4/arch/arm64/configs/rockchip_linux_defconfig?

BTW, here is a script I’ve written to compile a new kernel update unattended, in case someone else finds it useful.

The mk-image.sh patch reduces the size of boot.img to 112MB so it doesn’t overrun the existing size for mmcblk1p4 in Ubuntu (the version in master uses 500MB for size) - the output file can be written directly with rkdeveloptool wl 32768 boot.img without overwriting the next partition on disk.

cat compile_rock960.sh

#!/bin/bash

LINUX_VERSION=${1:-5.8}
BASE_DIR=`readlink -f ${2:-.}`
echo "Using: ${LINUX_VERSION} into ${BASE_DIR}"
CURR_DIR=${PWD}
WORK_DIR=${BASE_DIR}/rock960_${LINUX_VERSION}
OUT_DIR=${WORK_DIR}/out
mkdir -p ${WORK_DIR}
mkdir -p ${OUT_DIR}
cd ${WORK_DIR}

sudo apt update
sudo apt-get install -y build-essential git libncurses5-dev libssl-dev make
sudo apt-get install -y bison device-tree-compiler flex gcc-arm-none-eabi mtools python
sudo apt-get remove -y apt-listchanges
sudo apt-get install -y zlib1g:i386

export ARCH=arm64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/x86_64-linux-gnu

wget http://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
mkdir ${WORK_DIR}/toolchain
tar -xf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz -C ${WORK_DIR}/toolchain --strip-components=1

git clone --depth 1 https://github.com/ARM-software/arm-trusted-firmware.git
export CROSS_COMPILE=${WORK_DIR}/toolchain/bin/aarch64-linux-gnu-
cd ${WORK_DIR}/arm-trusted-firmware/
make CROSS_COMPILE=${WORK_DIR}/toolchain/bin/aarch64-linux-gnu- PLAT=rk3399

cd ${WORK_DIR}
git clone --branch release-4.4-rock960 --depth 1 https://github.com/96rocks/kernel.git
cd ${WORK_DIR}/kernel
make rockchip_linux_defconfig
make Image dtbs -j$(nproc)
ls -l ${WORK_DIR}/kernel/arch/arm64/boot/dts/rockchip/rock960-model-ab-linux.dtb
cp ${WORK_DIR}/kernel/arch/arm64/boot/dts/rockchip/rock960-model-ab-linux.dtb ${OUT_DIR}/.

cd ${WORK_DIR}
git clone --depth 1 https://github.com/96rocks/build.git
mkdir -p ${WORK_DIR}/out/kernel && cd ${WORK_DIR}/out/kernel
cp ${WORK_DIR}/kernel/arch/arm64/boot/Image .
cd ${WORK_DIR}/build
patch -p0 < ${CURR_DIR}/mk-image.sh.patch
cd ${WORK_DIR}
./build/mk-image.sh -c rk3399 -t boot

ls -l ${WORK_DIR}/kernel/arch/arm64/boot/Image
ls -l ${WORK_DIR}/out/boot.img
ls -l ${WORK_DIR}/kernel/arch/arm64/boot/dts/rockchip/rock960-model-ab-linux.dtb
cp ${WORK_DIR}/kernel/arch/arm64/boot/Image ${OUT_DIR}/Image.96rocks
cp ${WORK_DIR}/kernel/arch/arm64/boot/dts/rockchip/rock960-model-ab-linux.dtb ${OUT_DIR}/.

cd ${WORK_DIR}
git clone --depth 1 https://gitlab.denx.de/u-boot/u-boot.git
cd ${WORK_DIR}/u-boot
export BL31=${WORK_DIR}/arm-trusted-firmware/build/rk3399/release/bl31/bl31.elf
make ARCH=arm64 rock960-rk3399_defconfig
make CROSS_COMPILE=${WORK_DIR}/toolchain/bin/aarch64-linux-gnu-
ls -l ${WORK_DIR}/u-boot/idbloader.img
ls -l ${WORK_DIR}/u-boot/u-boot-rockchip.bin
ls -l ${WORK_DIR}/u-boot/u-boot.itb
cp ${WORK_DIR}/u-boot/idbloader.img ${OUT_DIR}/.
cp ${WORK_DIR}/u-boot/u-boot-rockchip.bin ${OUT_DIR}/.
cp ${WORK_DIR}/u-boot/u-boot.itb ${OUT_DIR}/.

cd ${WORK_DIR}
git clone --branch linux-${LINUX_VERSION}.y --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

cp ${WORK_DIR}/kernel/arch/arm/configs/rockchip_linux_defconfig ${WORK_DIR}/linux/arch/arm/configs/rockchip_linux_defconfig
cp ${WORK_DIR}/kernel/arch/arm64/configs/rockchip_linux_defconfig ${WORK_DIR}/linux/arch/arm64/configs/rockchip_linux_defconfig

cd ${WORK_DIR}/linux
patch -p0 < ${CURR_DIR}/rockchip_linux_defconfig.patch
make ARCH=arm64 rockchip_linux_defconfig
make ARCH=arm64 CROSS_COMPILE=${WORK_DIR}/toolchain/bin/aarch64-linux-gnu- -j$(nproc)
ls -l ${WORK_DIR}/linux/arch/arm64/boot/Image
ls -l ${WORK_DIR}/linux/arch/arm64/boot/dts/rockchip/rk3399-rock960.dtb
cp ${WORK_DIR}/linux/arch/arm64/boot/Image ${OUT_DIR}/.
cp ${WORK_DIR}/linux/arch/arm64/boot/dts/rockchip/rk3399-rock960.dtb ${OUT_DIR}/.

cat mk-image.sh.patch

diff --git mk-image.sh mk-image.sh
index 0ff6055..afb5c5e 100755
--- mk-image.sh
+++ mk-image.sh
@@ -54,7 +54,10 @@ generate_boot_image() {
 	echo -e "\e[36m Generate Boot image start\e[0m"
 
 	# 500Mb
-	mkfs.vfat -n "boot" -S 512 -C ${BOOT} $((500 * 1024))
+	# mkfs.vfat -n "boot" -S 512 -C ${BOOT} $((500 * 1024))
+
+	# 112Mb
+	mkfs.vfat -n "boot" -S 512 -C ${BOOT} $((112 * 1024))
 
 	mmd -i ${BOOT} ::/extlinux
 	mcopy -i ${BOOT} -s ${EXTLINUXPATH}/${CHIP}.conf ::/extlinux/extlinux.conf

cat rockchip_linux_defconfig.patch

--- arch/arm64/configs/rockchip_linux_defconfig	2021-02-28 12:30:52.232068920 -0800
+++ arch/arm64/configs/rockchip_linux_defconfig	2021-02-28 12:31:36.212170628 -0800
@@ -148,9 +148,9 @@
 CONFIG_NF_CONNTRACK_EVENTS=y
 CONFIG_NF_CONNTRACK_TIMEOUT=y
 CONFIG_NF_CONNTRACK_TIMESTAMP=y
-CONFIG_NF_CT_PROTO_DCCP=m
-CONFIG_NF_CT_PROTO_SCTP=m
-CONFIG_NF_CT_PROTO_UDPLITE=m
+CONFIG_NF_CT_PROTO_DCCP=y
+CONFIG_NF_CT_PROTO_SCTP=y
+CONFIG_NF_CT_PROTO_UDPLITE=y
 CONFIG_NF_CONNTRACK_AMANDA=m
 CONFIG_NF_CONNTRACK_FTP=m
 CONFIG_NF_CONNTRACK_H323=m
@@ -164,8 +164,8 @@
 CONFIG_NF_CT_NETLINK=m
 CONFIG_NF_CT_NETLINK_TIMEOUT=m
 CONFIG_NF_TABLES=m
-CONFIG_NF_TABLES_INET=m
-CONFIG_NF_TABLES_NETDEV=m
+CONFIG_NF_TABLES_INET=y
+CONFIG_NF_TABLES_NETDEV=y
 CONFIG_NFT_EXTHDR=m
 CONFIG_NFT_META=m
 CONFIG_NFT_CT=m
@@ -285,7 +285,7 @@
 CONFIG_NF_CONNTRACK_IPV4=m
 CONFIG_NFT_CHAIN_ROUTE_IPV4=m
 CONFIG_NFT_DUP_IPV4=m
-CONFIG_NF_TABLES_ARP=m
+CONFIG_NF_TABLES_ARP=y
 CONFIG_NF_LOG_ARP=m
 CONFIG_NFT_CHAIN_NAT_IPV4=m
 CONFIG_NFT_MASQ_IPV4=m
@@ -767,7 +767,7 @@
 CONFIG_MEDIA_CEC_SUPPORT=y
 CONFIG_MEDIA_CONTROLLER=y
 CONFIG_VIDEO_V4L2_SUBDEV_API=y
-CONFIG_LIRC=m
+CONFIG_LIRC=y
 CONFIG_MEDIA_USB_SUPPORT=y
 CONFIG_USB_VIDEO_CLASS=y
 # CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV is not set

Debug serial console works with the following, corrected version of extlinux.conf:

label kernel-5.8.18
    kernel /Image-5.8.18
    fdt /rk3399-rock960-5.8.18.dtb
    append earlycon=uart8250,mmio rw root=PARTUUID=b921b045-1d rootwait rootfstype=ext4 init=/sbin/init

The script can be used to compile 5.9.16, etc. Wi-fi is still MIA.