Skip to content
Draft
Show file tree
Hide file tree
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
182 changes: 182 additions & 0 deletions docs/common/dev/_dev-env.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
本文档介绍如何在 **x86 主机** 上搭建可用于 **Radxa Linux 内核 / U-Boot** 构建的 ARM64 开发环境。

## 推荐环境方案概览

根据 Radxa 内部实践和社区使用情况,推荐以下三种环境方案:

| 方案 | 特点 | 适用场景 |
| ------------------------- | -------------- | ------------------ |
| VS Code Dev Container | 最简单、零污染 | 日常开发、补丁调试 |
| ARM64 Docker 容器 | 稳定、可脚本化 | CI / 自动化构建 |
| systemd-nspawn ARM64 容器 | 无 Docker | 企业 / 受限环境 |

---

## 方案一:VS Code Dev Container

这是 **最方便部署环境** 的方式。

### 前置条件

- Docker / Docker Desktop
- Visual Studio Code
- VS Code 插件:`Remote - Containers`

### 使用方式

请参照 [内核开发](./dev-kernel.md) 克隆所需的源码

进入内核源码目录:

<NewCodeBlock tip="x86 Linux PC" type="PC">

```
code .
```

</NewCodeBlock>

radxa 提供的内核目录中存在 `.devcontainer/devcontainer.json`,VS Code 会提示:

```
Reopen in Container
```

确认后,VS Code 会自动拉起 ARM64 构建容器并进入开发环境。

如果没有提示,可以自行按`F1`或者`Ctrl+Shift+P`,输入 `DevContainers: Reopen in Container` 来启动容器。

该环境中已包含常用交叉编译工具链和构建依赖,无需手动安装。

---

## 方案二:ARM64 Docker 容器(命令行 / CI 推荐)

适合命令行用户或 CI 系统使用。

### 安装 docker/podman

<NewCodeBlock tip="x86 Linux PC" type="PC">

```
sudo apt install -y docker.io
sudo systemctl start docker
```

</NewCodeBlock>

### 启用多架构支持(仅首次)

<NewCodeBlock tip="x86 Linux PC" type="PC">

```
sudo apt install -y qemu-user-static binfmt-support
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
```

</NewCodeBlock>

### 启动 ARM64 Debian 容器

<NewCodeBlock tip="Host" type="Host">

```
docker run -it --rm \
--platform linux/arm64 \
-v "$(pwd):/workspace" \
-w /workspace \
arm64v8/debian:12 \
bash
```

</NewCodeBlock>

### 安装基础构建依赖

<NewCodeBlock tip="Container" type="Container">

```bash
apt update
apt install -y \
build-essential bc kmod cpio flex bison \
libssl-dev libelf-dev \
debhelper dh-make \
git
```

</NewCodeBlock>

该容器环境适用于:

- Linux Kernel 构建
- U-Boot 构建
- Debian 内核包生成

---

## 方案三:systemd-nspawn ARM64 容器(无 Docker)

适用于无法使用 Docker 的 Linux 主机环境。

### 安装工具

<NewCodeBlock tip="x86 Linux PC" type="PC">

```bash
sudo apt install -y \
systemd-container \
qemu-user-static \
debootstrap \
debian-archive-keyring
```

</NewCodeBlock>

### 创建 ARM64 rootfs

<NewCodeBlock tip="x86 Linux PC" type="PC">

```bash
sudo debootstrap --arch=arm64 \
bookworm /var/lib/machines/debian12-arm64 \
http://deb.debian.org/debian
```

</NewCodeBlock>

:::tip
若网络遇到问题,可将 `http://deb.debian.org/debian` 替换为国内镜像源,例如: `https://mirrors.tuna.tsinghua.edu.cn/debian/`
:::

### 进入容器

<NewCodeBlock tip="x86 Linux PC" type="PC">

```bash
sudo systemd-nspawn -D /var/lib/machines/debian12-arm64
```

</NewCodeBlock>

### 安装构建依赖

<NewCodeBlock tip="Container" type="Container">

```bash
apt update
apt install -y \
build-essential bc kmod cpio flex bison \
libssl-dev libelf-dev \
debhelper dh-make \
git
```

</NewCodeBlock>

---

## 注意事项

- 若在 **ARM64 原生设备** 上开发,可直接编译,无需 QEMU
- 构建环境仅用于 **编译**,不涉及刷机或启动配置
- Kernel 与 U-Boot 构建流程在后续文档中分别说明
153 changes: 153 additions & 0 deletions docs/common/dev/_dev-kernel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
本文档介绍如何使用 **Radxa 官方 Linux 内核仓库** 构建 ARM64 内核,并生成可安装的 Debian 内核包。

:::tip
请先确保已配置好开发环境,并且在容器内进行操作。具体请参考:[ARM64 内核开发环境准备](./dev-env)
:::

## 选择正确的内核仓库

Radxa 为不同平台维护独立内核仓库,命名格式为:

```
https://github.com/radxa-pkg/linux-<profile>
```

#### Profile 对照表

| 设备 | Profile |
| ------------------------------------- | ------------ |
| ROCK 5A / 5B / 5B\+ / 5C / 5T / 5 ITX | rk2410 |
| ROCK 2A/ROCK 2F/ E20C/E24C | rk2312 |
| E52C / E54C / NX5 / CM5 | rk2410 |
| ROCK 3 系列 / ZERO 3 / CM3 | rk2410-nocsf |
| ROCK Pi 4 / ROCK 4(除 4D) | rk2501 |
| ROCK 4D | rk2410-nocsf |
| Dragon Q6A | qcom |
| AIRBox Q900 | qc2509 |
| Cubie A7A / A7Z | a733 |
| Orion O6 / O6N | sky1 |

---

## 克隆内核源码

:::tip
请先确保已配置好开发环境,并且在容器内进行操作。
:::

克隆时必须包含子模块:

<NewCodeBlock tip="Container" type="Container">

```
git clone --recurse-submodules \
https://github.com/radxa-pkg/linux-rk2410.git
cd linux-rk2410
```

</NewCodeBlock>

若克隆时遗漏子模块,可在仓库目录中补齐:

<NewCodeBlock tip="Container" type="Container">

```
git submodule update --init --recursive
```

## </NewCodeBlock>

## 构建 Debian 内核包(推荐)

适用于 RadxaOS / Debian / Ubuntu 系统,推荐优先使用该方式。

#### 安装构建依赖

<NewCodeBlock tip="Container" type="Container">

```
sudo apt build-dep .
```

</NewCodeBlock>

#### 配置内核

- 如果你需求修改内核源码,可直接编辑 `src` 目录下的源码文件。
- 如果你需求修改内核配置文件,可以修改 `/debian/patches/linux/`目录下的 patch 文件

#### 构建内核包

<NewCodeBlock tip="Container" type="Container">

```
make deb
```

</NewCodeBlock>

生成的文件包括:

- linux-image-\*.deb
- linux-headers-\*.deb

---

## 手动构建(高级)

适用于需要自定义内核配置或不生成 Debian 包的高级场景。

<NewCodeBlock tip="Container" type="Container">

```
cd src
make menuconfig
make -j"$(nproc)"
```

</NewCodeBlock>

---

## 安装与验证

### 安装内核

需要退出容器环境,并将产物拷贝到 SBC 板端系统

<NewCodeBlock tip="Container" type="Container">

```
exit
```

</NewCodeBlock>

后面的步骤在 SBC 板端系统进行:

<NewCodeBlock tip="SBC" type="device">

```bash
sudo dpkg -i linux-image-*.deb linux-headers-*.deb
sudo reboot
```

</NewCodeBlock>

### 验证

<NewCodeBlock tip="SBC" type="device">

```
uname -r
zcat /proc/config.gz | grep CONFIG_XXX
```

</NewCodeBlock>

---

## 注意事项

- 克隆仓库时必须使用 `--recurse-submodules`,否则可能因缺失子模块导致构建失败。
- 内核安装后是否生效,取决于启动加载器和启动配置是否正确加载了新内核。
10 changes: 10 additions & 0 deletions docs/rock5/rock5b/low-level-dev/dev-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
sidebar_position: 2
description: "Radxa 开发环境配置"
---

import DEVENV from '../../../common/dev/\_dev-env.mdx'

# 开发环境准备

<DEVENV />
10 changes: 10 additions & 0 deletions docs/rock5/rock5b/low-level-dev/dev-kernel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
sidebar_position: 3
description: "Radxa kernel 开发"
---

import KERNEL from '../../../common/dev/\_dev-kernel.mdx'

# Kernel 开发

<KERNEL/>
10 changes: 0 additions & 10 deletions docs/rock5/rock5b/low-level-dev/kernel.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/rock5/rock5b/low-level-dev/u-boot.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 2
sidebar_position: 4
description: "用 Radxa BSP 工具,轻松构建个性化 U-boot,开启智能硬件的创新之旅"
---

Expand Down
Loading
Loading