OrangePi-3B 系列笔记:
- OrangePi-3B 移植 Linux —— 认识开发板
- OrangePi-3B 移植 Linux —— 准备构建环境
- OrangePi-3B 移植 Linux —— 构建 U-Boot
- OrangePi-3B 移植 Linux —— 构建 Kernel
- OrangePi-3B 移植 Linux —— 点亮 LCD 屏幕
- OrangePi-3B 移植 Linux —— 移植 WiFi & BT 驱动
- OrangePi-3B 移植 Linux —— 构建文件系统镜像
温馨提示:
- OrangePi-3B 硬件版本 V1.1.1 的板子出现过有线网卡“无故”失灵的故障, 所以在进行操作前请确认开发板工作良好(修复这个问题需要更换 RK3566 芯片).
https://www.bilibili.com/read/cv33224126- 香橙派目前已经推出了硬件版本为 V2.1 的 OrangePi-3B, 有线网卡供应商更换为 RTL. 本系列文章没有针对 V2.1 的板子做过适配, 请根据实际情况操作(同时强烈谴责此种不负责任的行为, 如考虑购买此型号板子商用, 建议换个型号避坑).
- 本系列文章最后更新时间: 2026年11月, 移植了 OP-TEE ,已确认环境可用.
编译环境
- 主板: OrangePi-3b_V1.1.1
- 芯片: RK3566
- 环境: Debian:13_x86_64(Docker)
内容说明
为了编译项目而不污染操作系统,笔记记录的操作都是使用的 Docker 和 Debian 12 的容器来完成的。
这一篇文章主要是记录一下之前使用到的编译环境,方便今后快速调用。
这篇笔记其实是在搞完 U-Boot、Kernel 和 RootFS 之后才整理出来的,但是为了方便一些按照这个系列文章实验的同学阅读,这里将它的顺序调整到第二篇。
所以这篇笔记是开了上帝视角,提前记录了后续构建系统要用到的软件包。不过都有明显的用途记录,方便理解。
镜像
基础环境镜像
构建镜像
docker build -t build-base - <<\EOF
FROM debian:13
RUN <<EOT
set -eux
sed -i -e 's|deb.debian.org|mirrors.cernet.edu.cn|g' /etc/apt/sources.list.d/debian.sources
apt update
# install base tool
apt install -y \
sudo bash-completion command-not-found procps vim wget curl net-tools file
# install version control
apt install -y \
git git-lfs subversion python3 python-is-python3
wget https://storage.googleapis.com/git-repo-downloads/repo -O /usr/local/bin/repo || exit 1
chmod +x /usr/local/bin/repo
# build command not found data
apt update
apt clean && rm -rf /var/lib/apt/lists/*
EOT
ENV TZ=Asia/Shanghai
RUN <<EOT
set -eux
useradd --create-home --uid 1000 --groups users,sudo --shell /bin/bash user
echo "user:1111" | chpasswd
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
echo "${TZ}" > /etc/timezone
EOT
COPY <<EOT /etc/profile.d/99-aliases.sh
alias ll='ls -lh -F --color=auto --time-style=long-iso'
alias la='ls -lhA -F --color=auto --time-style=long-iso'
alias lt='ls -lht -F --color=auto --time-style=long-iso'
alias lat='ls -lhAt -F --color=auto --time-style=long-iso'
EOT
RUN <<-"EOT" tee -a /home/user/.bashrc
export PS1="\D{%m/%d %H:%M:%S} $PS1"
EOT
USER user
WORKDIR /home/user/
EOF
- 使用管道输入
Dockerfile内容,自定义镜像标签为build-base。
https://docs.docker.com/build/building/context/#how-to-build-without-a-context- 使用
Here-Documents运行RUN、COPY指令,注意如果是在Dockerfile中使用需要保证文件换行符是LF。
https://docs.docker.com/reference/dockerfile/#here-documentsrepo工具若是无法下载,可以考虑使用https://mirrors.tuna.tsinghua.edu.cn/git/git-repo镜像代替。- 备用镜像站:
- mirrors.aliyun.com
- mirrors.cernet.edu.cn
- mirrors.tuna.tsinghua.edu.cn
使用镜像
docker run -ti --rm build-base bash -l
- 默认为
non-login的shell,需要使用 ‘-l’ 参数登录以生效/etc/profile配置。
https://github.com/gliderlabs/docker-alpine/issues/443
编译环境镜像
构建镜像
docker build -t build-linux - <<\EOF
FROM build-base
USER root
# LLVM sources
# RUN <<EOT
# set -eux
# codename=$(. /etc/os-release; echo "$VERSION_CODENAME")
# mirror=http://apt.llvm.org
# source=/etc/apt/sources.list.d/llvm.list
# {
# for v in $(seq 15 23); do
# echo "deb $mirror/$codename/ llvm-toolchain-$codename-$v main"
# done
#
# # 不带版本号 = 滚动仓库,当前对应 LLVM 24
# echo "deb $mirror/$codename/ llvm-toolchain-$codename main"
# } > "$source"
#
# wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
# EOT
RUN <<EOT
set -eux
apt update
# host toolchain
apt install -y \
build-essential libncurses-dev cmake clang
# cross compile toolchain
apt install -y \
gcc-12-arm-linux-gnueabihf g++-12-arm-linux-gnueabihf \
gcc-12-aarch64-linux-gnu g++-12-aarch64-linux-gnu
# u-boot toolchain
apt install -y \
bc bison flex swig uuid-dev libssl-dev libgnutls28-dev \
python3 python3-dev python3-setuptools python3-pyelftools python3-cryptography
# u-boot rockchip toolchain
apt install -y \
device-tree-compiler python-is-python3
# kernel toolchain
apt install -y \
flex bison bc libssl-dev cpio
# kernel patch toolchain
apt install -y \
patchutils
# kernel rockchip toolchain
apt install -y \
u-boot-tools xz-utils lz4
# rootfs toolchain
apt install -y \
debootstrap binfmt-support qemu-user-static u-boot-tools initramfs-tools \
android-sdk-libsparse-utils e2fsprogs file fdisk gdisk parted
# openwrt toolchain
apt install -y \
gcc g++ clang \
build-essential flex bison gawk \
gettext git libncurses5-dev libssl-dev \
python3-setuptools rsync swig unzip zlib1g-dev file wget
# clean
apt clean && rm -rf /var/lib/apt/lists/*
EOT
RUN <<'EOT'
set -eux
strip() {
local dir="$1"
local suffix="${2:-}"
if [ -n "$suffix" ]; then
for f in ${dir}*${suffix}; do
[ -e "$f" ] || continue
local name target
name="$(basename "$f")"
target="/usr/bin/${name%${suffix}}"
[ -e "$target" ] || ln -sf "$f" "$target"
done
else
for f in ${dir}*; do
[ -e "$f" ] || continue
local name target
name="$(basename "$f")"
target="/usr/bin/${name}"
[ -e "$target" ] || ln -sf "$f" "$target"
done
fi
}
strip /usr/bin/arm- -12
strip /usr/bin/aarch64- -12
# strip /usr/lib/llvm-24/bin/
EOT
USER user
EOF
OpenWRT中的gcc-multilib、g++-multilib和 Arm 交叉编译工具链互斥,因此没有安装。- 使用
apt安装的gcc-arm-linux-gnueabi和gcc-aarch64-linux-gnu版本为12.2.0,用来编译较新的项目源码。- 旧版本的
gcc-linaro-7.5.0-2019.12下载地址请参考:- 网络不好的可以加代理:
docker build -t build-linux --build-arg HTTPS_PROXY=socks5://<IP>:<PORT>。
使用镜像
docker run -ti --rm --privileged -v ~/projects/:/projects/ build-linux bash -l