0%

OrangePi-3B 适配 AOSP —— 准备编译环境

OrangePi-3B 适配 AOSP 系列笔记:

温馨提示:

  1. OrangePi-3B 硬件版本 V1.1.1 的板子出现过有线网卡“无故”失灵的故障, 所以在进行操作前请确认开发板工作良好(修复这个问题需要更换 RK3566 芯片).
    https://www.bilibili.com/read/cv33224126
  2. 香橙派目前已经推出了硬件版本为 V2.1 的 OrangePi-3B, 有线网卡供应商更换为 RTL. 本系列文章没有针对 V2.1 的板子做过适配, 请根据实际情况操作(同时强烈谴责此种不负责任的行为, 如考虑购买此型号板子商用, 建议换个型号避坑).
  3. 本系列文章最后更新时间: 2026年11月20日, 实现了初始化 TEE 环境, 填了一个 ATF 关于GPU的坑.

编译环境

  • 主板: OrangePi-3b_V1.1.1
  • 芯片: RK3566
  • 环境: Debian:13_x86_64(Docker)

内容说明

为了编译源码而不污染操作系统,笔记记录的操作都是使用的 Docker 和 Debian 13 的容器来完成的。

镜像

基础环境镜像

构建镜像

docker build -t build-base - <<\EOF
FROM debian:13

RUN <<EOT
    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
    # 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
    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/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

USER user
WORKDIR /home/user/
EOF
  1. 使用管道输入 Dockerfile 内容,自定义镜像标签为 build-base。
    https://docs.docker.com/build/building/context/#how-to-build-without-a-context
  2. 使用 Here-Documents 运行 RUN、COPY 指令,注意如果是在 Dockerfile 中使用需要保证文件换行符是 LF。
    https://docs.docker.com/reference/dockerfile/#here-documents
  3. repo 工具若是无法下载,可以考虑使用 https://mirrors.tuna.tsinghua.edu.cn/git/git-repo 镜像代替。
  4. 备用镜像站:
    - mirrors.aliyun.com
    - mirrors.cernet.edu.cn
    - mirrors.tuna.tsinghua.edu.cn

使用镜像

docker run -ti --rm build-base bash -l
  1. 默认为 non-login 的 shell,需要使用 ‘-l’ 参数登录以生效 /etc/profile 配置。
    https://github.com/gliderlabs/docker-alpine/issues/443

编译环境镜像

构建镜像

docker build -t build-android - <<\EOF
FROM build-base
USER root

# AOSP
RUN <<EOT
    apt update
    # base
    apt install -y libncurses5 cpio \
	    make gcc g++ gcc-arm-linux-gnueabi g++-arm-linux-gnueabi gcc-aarch64-linux-gnu g++-aarch64-linux-gnu clang
    # bazel
    apt install -y perl rsync
    # u-boot
    apt install -y bc bison build-essential coccinelle device-tree-compiler dfu-util efitools flex gdisk graphviz imagemagick liblz4-tool libgnutls28-dev libguestfs-tools libncurses-dev libpython3-dev libsdl2-dev libssl-dev lz4 lzma lzma-alone openssl pkg-config python3 python3-asteval python3-coverage python3-filelock python3-pkg-resources python3-pycryptodome python3-pyelftools python3-pytest python3-pytest-xdist python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme python3-subunit python3-testtools python3-virtualenv swig uuid-dev xxd
    # kernel
    apt install -y bc binutils bison dwarves flex gcc git make openssl pahole perl-base libssl-dev libelf-dev
    # android
    apt install -y git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev x11proto-core-dev libx11-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip procps
    # mesa
    apt install -y python3-pip pkg-config \
	    llvm llvm-19-dev libclang-19-dev libclang-cpp19-dev \
        libclang-common-19-dev libclc-19-dev libllvmspirvlib-19-dev spirv-tools libdrm-dev
    pip install -i https://mirrors.aliyun.com/pypi/simple/ --break-system-packages \
	    meson ninja mako pyyaml packaging
	# clean
    apt clean &&  rm -rf /var/lib/apt/lists/*
EOT

# LineageOS
RUN <<EOT
    apt update
    # lineage 22 toolchain
    apt install -y bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick protobuf-compiler python3-protobuf lib32readline-dev lib32z1-dev libdw-dev libelf-dev libgnutls28-dev lz4 libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
    # lineage 23 toolchain
    apt install -y bc bison build-essential ccache curl erofs-utils flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick protobuf-compiler python3-protobuf lib32readline-dev lib32z1-dev libdw-dev libelf-dev libgnutls28-dev lz4 libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc xxd zip zlib1g-dev
    # extract files toolchain
    apt install -y python3 python-is-python3 e2fsprogs
    # clean
    apt clean &&  rm -rf /var/lib/apt/lists/*
EOT

USER user
EOF
  1. Android 中的 gcc-multilib、g++-multilib、libc6-dev-i386、lib32ncurses5-dev 和 lib32z-dev 依赖和交叉编译工具链互斥, 因此没有安装.
  2. LineageOS 软件列表请参考: https://wiki.lineageos.org/devices/sagit/build#install-the-build-packages

使用镜像

docker run -ti --rm --privileged -v ~/projects/:/projects/ build-android bash -l

源码

启用 git lfs

git lfs install

配置镜像

cat >> ~/.gitconfig <<EOF
#[http "https://gerrit.googlesource.com/"]
#    proxy = socks5://<IP>:<PORT>
#[http "https://android.googlesource.com/"]
#    proxy = socks5://<IP>:<PORT>

[url "https://mirrors.tuna.tsinghua.edu.cn/git/git-repo"]
    insteadof = https://gerrit.googlesource.com/git-repo
[url "https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/"]
    insteadof = https://android.googlesource.com/
EOF

有时候镜像源可能出现代码尚未完成同步的情况, 这个时候建议屏蔽镜像开启代理尝试直接同步.

参考