Building Embedded U-Boot, Kernel, and File System with Yocto

Click the blue text above to follow Weilian Zhikong

You can click the … in the upper right corner to share this article

What is Yocto? In brief, it is a tool used to build U-Boot, kernel, file system, cross-compilation toolchain, etc. Yocto provides a complete and comprehensive embedded Linux porting solution. It allows embedded Linux system porting to say goodbye to the previous era of manual step-by-step source code porting. Yocto addresses the chaos in the embedded Linux industry by providing broad and consistent industry support for collaboration among chip manufacturers, operating systems, and device vendors.

For how to build U-Boot, kernel, and rootfs for i.MX6UL based on Yocto, NXP provides a guide titled “i.MX_Yocto_Project_User’s_Guide.pdf”. With reference to the official guide provided by NXP, we begin to build U-Boot, kernel, and rootfs file system for i.MX6UL based on Yocto.

Before building the system, a series of preparations are required:

1. Host computer’s Linux version: ubuntu16.04.2 LTS

2. Recommended host computer configuration: Intel i7 quad-core or above, 8G memory, SSD hard drive is better.

3. The host should reserve more than 150GB of disk space for setting up the Yocto environment.

4. The host must have proper internet access (preferably with a fast connection).

5. The build should be conducted in a normal user environment.

The following is the entire Yocto build process. If permission issues arise during the build process, use the sudo tool to resolve them.

(1) Install the required dependencies for the Yocto build on the host Linux by executing the following commands.

$ sudo apt-get install gawk wget git-core

$ sudo apt-get install diffstat unzip texinfo gcc-multilib

$ sudo apt-get install build-essential chrpath socat libsdl1.2-dev

$ sudo apt-get install libsdl1.2-dev

$ sudo apt-get install xterm sed cvs

$ sudo apt-get install subversion coreutils texi2html

$ sudo apt-get install docbook-utils python-pysqlite2

$ sudo apt-get install help2man make gcc g++

$ sudo apt-get install desktop-file-utils

$ sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev mercurial

$ sudo apt-get install autoconf automake groff

$ sudo apt-get install curl lzop asciidoc

$ sudo apt-get install u-boot-tools

As long as the network environment is normal, this step of installing software dependencies generally should not encounter problems. If some dependencies fail to install, try changing the software source. The author defaults to using the official source of ubuntu16.04.

(2) The Yocto project is managed using the repo tool, so it is necessary to install and configure the repo tool on the Ubuntu host. The entire Yocto build takes place in the directory /opt/yocto_project. Note that the following operations need to be performed in a normal user environment. If permission issues arise, use the sudo command to resolve them. Execute the following commands to install the repo tool:

$ mkdir /opt/yocto_project/bin -p

$ chmod -R 777 /opt/yocto_project

$ PATH=/opt/yocto_project/bin:$PATH

$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > /opt/yocto_project/bin/repo

$ chmod a+x /opt/yocto_project/bin/repo

(3) After the repo tool is installed, it is necessary to set up the Git version control tool information by executing the following commands:

$ git config --global user.name "your_name"

$ git config --global user.email "your_email"

$ git config --list

(4) For the imx6ul platform, during the process of using Yocto to build the BSP package, many files will be downloaded from the official NXP Git repository, and many file information will be generated during compilation. Therefore, we place all downloaded and installed files from the entire build process in the /opt/yocto_project/fsl-release-bsp directory for unified management. Execute the following commands:

$ mkdir /opt/yocto_project/fsl-release-bsp

$ chmod 777 -R /opt/yocto_project/fsl-release-bsp

$ cd /opt/yocto_project/fsl-release-bsp

$ repo init -u git://git.freescale.com/imx/fsl-arm-yocto-bsp.git -b imx-4.1-krogoth

$ repo sync -f -j4

(5) Due to certain indescribable reasons in China, there may be network interruptions or inaccessible errors during the repo synchronization process, such as the following errors:

Building Embedded U-Boot, Kernel, and File System with Yocto

The solution is to first clone the repo separately:

$ git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo

Then copy the executable file from git-repo to the /opt/yocto_project/bin directory:

$ cp git-repo/repo /opt/yocto_project/bin -a

$ chmod a+x /opt/yocto_project/bin/repo

Next, create a .repo folder in the source code synchronization working directory fsl-release-bsp (if it already exists, no need to create), rename the git-repo folder to repo folder, and copy it to the .repo directory:

$ mv git-repo ./.repo/repo

Then re-execute the following command to initialize the repo repository:

$ repo init -u git://git.freescale.com/imx/fsl-arm-yocto-bsp.git -b imx-4.1-krogoth

After successful initialization, it will look like the following:

Building Embedded U-Boot, Kernel, and File System with Yocto

Start the repo synchronization again:

$ repo sync -f -j8

Repository synchronization takes some time. After synchronization is complete, it will look like the following:

Building Embedded U-Boot, Kernel, and File System with Yocto

(6) After the repo synchronization is successful, you can start the image building. In the fsl-release-bsp directory, use the following command format to configure the build parameters for the image:

DISTRO=<distro name> MACHINE=<machine name> source fsl-setup-release.sh -b <build dir>

DISTRO has the following options:

fsl-imx-x11

fsl-imx-wayland

fsl-imx-xwayland

fsl-imx-fb

Here, we choose the optionfsl-imx-x11. Note that NXP no longer supports DirectFB.

MACHINE has the following options:

imx6qpsabreauto

imx6qpsabresd

imx6ulevk

imx6ull14x14evk

imx6ull9x9evk

imx6dlsabreauto

imx6dlsabresd

imx6qsabreauto

imx6qsabresd

imx6slevk

imx6solosabreauto

imx6solosabresd

imx6sxsabresd

imx6sxsabreauto

imx7dsabresd

Here, we choose the optionimx6ulevk.

The complete command for configuring the image build parameters is as follows:

$ DISTRO=fsl-imx-x11 MACHINE=imx6ulevk source fsl-setup-release.sh -b ./fsl_build_x11

fsl-setup-release.sh is the build script. If the script is not executable, use the chmod command to add executable permissions.

-b <build dir> specifies the directory for the build.

After executing the above command to configure the parameters, you will be prompted to accept the EULA agreement. Press the space bar until the end of the agreement, then press “y” to confirm acceptance. Finally, after completion, it will look like the following:

Building Embedded U-Boot, Kernel, and File System with Yocto

(7) In the Yocto system, the bitbake tool is used for building and installing various systems or third-party libraries. bitbake is an automated build tool for software components. It can control how to build a system or solve dependency issues during the system build process, similar to the make command. However, unlike make, which relies on makefile, bitbake can collect and manage a large number of configuration description files (commonly known as recipes) that have no dependencies and automatically build them in the correct order based on these description files. Note: The bitbake tool can only be used in a normal user environment. In the configured Yocto environment, bitbake supports building the following images:

core-image-minimal

meta-toolchain

meta-toolchain-sdk

adt-installer

meta-ide-support

Here, we need to build a minimal embedded Linux system, so execute the following command to build it:

$ bitbake core-image-minimal

The process of building this minimal embedded Linux system is very lengthy, depending on your network speed and computer configuration. Since bitbake downloads and compiles at the same time, the build process is shown below:

Building Embedded U-Boot, Kernel, and File System with Yocto

Note: If a network interruption occurs during the build process or if the build terminal is closed, simply execute the following command in the fsl-release-bsp directory:

$ DISTRO=fsl-imx-x11 MACHINE=imx6ulevk source fsl-setup-release.sh -b ./fsl_build_x11

Reconfigure the build environment, then enter the fsl_build_x11 directory, and re-execute the bitbake command to continue the build.

After successfully building core-image-minimal with Yocto, it will look like the following:

Building Embedded U-Boot, Kernel, and File System with Yocto

(8) Due to various indescribable reasons, ordinary networks in China may encounter source code download errors and interruptions when accessing foreign source code servers. Generally, when such situations occur, you can first ignore the errors or warnings, and after the entire Yocto build is completed, re-execute bitbake. This factor of the network environment is not something every developer can control; it is largely a matter of luck. Developers with conditions can constantly seek high-quality network environments.

(9) After the minimal embedded Linux system is built, the build directory of the Yocto project already contains the source code for the kernel and U-Boot, as well as the root file system directory. The source code directories are shown below:

U-Boot source code directory:

/opt/yocto_project/fsl-release-bsp/fsl_build_x11/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2016.03-r0/git

Linux kernel source code directory:

/opt/yocto_project/fsl-release-bsp/fsl_build_x11/tmp/work-shared/imx6ulevk/kernel-source

Root file directory:

/opt/yocto_project/fsl-release-bsp/fsl_build_x11/tmp/deploy/images/imx6ulevk/core-image-minimal-imx6ulevk-20190621012322.rootfs.tar.bz2

For convenience in management, we store the U-Boot source code, Linux kernel source code, and rootfs root file directory in the /opt/imx6ul_bsp directory and rename the source code folders. After completion, it will look like the following:

Building Embedded U-Boot, Kernel, and File System with Yocto

(10) Using Yocto not only allows us to obtain source code but also successfully compiles various source code image files. These image files can be directly burned into the official development kit (imx6ul-evk) for operation. The image files are stored in the following directory:

/opt/yocto_project/fsl-release-bsp/fsl_build_x11/tmp/deploy/images/imx6ulevk

(11) Thus, the minimum system for imx6ul, U-Boot, kernel, and rootfs has been completed. The next step can be to carry out porting work based on the minimum system built with Yocto to adapt to our custom development board platform. In this chapter, we simply described how to use Yocto to build the minimum system for i.MX6UL, and the various images built for i.MX6UL are based on the NXP official development kit (imx6ul-evk). For user-customized development boards, further porting work is required to run U-Boot, kernel, and rootfs on the custom development board.

(12) Yocto is a powerful build tool. Its functions are not limited to obtaining BSP source code and simply compiling it. Developers can also use Yocto to add various third-party development libraries to their development boards without having to start from scratch (compiling source code from zero and resolving third-party dependencies) each time, greatly improving development efficiency. Developers can also add their defined development boards to the Yocto build project based on Yocto’s build rules, making it easier to release to third parties. However, Yocto is also a large build system with many basic build rules that developers need to familiarize themselves with to use flexibly. When encountering problems, it is advisable to use search engines to find answers. The best reference tutorial is the official Yocto Project documentation. Developers must continually learn and improve to use Yocto effectively and achieve maximum efficiency in development.

— END —

Long press to identify the QR code and follow Weilian Zhikong

Building Embedded U-Boot, Kernel, and File System with Yocto

Leave a Comment