Cover image for topeet RK3568 Linux5.10 编译

topeet RK3568 Linux5.10 编译

字数 866
阅读
访客

时间轴

时间轴

2025-12-26

init

本文介绍了在WSL Archlinux环境下,使用aarch64-linux-gnu-gcc 15.1.0编译器编译topeet RK3568平台Linux 5.10内核、U-Boot及根文件系统的过程。文章详细说明了内核编译步骤、通过clangd查看内核源码时生成compile_command.json的方法,以及针对Clang对GCC内联汇编(如读取sp寄存器)报错的源码修改方案。同时,列出了RK3568 U-Boot的多种defconfig配置及其适用场景,并提及生成的镜像文件类型。此外,文章还涉及根文件系统编译和Recovery烧写等内容,但部分步骤标注为待研究(TODO)。整体为一份面向开发者的实践记录。

环境

OS

使用 wsl 的 archlinux

环境
环境

compiler

ARM目前总共发布了8种架构:ARMv1、ARMv2、ARMv3、ARMv4、ARMv5、ARMv6、ARMv7、ARMv8。

针对于Cortex-A5x处理器可以使用aarch64-linux-gnu-gcc -march=armv8-a命令编译代码,ARM GNU编译器可通过下面的链接下载

使用archlinux上通过pacman下载的aarch64-linux-gnu-gcc版本是15.1.0

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

source code

源码是topeet提供的:

编译内核

编译

使用aarch64-linux-gnu-gcc 15.1.0版本编译器

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 禁用 GCC 的 “悬空指针” 警告。# -Wno-enum-int-mismatch 禁用 “枚举类型与整数类型不匹配” 的警告。export KCFLAGS="-Wno-dangling-pointer -Wno-enum-int-mismatch"make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image dtbs -j$(nproc)unset KCFLAGS  # 可选,用完清除

clangd 查看内核源码

生成compile_command.json

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

使用 clangd 作为语言服务器要添加 CompileFlags,因为 clangd 对 GCC 的某些编译选项不识别:

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

sp报错

clangd报错:

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

将变量 current_stack_pointer 绑定到 sp 寄存器(即当前栈指针),以便直接读取栈顶地址。这种写法在 GCC 编译 Linux 内核时是合法的(尤其在 ARM64 架构下),但 Clang 对此有更严格的限制。因此我们修改arch/arm64/include/asm/stack_pointer.h源码如下,对于__clang__使用内联汇编函数返回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 */

编译uboot

RK3568 的 defconfig 如下

defconfig支持 kernel dtb说明
rk3568_defconfigY通用版本
rk3568-dfu.configY支持 dfu
rk3568-nand.configY支持 MLC/TLC/eMMC
rk3568-spl-spi-nand_defconfigYSPI-nand 专用 SPL
rk3568-aarch32.configY支持 aarch32 模式
rk3568-usbplug.configY支持 usbplug 模式
1234
make rk3568_defconfigexport KCFLAGS="-Wno-enum-int-mismatch -Wno-maybe-uninitialized"make CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc) allunset KCFLAGS  # 可选,用完清除

生成:

  • u-boot(ELF)
  • u-boot.bin(原始二进制)
  • spl/u-boot-spl.bin(如果启用 SPL)
  • tpl/u-boot-tpl.bin(如果启用 TPL)
  • u-boot.dtb(内嵌的外部设备树)
123
tools/mkimage -n rk3568 -T rksd -d tpl/u-boot-tpl.bin idbloader.imgcat spl/u-boot-spl.bin >> idbloader.img

这样生成的loader可能有点问题还待研究TODO

编译根文件系统

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

编译recover

TODO

烧写

TODO

评论加载中…