Cover image for topeet RK3568 Linux5.10 Compilation

topeet RK3568 Linux5.10 Compilation

Words 702
Views
Visitors

Timeline

Timeline

2025-12-26

init

This article describes the process of compiling the topeet RK3568 platform Linux 5.10 kernel, U-Boot, and root filesystem using the aarch64-linux-gnu-gcc 15.1.0 compiler in a WSL Archlinux environment. It details the kernel compilation steps, the method for generating compile_command.json when viewing kernel source code with clangd, and source code modifications to address Clang errors on GCC inline assembly (such as reading the sp register). It also lists various defconfig configurations for RK3568 U-Boot and their applicable scenarios, and mentions the generated image file types. Additionally, the article covers root filesystem compilation and Recovery flashing, but some steps are marked as TODO (to be studied). Overall, it is a practical record for developers.

Environment

OS

Using Archlinux on WSL

Environment
Environment

compiler

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

For Cortex-A5x processors, you can useaarch64-linux-gnu-gcc -march=armv8-aCompile the code using the command. The ARM GNU compiler can be downloaded from the link below.

Using aarch64-linux-gnu-gcc version 15.1.0 downloaded via pacman on Archlinux.

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

source code

The source code is provided by topeet:

Compile the kernel.

Compilation

Use the aarch64-linux-gnu-gcc 15.1.0 compiler.

123456789101112131415
sudo pacman -Sy bcmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- cleanmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rockchip_linux_defconfigmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfigmake 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 the language server, you need to add CompileFlags because clangd does not recognize some GCC compilation options:

123
CompileFlags:  Add: -Wno-unknown-warning-option  Remove: [-m*, -f*]

sp error

clangd reports an 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 stack top address. This syntax is legal when GCC compiles the Linux kernel (especially on ARM64), but Clang has stricter restrictions. 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.

123456789101112131415161718192021222324
/* 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 itstatic inline unsigned long get_sp(void){	unsigned long sp;	__asm__("" : "=r"(sp) : "r"(0));	return sp;}#define current_stack_ptr get_sp()#elseregister 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
1234
make rk3568_defconfigexport KCFLAGS="-Wno-enum-int-mismatch -Wno-maybe-uninitialized"make CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc) allunset 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)
123
tools/mkimage -n rk3568 -T rksd -d tpl/u-boot-tpl.bin idbloader.imgcat spl/u-boot-spl.bin >> idbloader.img

The loader generated this way may have some issues, still to be investigated TODO

Compile the root filesystem.

123
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rockchip_rk3568_defconfigmake ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfigsudo pacman -Sy cpio rsync

Compile recovery

TODO

Flash

TODO

Loading comments…