7.2.1 Development Environment Setup and Compilation Instructions
This chapter introduces the requirements and setup of the cross-compilation development environment, as well as instructions for downloading the source code and compiling the system image.
Cross-compilation Development Environment
Cross-compilation refers to developing and building software on a host machine, and then deploying the built software to a development board for execution. The host machine generally has higher performance and memory than the development board, which can accelerate code building and install more development tools for convenient development.
Host Compilation Environment Requirements
It is recommended to use Ubuntu operating system. If using other system versions, adjustments may be needed for the compilation environment.
For Ubuntu 18.04 system, install the following packages:
sudo apt-get install -y build-essential make cmake libpcre3 libpcre3-dev bc bison \
flex python-numpy mtd-utils zlib1g-dev debootstrap \
libdata-hexdumper-perl libncurses5-dev zip qemu-user-static \
curl git liblz4-tool apt-cacher-ng libssl-dev checkpolicy autoconf \
android-tools-fsutils mtools parted dosfstools udev rsync
For Ubuntu 20.04 system, install the following packages:
sudo apt-get install -y build-essential make cmake libpcre3 libpcre3-dev bc bison \
flex python-numpy mtd-utils zlib1g-dev debootstrap \
libdata-hexdumper-perl libncurses5-dev zip qemu-user-static \
curl git liblz4-tool apt-cacher-ng libssl-dev checkpolicy autoconf \
android-sdk-libsparse-utils android-sdk-ext4-utils mtools parted dosfstools udev rsync
For Ubuntu 22.04 system, install the following packages:
sudo apt-get install -y build-essential make cmake libpcre3 libpcre3-dev bc bison \
flex python3-numpy mtd-utils zlib1g-dev debootstrap \
libdata-hexdumper-perl libncurses5-dev zip qemu-user-static \
curl repo git liblz4-tool apt-cacher-ng libssl-dev checkpolicy autoconf \
android-sdk-libsparse-utils mtools parted dosfstools udev rsync
Install Python
Compiling the Linux kernel requires a Python 2 environment. Starting from version Ubuntu 22.04, Python 2 is no longer installed by default. Therefore, you need to execute the following command to install it:
sudo apt install python2
Compiling Debian packages requires a Python 3 environment. Use the following commands to set the Python selector and install python3-setuptools and pip, which are dependency tools for generating wheel packages:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
sudo update-alternatives --list python
apt-get install python3-setuptools
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Installing Cross-Compilation Toolchain
Execute the following command to download the cross-compilation toolchain:
curl -fO http://archive.d-robotics.cc/toolchain/gcc-ubuntu-9.3.0-2020.03-x86_64-aarch64-linux-gnu.tar.xz
Unzip and install it. It is recommended to install it under the /opt directory. Usually, writing data to the /opt directory requires sudo permission, for example:
sudo tar -xvf gcc-ubuntu-9.3.0-2020.03-x86_64-aarch64-linux-gnu.tar.xz -C /opt
Configure environment variables for the cross-compilation toolchain:
export CROSS_COMPILE=/opt/gcc-ubuntu-9.3.0-2020.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
export LD_LIBRARY_PATH=/opt/gcc-ubuntu-9.3.0-2020.03-x86_64-aarch64-linux-gnu/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
export PATH=$PATH:/opt/gcc-ubuntu-9.3.0-2020.03-x86_64-aarch64-linux-gnu/bin/
export ARCH=arm64
The above commands configure the environment variables temporarily. To make the configuration permanent, you can add the above commands to the environment variable files ~/.profile
or ~/.bash_profile
at the end.
Compiling Environment Source Code (rdk-gen)
rdk-gen is used to build a custom operating system image for the D-Robotics RDK X3. It provides a scalable framework that allows users to customize and build the Ubuntu operating system for RDK X3 according to their needs.
Download the source code:
git clone https://github.com/D-Robotics/rdk-gen.git
After downloading, the directory structure of rdk-gen is as follows:
Directory | Description |
---|---|
pack_image.sh | Code entry for building system images |
download_samplefs.sh | Download the pre-made base Ubuntu file system |
download_deb_pkgs.sh | Download D-Robotics's deb packages, including kernel, multimedia libraries, sample code, tros.bot, etc., which need to be pre-installed in the system image |
hobot_customize_rootfs.sh | Customized modification of the Ubuntu file system |
source_sync.sh | Download source code, including bootloader, uboot, kernel, example code, etc. |
mk_kernel.sh | Compile kernel, device tree, and driver modules |
mk_debs.sh | Generate deb packages |
make_ubuntu_samplefs.sh | Code for creating Ubuntu system filesystem, which can be modified to customize samplefs |
config | Store the contents that need to be placed in the /hobot/config directory of the system image, a VFAT-rooted partition. If the SD card boot method is used, users can directly modify the contents of this partition in the Windows system. |
Compiling the System Image
Run the following command to package the system image:
cd rdk-gen
sudo ./pack_image.sh
sudo privileges are required for compilation. After successful compilation, the system image file *.img
will be generated in the deploy directory.
Introduction to the Compilation Process of pack_image.sh
- Call the scripts download_samplefs.sh and download_deb_pkgs.sh to download samplefs and the required pre-installed deb packages from D-Robotics's file server.
- Extract samplefs and call the hobot_customize_rootfs.sh script to customize the filesystem configuration.
- Install deb packages into the filesystem.
- Generate the system image. Refer to Install OS for how to use the system image.
Downloading Source Code
Downloading source code is not required when running pack_image.sh
to compile the system image, because pack_image.sh
will directly download the official debian packages from D-Robotics's file server and install them into the system. Only when you need to modify the content of debian packages and re-create custom packages, you need to download the source code.
The source code of rdk-linux related linux kernel, bootloader, hobot-xxx packages are hosted on GitHub. Before downloading the code, please register and log in to GitHub, and add the SSH Key
of the development server to user settings through Generating a new SSH key and adding it to the ssh-agent method.
source_sync.sh
is used to download the source code, including bootloader, uboot, kernel, example code, etc. This download program downloads all the source code to the local computer by executing git clone git@github.com:xxx.git
.
Run the following command to download the main branch code (the latest release version branch maintained by the official):
./source_sync.sh -t main
Please execute the following command to download the code from the development branch (development branch, not fully tested, may have issues):
./source_sync.sh -t develop
If you want to download the source code that corresponds to the official system image version, such as the source code for the 2.0.0 version, please use the following command:
./source_sync.sh -t os-image_2.0.0
By default, the program will download the source code to the source
directory:
source
├── bootloader
├── hobot-boot
├── hobot-bpu-drivers
├── hobot-camera
├── hobot-configs
├── hobot-display
├── hobot-dnn
├── hobot-dtb
├── hobot-io
├── hobot-io-samples
├── hobot-kernel-headers