Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 284 additions & 0 deletions docs/radxa-dto-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
---
title: Radxa SBC 添加 Device Tree Overlay
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该文档的 front matter 缺少 sidebar_position,会被 scripts/agent-doc-lint.sh 判定为失败(要求每个非 _*.mdx/wrapper 文档必须包含 sidebar_position)。建议在 front matter 中补充 sidebar_position(并可选补充 slug/description)。

Suggested change
title: Radxa SBC 添加 Device Tree Overlay
title: Radxa SBC 添加 Device Tree Overlay
sidebar_position: 1

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:在 front matter 中添加了 sidebar_position: 1

---
Comment on lines +1 to +3
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增了 docs/radxa-dto-guide.md,但 i18n/en/docusaurus-plugin-content-docs/current/ 下没有对应镜像文件;仓库里有 scripts/agent-doc-drift-guard.sh 会对新增的 docs/i18n 路径漂移进行门禁(需要在同一 PR 添加英文镜像文件,或更新 .github/agent-doc-drift-baseline.md 将该漂移纳入基线)。

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该文档目前仅有中文版本,英文 i18n 文件待产品侧确认具体内容后再补充。

建议方案:1) 此次 PR 先合并中文版;2) 英文翻译在后续单独 PR 中补充;或 3) 更新 `.github/agent-doc-drift-baseline.md` 将该路径漂移纳入基线豁免。请确认您倾向的处理方式。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. A few points to clarify:

  1. The new file is at the repo root (not under ), so the expected i18n path would be rather than under .

  2. The repository does not currently have or - the guard script referenced in this comment does not exist yet.

  3. The English i18n tree () was removed in this PR, so there is currently no English version of this guide in the i18n structure.

Could you clarify: (a) is an English translation of this guide expected to be added in this PR, or (b) should this be treated as a future i18n requirement and tracked separately? Happy to add the English file or update a baseline once the expected path is confirmed.


# Radxa SBC 添加 Device Tree Overlay

本文介绍如何在 Radxa SBC(如 ROCK 3A、ROCK 3B、E23、E25、CM3 等)上添加自定义 Device Tree Overlay(设备树overlay),而不需要直接修改内核的 DTS 文件。

## 概念说明

- **DTS**(Device Tree Source):设备树源码,文本格式
- **DTO**(Device Tree Overlay):设备树overlay,在已有设备树基础上做增量修改
- **DTC**(Device Tree Compiler):设备树编译器,将 DTS 编译为 DTB
- **`rsetup`**:Radxa 提供的外壳配置工具,用于管理 overlay

## 操作流程

### 第一步:克隆仓库并准备构建环境

```bash
git clone https://github.com/radxa-pkg/radxa-overlays
cd radxa-overlays

# 安装构建依赖
sudo apt build-dep . -y
```

### 第二步:找到对应 SoC 的目录

Overlay 文件按 SoC 平台分类存放:

```
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码块使用了未标注语言的围栏(```),会触发 agent-doc-lint 的 “unlabeled code fence” 校验失败。请为该代码块补充语言标注(例如 `text`/`console`)。

Suggested change
```
```text

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:将该代码块标注为 ```text

arch/arm64/boot/dts/rockchip/overlays/
├── rk3568-i2c1.dts # RK3568 平台
├── rk3588-i2c1.dts # RK3588 平台
├── ...
```

**注意**:overlay 文件名需要与主设备树中的节点名对应。例如 `&i2c1` 表示对主设备树中的 `i2c1` 节点做覆盖。

### 第三步:编写 Overlay DTS 文件

参考 `rk3568-i2c1.dts`:

```dts
/dts-v1/;
/plugin/;

/ {
metadata {
title = "Enable I2C1";
compatible = "radxa,rock-3a", "radxa,rock-3b", "radxa,e23", "radxa,e25",
"radxa,cm3s-io", "radxa,radxa-cm3-sodimm-io";
category = "misc";
exclusive = "GPIO0_B4", "GPIO0_B3";
description = "Enable I2C1.
On Radxa ROCK 3A this is SDA pin 27 and SCL pin 28.
On Radxa ROCK 3B this is SDA pin 27 and SCL pin 28.
On Radxa E23 this is SDA pin 36 and SCL pin 40.
On Radxa E25 this is SDA pin 1 and SCL pin 10.
On Radxa CM3S IO this is SDA pin3 and SCL pin 5";
};
};

&i2c1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&i2c1_xfer>;
};
```

#### metadata 字段说明

| 字段 | 说明 |
|------|------|
| `title` | overlay 名称,在 `rsetup` 菜单中显示 |
| `compatible` | 适用设备列表,必须与主设备树的 compatible 匹配 |
| `category` | 分类,如 `misc`、`display`、`audio` 等 |
| `exclusive` | 互斥的 GPIO 引脚,与其他 overlay 冲突时提示 |
| `description` | 详细说明,在 rsetup UI 中可见 |
Comment on lines +74 to +80
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该表格的表头行以 || 开头(双竖线),会导致 Markdown 渲染/格式化不一致。建议按常规表格语法使用单个 | 开头(例如 | 字段 | 说明 |)。

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

经检查,当前表格的表头已使用标准单竖线语法 `| 字段 | 说明 |`,未发现双竖线问题。如果在渲染后发现异常,请告知具体 URL 以便进一步排查。


#### 常用 Overlay 操作

**启用节点**(如 I2C、SPI、UART):

```dts
&i2c1 {
status = "okay";
};
```

**修改节点属性**:

```dts
&uart2 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart2m1_xfer>;
};
```

**添加子节点**:

```dts
&i2c1 {
/* 添加一个设备到 i2c1 总线 */
myDevice@3c {
compatible = "vendor,my-device";
reg = <0x3c>;
};
};
```

### 第四步:编译打包

```bash
make deb
```

构建完成后会生成 `.deb` 包,位于上级目录:

```
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码块使用了未标注语言的围栏(```),会触发 agent-doc-lint 的 “unlabeled code fence” 校验失败。请为该代码块补充语言标注(例如 `text`/`console`)。

Suggested change
```
```text

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:将该输出块标注为 ```text

../radxa-overlays_*.deb
```

### 第五步:安装并应用

```bash
sudo apt install -y ../radxa-overlays_*.deb
```

### 第六步:使用 rsetup 启用 overlay

```bash
sudo rsetup
```

进入交互菜单:

```
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码块使用了未标注语言的围栏(```),会触发 agent-doc-lint 的 “unlabeled code fence” 校验失败。请为该代码块补充语言标注(例如 `text`/`console`)。

Suggested change
```
```text

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:将该代码块标注为 ```text

Radxa Overlay Configuration
├── Overlay: Enable I2C1 [ ] ← 勾选启用
├── Save and exit ← 保存退出
```

也可以用命令行:

```bash
# 查看可用 overlay
sudo rsetup --list

# 启用指定 overlay
sudo rsetup --enable-overlay rk3568-i2c1

# 禁用 overlay
sudo rsetup --disable-overlay rk3568-i2c1
```

## 完整示例:新增 SPI1 Overlay

假设在 RK3568 平台上需要启用 SPI1:

### 1. 创建文件

`arch/arm64/boot/dts/rockchip/overlays/rk3568-spi1.dts`:

```dts
/dts-v1/;
/plugin/;

/ {
metadata {
title = "Enable SPI1";
compatible = "radxa,rock-3a", "radxa,rock-3b", "radxa,e23", "radxa,e25";
category = "misc";
exclusive = "GPIO1_M1", "GPIO1_M2";
description = "Enable SPI1 on 40-pin header.";
};
};

&spi1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi1m1_xfer>;
};
```

### 2. 提交到 GitHub PR(推荐)

Fork 仓库后在你自己分支上提交 PR:

```bash
git checkout -b add-spi1-overlay
git add arch/arm64/boot/dts/rockchip/overlays/rk3568-spi1.dts
git commit -m "overlay: add SPI1 enable for RK3568 platforms"
git push origin add-spi1-overlay
# 然后在 GitHub 上提 PR
```

官方 merge 后,新 overlay 会随 `radxa-overlays` 包更新自动推送到设备。

## 方式二:本地编译后通过 rsetup 加载(无需 PR)

不想提 PR?可以直接在设备上编译,然后通过 rsetup 加载第三方 overlay。

### 第一步:克隆 overlay 仓库

```bash
git clone https://github.com/radxa/overlays.git
cd overlays
```

### 第二步:编写自己的 Overlay 文件

在对应目录创建 DTS 文件,例如 `arch/arm64/boot/dts/rockchip/overlays/rk3568-spi1.dts`。

### 第三步:编译 DTBO

```bash
# 编译单个 overlay 文件
dtc -I dts -O dtb -o arch/arm64/boot/dts/rockchip/overlays/rk3568-spi1.dtbo \
arch/arm64/boot/dts/rockchip/overlays/rk3568-spi1.dts

# 或者用项目自带的 Makefile
make
```

### 第四步:通过 rsetup 安装第三方 Overlay

```bash
sudo rsetup
```

进入菜单:

```
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码块使用了未标注语言的围栏(```),会触发 agent-doc-lint 的 “unlabeled code fence” 校验失败。请为该代码块补充语言标注(例如 `text`/`console`)。

Suggested change
```
```text

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:将该代码块标注为 ```text

Overlays
└── Install 3rd party overlay
```

然后选择你刚编译的 overlay(路径为 `arch/arm64/boot/dts/rockchip/overlays/*.dts`),确认后退出并重启。
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里说明“选择你刚编译的 overlay(路径为 .../*.dts)”,但上一步实际编译产物是 .dtbo(且第三方 overlay 一般也是安装/选择 .dtbo)。建议将此处的文件后缀与示例路径改为 .dtbo,避免读者按 .dts 选择导致失败。

Suggested change
然后选择你刚编译的 overlay(路径为 `arch/arm64/boot/dts/rockchip/overlays/*.dts`),确认后退出并重启。
然后选择你刚编译的 overlay(路径为 `arch/arm64/boot/dts/rockchip/overlays/*.dtbo`),确认后退出并重启。

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:已将路径和文件后缀改为 *.dtbo(编译产物为 .dtbo 文件)


### 第五步:验证

```bash
# 查看已加载的 overlay
cat /boot/extlinux/extlinux.conf

# 或检查 overlay 是否生效
ls /boot/dtb/rockchip/overlay/
```

---

## 附录

### 查找可用的节点名

查看主设备树源文件(需要内核源码):

```bash
# 查看主设备树中已有的 i2c 节点
grep -r "i2c[0-9]" arch/arm64/boot/dts/rockchip/ --include="*.dts" | head
```

### 查看当前已加载的 overlay

```bash
ls /boot/dtb/rockchip/overlay/ 2>/dev/null
# 或
cat /sys/kernel/debug/device-tree/overlay/ 2>/dev/null
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/sys/kernel/debug/device-tree/overlay/ 通常是目录(包含多个 overlay 节点),对目录执行 cat 会报错(Is a directory)。建议改为 ls/find 等方式列出内容,或指向具体的文件节点。

Suggested change
cat /sys/kernel/debug/device-tree/overlay/ 2>/dev/null
find /sys/kernel/debug/device-tree/overlay/ -mindepth 1 -maxdepth 1 2>/dev/null

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复:改为使用 find 命令列出目录内容,避免对目录执行 cat 报错

```

### rsetup 常用命令

```bash
rsetup --help
rsetup --list # 列出所有 overlay
rsetup --enable-overlay # 启用
rsetup --disable-overlay # 禁用
rsetup --reboot # 更改后重启
```

如果觉得改动有通用价值,欢迎提 PR 到 [radxa-pkg/radxa-overlays](https://github.com/radxa-pkg/radxa-overlays),官方 merge 后所有人就都能用了。
Loading