Cover image for topeet RK3568 Linux 5.10 compilation

topeet RK3568 Linux 5.10 compilation

Words 659
Views
Visitors

Timeline

Timeline

2025-12-26

init

This article introduces the process of compiling the Topeet RK3568 Linux 5.10 kernel and U-Boot using aarch64-linux-gnu-gcc 15.1.0 in a WSL Archlinux environment. It details the source code modification method to resolve stack pointer errors when configuring clangd, lists various U-Boot defconfig options and their generation results, and notes that the compilation of the root filesystem and recovery will be improved in the future.

Environment

OS

Using Archlinux on WSL

Environment
Environment

compiler

ARM has currently released a total of 8 architectures: ARMv1, ARMv2, ARMv3, ARMv4, ARMv5, ARMv6, ARMv7, ARMv8.

Can be used for Cortex-A5x processorsaarch64-linux-gnu-gcc -march=armv8-acommand to compile code, the ARM GNU compiler can be downloaded via the link below

The version of aarch64-linux-gnu-gcc downloaded via pacman on Archlinux is 15.1.0

aarch64-linux-gnu-gcc
aarch64-linux-gnu-gcc

source code

The source code is provided by topeet:

Compile the kernel

Compilation

Using the aarch64-linux-gnu-gcc version 15.1.0 compiler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo pacman -Sy bc

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- clean
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rockchip_linux_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_prepare

# -Wno-dangling-pointer disables GCC's "dangling pointer" warning.
# -Wno-enum-int-mismatch disables the "enum type and integer type mismatch" warning.
export KCFLAGS="-Wno-dangling-pointer -Wno-enum-int-mismatch"

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image dtbs -j$(nproc)

unset KCFLAGS # Optional, clear after use

Viewing kernel source code with clangd

Generate compile_command.json

1
./scripts/clang-tools/gen_compile_commands.py

When using clangd as a language server, CompileFlags need to be added because clangd does not recognize some GCC compilation options:

1
2
3
CompileFlags:
Add: -Wno-unknown-warning-option
Remove: [-m*, -f*]

sp error

clangd error:

1
clang [asm_invalid_global_var_reg]: Register 'sp' unsuitable for global register variables on this target

Bind the variable current_stack_pointer to the sp register (i.e., the current stack pointer) to directly read the top address of the stack. This syntax is legal when compiling the Linux kernel with GCC (especially under the ARM64 architecture), but Clang has stricter restrictions on this. Therefore, we modifyarch/arm64/include/asm/stack_pointer.hThe source code is as follows, for__clang__Use an inline assembly function to return the value of sp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_STACK_POINTER_H
#define __ASM_STACK_POINTER_H

/*
* how to get the current stack pointer from C
*/
#ifdef __clang__
// For clang: fake it
static inline unsigned long get_sp(void)
{
unsigned long sp;
__asm__("" : "=r"(sp) : "r"(0));
return sp;
}
#define current_stack_ptr get_sp()

#else
register unsigned long current_stack_pointer asm("sp");

#endif

#endif /* __ASM_STACK_POINTER_H */

Compile U-Boot

The defconfig for RK3568 is as follows

defconfigSupport kernel dtbDescription
rk3568_defconfigYGeneric version
rk3568-dfu.configYSupport dfu
rk3568-nand.configYSupport MLC/TLC/eMMC
rk3568-spl-spi-nand_defconfigYSPI-nand dedicated SPL
rk3568-aarch32.configYSupport aarch32 mode
rk3568-usbplug.configYSupport usbplug mode
1
2
3
4
make rk3568_defconfig
export KCFLAGS="-Wno-enum-int-mismatch -Wno-maybe-uninitialized"
make CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc) all
unset KCFLAGS # Optional, clear after use

Generate:

  • u-boot(ELF)
  • u-boot.bin(Raw binary)
  • spl/u-boot-spl.bin(If SPL is enabled)
  • tpl/u-boot-tpl.bin(If TPL is enabled)
  • u-boot.dtb(Embedded external device tree)
1
2
3
tools/mkimage -n rk3568 -T rksd -d tpl/u-boot-tpl.bin idbloader.img

cat spl/u-boot-spl.bin >> idbloader.img

The generated loader may have some issues, TODO for further research

Compile the root file system

1
2
3
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rockchip_rk3568_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
sudo pacman -Sy cpio rsync

Compile recovery

TODO

Flash

TODO