Click the above “Yikou Linux“, select “Star Public Account“
Practical benefits delivered to you first!
Introduction
This article is based on testing and verification of the HD-IMX6ULL-MB series development board, which is co-developed by Wuhan Xinluyao Technology Co., Ltd. and Wuhan Wanxiang Aoke Electronics Co., Ltd. This development board is designed based on the NXP iMX6ULL series Cortex-A7 high-performance processor and is suitable for rapid development of a series of innovative products such as human-machine interface industrial 4.0 scanners, on-board terminals, and portable medical devices.
1. Building Cross-Compiler with Buildroot
As mentioned earlier, if you want to build your own cross-compiler, you typically need two tools: crosstool-NG and Buildroot. However, it is important to understand that creating a cross-compiler is just the first step in embedded development. Subsequently, we also need to use the cross-compiler to port the bootloader, Linux kernel, and create the root filesystem (rootfs), and then use it to cross-compile various required applications. Among them, crosstool-NG only creates a cross-compiler, while if you want to accomplish all of these tasks with one click, you can use Buildroot.
If you are an embedded software engineer, it is essential to know what Buildroot is. In addition to creating cross-compilers, Buildroot provides a more efficient management method by integrating the bootloader, Linux, applications, and rootfs together. It allows for easy customization, management, compilation, and assembly of a complete software system tailored to your device, enabling us to develop a complete BSP and SDK for our embedded devices using Buildroot.
Next, we will introduce how to use Buildroot to create a cross-compiler while generating a root filesystem that can be used by the development board. It is important to note that since the Linux kernel and u-boot will need to be ported and modified specifically for the development board in the future, we will not compile the Linux kernel and u-boot programs here.
1.1 Introduction to Buildroot
The official website of Buildroot provides a clear definition and features of Buildroot: https://buildroot.org/.
-
The purpose of Buildroot is to make embedded Linux development easier;
-
Manage everything! Generate cross-compilation toolchains, filesystems, and cross-compile bootloaders and kernel images for embedded devices;
-
Easy to use! All configurations can be done through menuconfig, gconfig, and xconfig like Linux;
-
Supports a rich package resource to build the rootfs you need;
Here, we download the latest long-term support version of Buildroot from the official download address: buildroot-2021.02.7 and unzip it.
The entire Buildroot is composed of Makefile (*.mk) scripts and Kconfig (Config.in) configuration files. Therefore, you can configure it like configuring the Linux kernel by executing make menuconfig to compile a complete Linux system file (including bootloader, kernel, rootfs, and various libraries and applications in rootfs) that can be directly written to the machine for operation. The workflow for building open-source software packages is roughly as follows:
-
Acquire: Get the source code and unzip it;
-
Patch: Apply patches for bug fixes and added features, configure: Prepare the build process based on the environment;
-
Install: Copy binaries and auxiliary files to their target directories;
-
Package: Package binaries and auxiliary files for installation on other systems;
The workflow for building each software package is almost the same. Buildroot mainly automates these repetitive operations, allowing users to check the required packages, and it will automatically complete all the above operations. Secondly, the compilation workflow for U-boot and the Linux Kernel is similar, but with more custom parameters for configuration, which will also be generated once set up in Buildroot.
1.2 Buildroot Configuration
In the Buildroot source code path, there are many reference configuration examples, including the reference configuration for imx6ullevk. We do not need to configure all options from scratch; we will modify based on its configuration.
If you are using SecureCRT to remotely log into the Linux server, you need to use the command export TERM=vt100 to configure the TERM environment variable; otherwise, the subsequent configuration may not allow input. Next, execute make menuconfig to configure the cross-compiler creation.
Below is the Buildroot configuration interface, and we will configure it accordingly. During the configuration process:
-
Use the up and down keys to select menus;
-
Use the Tab key to select the bottom line’s <Select> or <Exit> ;
-
Press h on an option to refer to the configuration help information for that option;
-
Use the spacebar to select or enable an option, or use y or n to enable or disable that option; if it is an option that requires input, press Enter to enter input;
In the Target options section, the architecture information for the cross-compiler is configured here. Since all processors of our development board i.MX6ULL sample the Cortex-A7 architecture with NEON floating-point operations, the default configuration is as follows.
In the Build options section, the following modifications are mainly made:
-
($(TOPDIR)/tarballs) Download dir modifies the specified download path for the source package;
-
(/opt/buildroot/cortexA7) Host dir modifies the specified installation path for the cross-compiler;
-
libraries (both static and shared) modifies the selection to enable static libraries, which may be needed during program compilation or learning.
In the Toolchain section, the following modifications are made:
-
C library selects (glibc);
-
Kernel Headers selects (Linux 5.10.x kernel headers);
-
[*] Enable C++ support selects support for the C++ compiler; if you want to support other languages (Fortran, D language), you can also select them;
-
The versions of gcc and binutils use the default versions.
In the System configuration section, the related information for the root filesystem is configured, and the following modifications are made:
-
(imx6ull) System hostname sets the hostname of the development board, which is saved in the root filesystem tree /etc/hostname file;
-
(Welcome to LingYun iMX6ULL Board, default password ‘12345’.) System banner sets the boot prompt message, which is saved in the root filesystem tree /etc/issue file;
-
/dev management (Dynamic using devtmpfs + mdev) sets the default program for device management, which uses mdev provided by busybox; it can also choose udev;
-
(12345) Root password sets the default password for the root account when logging into the development board as 12345;
-
Remove the custom scripts to run after creating filesystem images that are set; we do not need them;
The kernel options mainly configure the compilation of the Linux kernel; we will port and compile the Linux kernel ourselves in the future, so do not select this option.
The target packages option has a large number of application or open-source library compilation options. If you want to include them in the root filesystem tree, you can make the appropriate selections here.
Here are some recommended software packages you can choose:
The Filesystem images option specifies the type of root filesystem image to generate. Since we will create the system image ourselves in the future, there is no need to generate it here. We only need to package the root filesystem tree and compress it using bzip2.
The Bootloaders option mainly configures the compilation of u-boot. We will port and compile U-boot ourselves in the future, so do not select this option.
The Host utilities are some tools that are dependent on the X86 host during the Buildroot compilation process. You can deselect some that can be removed to save compilation time;
The Legacy config options are some deprecated software packages that are generally not needed;
After completing the configuration, select <Exit> to exit and save the configuration. These configurations will be saved in the hidden file .config in the current path. The subsequent compilation process will select and download the relevant programs or code based on the configurations in this file.
1.3 Buildroot Compilation
First, create the installation path for the cross-compiler. Be careful not to use the root account to create the cross-compiler, otherwise, you may damage your
Linux system.
Next, we will start the cross-compilation process. The time for this process depends on the performance of the PC and the number of options selected. My
Linux server processor is Intel(R) Xeon(R) CPU E31235 @ 3.20GHz, 4 cores 8 threads, so I will use the command make -j8
to compile using 8 processes simultaneously.
After successful compilation, the output is as follows:
The source code packages downloaded during the compilation process will be placed in the tarballs folder:
The generated root filesystem tree will be placed in the output/images/ folder:
The generated cross-compiler will be located at /opt/buildroot/cortexA7 path:
We can check the version information of the generated cross-compiler using the following command:
1.4 Buildroot Testing
Next, we will use the generated cross-compiler to cross-compile the previously written hello.c test program and run the test on the ARM development board. It is important to note that because the newly created cross-compiler has a different version of the C runtime library from that running on the development board, we must add -static for static linking, so that the compiled program can run on the development board.
Download and run the test on the ARM development board:
Copyright Statement
All content of this document is authored by Engineer Guo from Lingyun Laboratory, mainly for internal use in Lingyun Embedded Linux teaching. The copyright belongs to the author personally. No media, website, or individual may reproduce, link, repost, or otherwise copy and publish/disseminate without the author’s agreement and authorization. Authorized media and websites must indicate the source when downloading and using; otherwise, the author will pursue legal responsibility.
-
Copyright (C) 2021 Lingyun IoT Intelligent Science Laboratory · Engineer Guo
end
Yikou Linux
Follow, reply 【1024】 to receive a wealth of Linux materials
Collection of Wonderful Articles
Article Recommendations
Click “Read Original” for more shares, welcome to share, collect, like, and view