0%

OrangePi-3B 折腾笔记—— 准备构建环境

OrangePi-3B 系列笔记:

编译环境

  • 主板: OrangePi-3b
  • 芯片: RK3566
  • 环境: Debian(12-x86_64) + Docker(Debian:12)

内容说明

为了编译项目而不污染操作系统,笔记记录的操作都是使用的 DockerDebian 12 的容器来完成的。

这一篇文章主要是记录一下之前使用到的编译环境,方便今后快速调用。

这篇笔记其实是在搞完 U-BootKernelRootFS 之后才整理出来的,但是为了方便一些按照这个系列文章实验的同学阅读,这里将它的顺序调整到第二篇。

所以这篇笔记是开了上帝视角,提前记录了后续构建系统要用到的软件包。不过都有明显的用途记录,方便理解。

创建镜像

docker build -t linux-build - <<\EOF
FROM debian:12

RUN \
sed -e 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' -i.bak /etc/apt/sources.list.d/debian.sources && \
apt update && \
apt install -y sudo wget curl vim bash-completion command-not-found git patchutils && \
apt update && \
apt clean &&  rm -rf /var/lib/apt/lists/*

RUN \
apt update && \
# linaro toolchain
apt install -y xz-utils && \
LINARO_GCC_SITE=https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/ && \
LINARO_GCC_ARM=arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz && \
LINARO_GCC_AARCH64=aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz && \
wget -q -O - ${LINARO_GCC_SITE}${LINARO_GCC_ARM}/ | tar -Jxvf - -C /opt/ && \
wget -q -O - ${LINARO_GCC_SITE}${LINARO_GCC_AARCH64}/ | tar -Jxvf - -C /opt/ && \
apt clean &&  rm -rf /var/lib/apt/lists/*

RUN \
apt update && \
# toolchain
apt install -y make gcc gcc-arm-linux-gnueabi gcc-aarch64-linux-gnu && \
# make menuconfig
apt install -y libncurses-dev && \
# u-boot
apt install -y bc bison flex swig libssl-dev python3 python3-dev python3-setuptools python3-pyelftools python3-cryptography && \
# u-boot rockchip
apt install -y device-tree-compiler && \
ln -s /bin/python3 /bin/python2 && \
ln -s /bin/python3 /bin/python && \
# kernel
apt install -y flex bison bc libssl-dev cpio && \
# kernel rockchip
apt install -y u-boot-tools xz-utils lz4 && \
# rootfs
apt install -y debootstrap binfmt-support qemu-user-static u-boot-tools initramfs-tools android-sdk-libsparse-utils e2fsprogs file fdisk gdisk parted && \
\
apt clean &&  rm -rf /var/lib/apt/lists/*

RUN \
echo "alias ll='ls -lh -F --color=auto --time-style=long-iso'" >> /etc/profile.d/aliases.sh && \
echo "alias la='ls -lhA -F --color=auto --time-style=long-iso'" >> /etc/profile.d/aliases.sh && \
echo "alias lt='ls -lht -F --color=auto --time-style=long-iso'" >> /etc/profile.d/aliases.sh && \
echo "alias lat='ls -lhAt -F --color=auto --time-style=long-iso'" >> /etc/profile.d/aliases.sh

ENV TZ=Asia/Shanghai
RUN \
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

USER user
WORKDIR /home/user/
EOF
  1. 使用管道输入 Dockerfile 内容,自定义镜像标签为 linux-build
    https://docs.docker.com/build/building/context/#how-to-build-without-a-context
  2. 使用 apt 安装的 gcc-arm-linux-gnueabigcc-aarch64-linux-gnu 版本为 12.2.0,用来编译较新的项目源码。
  3. 手动安装的 gcc-linaro-7.5.0-2019.12 用来编译旧版本的项目源码。

镜像使用

docker run -ti --rm \
    \
    -v ~/projects/rkbin/:/projects/rkbin/ \
    -v ~/projects/u-boot/:/projects/u-boot/ \
    \
    -v ~/projects/kernel/:/projects/kernel/ \
    \
    --privileged \
    -v ~/projects/rootfs-build/:/projects/buildfs/ \
    \
    linux-build bash
  1. 项目存放路径均是:~/projects/

如果路径一致,可以这样:

docker run -ti --rm --privileged -v ~/projects/:/projects/ linux-build bash -l
  1. 默认 shellnon-loginshell,需要使用 '-l' 参数登录以生效 /etc/profile 配置。
    https://github.com/gliderlabs/docker-alpine/issues/443