zynq的xlnx_rebase_v5.4_2020.2分支打patch-5.4.3-rt1.patch.xz补丁

Linux RT 官方下载链接

https://cdn.kernel.org/pub/linux/kernel/projects/rt/

下载文件

bash 复制代码
minglie@minglie:cd /home/wpf/workspace/kernel-driver/linux_rt
# 克隆 xlnx_rebase_v5.4_2020.2 
git clone --depth 1 \
-b xlnx_rebase_v5.4_2020.2 \
https://hub.fastgit.org/Xilinx/linux-xlnx.git
# 创建个新分支rt_5.4.0
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx$ git switch -c rt_5.4.0
Switched to a new branch 'rt_5.4.0'
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx$ git branch
* rt_5.4.0
# 下载 patch-5.4.3-rt1.patch
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx$ cd /home/wpf/workspace/kernel-driver/linux_rt
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt$ wget https://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older/patch-5.4.3-rt1.patch.xz
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt$ unxz patch-5.4.3-rt1.patch.xz
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt$ ls
linux-xlnx  patch-5.4.3-rt1.patch

应用RT补丁

bash 复制代码
# 检查 git 状态
cd /home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx
# 应用RT补丁
patch -p1 < ../patch-5.4.3-rt1.patch
# 统计冲突
git apply --check --verbose ../patch-5.4.3-rt1.patch
# 检查 git 状态
git status --short --branch
# 检查内核版本
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx$ sed -n '1,8p' Makefile
# SPDX-License-Identifier: GPL-2.0
VERSION = 5
PATCHLEVEL = 4
SUBLEVEL = 0
EXTRAVERSION =
# 检查 RT localversion
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx$ test -f localversion-rt && cat localversion-rt || true
-rt1
# 检查reject 内容
# smp.c.rej是补丁打失败产生的「冲突拒绝文件」
# 有冲突,不一定会影响编译
sed -n '1,220p' arch/arm/kernel/smp.c.rej
 case IPI_CPU_BACKTRACE:
-        printk_nmi_enter();
         irq_enter();
         nmi_cpu_backtrace(regs);
         irq_exit();
-        printk_nmi_exit();
         break;
# 检查当前源码:
sed -n '560,700p' arch/arm/kernel/smp.c

RT 配置项检查

bash 复制代码
minglie@minglie:/home/wpf/workspace/kernel-driver/linux_rt/linux-xlnx$ grep -n 'config ARCH_SUPPORTS_RT\|ARCH_SUPPORTS_RT\|HAVE_PREEMPT_LAZY\|config PREEMPT_RT' \
  arch/arm/Kconfig kernel/Kconfig.preempt arch/Kconfig
arch/arm/Kconfig:35:    select ARCH_SUPPORTS_RT
arch/arm/Kconfig:106:   select HAVE_PREEMPT_LAZY
kernel/Kconfig.preempt:3:config HAVE_PREEMPT_LAZY
kernel/Kconfig.preempt:7:       def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT
kernel/Kconfig.preempt:64:config PREEMPT_RT
kernel/Kconfig.preempt:66:      depends on EXPERT && ARCH_SUPPORTS_RT
arch/Kconfig:818:config ARCH_SUPPORTS_RT

内核配置

linux-xlnx-5.4.3-rt1-patched.config

bash 复制代码
make xilinx_zynq_defconfig
make menuconfig
# 进入
General setup
# 勾选 (CONFIG_EXPERT=y)
Configure standard kernel features (expert users)
# 进入
General setup -> Preemption Model
# 选择
────────────────────── Preemption Model ───────────────────────┐
│  Use the arrow keys to navigate this window or press the      │
│  hotkey of the item you wish to select followed by the <SPACE │
│  BAR>. Press <?> for additional information about this        │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │       ( ) No Forced Preemption (Server)                   │ │
│ │       ( ) Voluntary Kernel Preemption (Desktop)           │ │
│ │       ( ) Preemptible Kernel (Low-Latency Desktop)        │ │
│ │       (X) Fully Preemptible Kernel (Real-Time)            │ │
│ │                                                           │ │
│ │                                                           │ │
│ └───────────────────────────────────────────────────────────┘ │
├───────────────────────────────────────────────────────────────┤
│                    <Select>      < Help >
# 保存编译
make

# 开发板测试
# 不加 rt1.patch 显示
root@ant:~# uname -a
Linux ant 5.4.0-xilinx #3 SMP PREEMPT Wed Feb 11 16:11:13 CST 2026 armv7l GNU/Linux
# 加 rt1.patch 显示
root@ant:~# uname -a
Linux ant 5.4.0-rt1-xilinx-dirty #3 SMP PREEMPT_RT Wed Jul 29 12:46:03 CST 2026 armv7l GNU/Linux
root@ant:~#  zcat /proc/config.gz | grep PREEMPT
CONFIG_HAVE_PREEMPT_LAZY=y
CONFIG_PREEMPT_LAZY=y
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
# CONFIG_PREEMPT is not set
CONFIG_PREEMPT_RT=y
CONFIG_PREEMPT_COUNT=y
CONFIG_PREEMPTION=y
CONFIG_PREEMPT_RCU=y
# CONFIG_DEBUG_PREEMPT is not set

遇到的 dtc 编译错误

执行 make 后遇到:

text 复制代码
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x20): multiple definition of `yylloc';
scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [scripts/Makefile.host:116: scripts/dtc/dtc] Error 1
make: *** [Makefile:1263: scripts_dtc] Error 2

这是老版本 Linux 内核自带 dtc 遇到新版本 GCC/binutils 时的常见问题。

原因是:

text 复制代码
scripts/dtc/dtc-lexer.l
scripts/dtc/dtc-parser.tab.c

里都定义了 yylloc,新工具链默认不再容忍这种重复定义。

对 dtc 做的补丁

检查位置:

bash 复制代码
grep -RIn 'YYLTYPE yylloc\|yylloc' \
  scripts/dtc/dtc-lexer.l \
  scripts/dtc/dtc-parser.y \
  scripts/dtc/*.c \
  scripts/dtc/*.h

确认 scripts/dtc/dtc-lexer.l 中有:

c 复制代码
YYLTYPE yylloc;

把它改成:

c 复制代码
extern YYLTYPE yylloc;

实际修改文件:

text 复制代码
scripts/dtc/dtc-lexer.l
相关推荐
醉城夜风~2 小时前
HTML常用标签详解学习博客:从基础标签到页面结构完整掌握
前端·学习·html
minglie13 小时前
蚂蚁S9矿板PS 内核定时器驱动
学习
你想知道什么?3 小时前
决策树-学习笔记
笔记·学习·决策树
MartinYeung53 小时前
[论文学习]WASP:面向提示注入攻击的Web代理安全性基准测试
前端·网络·学习
懒狗跑ai的程序员Brain4 小时前
如何利用粒子系统在unity制作一个烟花(粒子系统学习向)
学习·unity·游戏引擎
念何架构之路4 小时前
moby-BuildKit(builder-next)
学习·docker·容器
惠惠软件4 小时前
快速生成磁盘目录文件-双击运行a.bat ,可以看到磁盘目录下出现了 文件目录.txt-供大家学习研究参考
windows·学习·文件列表
星恒随风4 小时前
C++ STL 详解:set 与 multiset 的使用、区间查询和算法应用
开发语言·c++·笔记·学习·算法
m4Rk_4 小时前
【论文阅读】Agent 记忆机制(20):RecMem——只在信息反复出现时进行长期记忆巩固
论文阅读·人工智能·学习·开源·github