I. Environment Preparation Prerequisites
Before setting up the Rockchip build environment, ensure the host machine meets the following basic requirements to ensure compatibility and stability for Docker image construction and container operation.
1. Host System Requirements
- System Type: Debian or Ubuntu operating system (Ubuntu 20.04/22.04 recommended)
- Architecture: x86_64 (64-bit) architecture
- Verification Commands:
# Check system version information cat /etc/os-release# Check system architecture (should return x86_64) uname -m
2. Docker Engine Installation
- Core Requirement: Docker engine must be installed on the host machine and the service must be running normally
- Installation Steps (Debian/Ubuntu):
# 1. Update system package index sudo apt-get update
2. Install dependency packages
sudo apt-get install -y ca-certificates curl gnupg lsb-release
3. Add Docker official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
4. Set up Docker stable repository
echo “deb [arch=(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu (lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5. Install Docker engine components
sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io
6. Start Docker service and set to start on boot
sudo systemctl start docker && sudo systemctl enable docker
- **Installation Verification**:
```bash
# Check Docker version
docker --version
# Check Docker service status (should show active (running))
sudo systemctl status docker
3. Loop Device Partition Support Configuration
- Configuration Purpose: Enable partition scanning for Loop devices to ensure automatic recognition and creation of image file partition nodes (max_part parameter must be greater than 0)
- Complete Configuration Process:
- Check current configuration value:
cat /sys/module/loop/parameters/max_part
# Edit GRUB configuration file sudo nano /etc/default/grub # Append loop.max_part=8 to GRUB_CMDLINE_LINUX line (preserve existing parameters) GRUB_CMDLINE_LINUX="quiet splash loop.max_part=8" # Save and update GRUB configuration (use sudo update-grub2 for UEFI systems) sudo update-grub # Reboot system for configuration to take effect sudo reboot- Verify configuration after reboot:
cat /sys/module/loop/parameters/max_part # Result must be greater than 0
- Check current configuration value:
II. Docker Image Construction
1. Writing Dockerfile
Create a Dockerfile in the host working directory with the following content (preinstalls toolchain required for Rockchip compilation):
# Base image: Ubuntu 22.04
FROM ubuntu:22.04
# Environment variable configuration (disable interactive installation)
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
# Install basic system tools
RUN apt-get update && \
apt-get install -y --no-install-recommends \
tzdata sudo vim wget curl ca-certificates gnupg lsb-release software-properties-common
# Install compilation and cross-compilation dependency tools
RUN apt-get install -y --no-install-recommends \
# Basic compilation tools
build-essential gcc-aarch64-linux-gnu bison flex libssl-dev bc \
# Image packaging and device management tools
rsync kmod cpio xz-utils fakeroot parted udev dosfstools uuid-runtime \
# Version control and device tree compilation tools
git-lfs device-tree-compiler \
# Python environment and dependencies
python2 python3 python-is-python3 python3-pyelftools python3-setuptools \
python3-distutils python3-pkg-resources swig libfdt-dev libpython3-dev \
# Virtualization and emulation tools
qemu-user-static qemu-system-arm qemu-efi u-boot-tools binfmt-support debootstrap \
# Other auxiliary tools
dctrl-tools libelf-dev dwarves gawk gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
# Clean installation cache to reduce image size
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Set container working directory
WORKDIR /workspace
# Default container startup command (enter bash terminal)
CMD ["/bin/bash"]
2. Executing Image Construction
Execute the following command in the directory containing the Dockerfile to build an image named rockchip-ubuntu-env:
docker build -t rockchip-ubuntu-env .
- Parameter Explanation:
-t rockchip-ubuntu-env: Specifies the image name, which can be customized as needed.: Indicates the Dockerfile is in the current directory
Build Notes: The first build requires downloading the base image and dependency packages, which takes a long time (depending on network speed); to rebuild, you can add the --no-cache parameter to ignore the cache.
III. Container Operation and Usage
1. Container Startup Command
Use the following command to start the container and mount necessary host resources to ensure normal compilation and device access:
docker run --privileged -it --rm \
-v $(pwd):/workspace \
-v /lib/modules:/lib/modules \
-v /dev:/dev \
rockchip-ubuntu-env
- Key Parameter Explanations:
--privileged: Grants container privileged mode, allowing access to host hardware devices-it: Runs in interactive terminal mode, supporting command line operations--rm: Automatically deletes the container after exit to avoid residual temporary files (remove this parameter if you need to keep the container)-v $(pwd):/workspace: Mounts the current host directory to /workspace in the container for bidirectional file synchronization-v /lib/modules:/lib/modules: Shares host kernel modules to ensure driver compatibility-v /dev:/dev: Mounts host device directory to support access to physical devices such as development boards and USB drives
2. Container Environment Verification
After entering the container, verify that core tools are installed correctly with the following commands:
# Verify cross-compiler version
aarch64-linux-gnu-gcc --version
# Verify Python environment
python --version
# Verify device tree compiler
dtc --version
# Verify QEMU emulation tool
qemu-system-arm --version
3. Common Operation Guide
- File Synchronization: The host and container /workspace directories are synchronized in real-time; you can edit code on the host and perform compilation operations in the container
- Permission Management: File permissions in the container are consistent with the host; it is recommended to use a user with the same UID as the host to avoid permission issues
- Container Exit: Execute the
exitcommand to exit the container; if the--rmparameter is enabled, the container will be automatically deleted, and compilation products will be saved in the host mount directory - Image Update: When you need to update the toolchain version, re-execute the
docker buildcommand to generate a new image
IV. Notes
- Source code and images are large in size; ensure the host has sufficient disk space >= 50GB
--privilegedmode is used to support hardware device access- After host kernel upgrade, it is recommended to restart the container to synchronize kernel modules in the
/lib/modulesdirectory - If network access through a proxy is required, you can add environment variables when starting the container:
--env http_proxy=http://proxy_address:port --env https_proxy=http://proxy_address:port - If dependency missing occurs during compilation, you can add the corresponding dependency package in the Dockerfile and rebuild the image
Through the above steps, you can quickly set up a standardized Rockchip compilation environment, effectively avoiding dependency conflicts caused by differences in host systems, and improving development efficiency and environment consistency.