Home  >  Article  >  System Tutorial  >  Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

WBOY
WBOYforward
2024-02-10 22:12:14762browse

If you are an embedded developer, you may encounter this question: How to create a suitable Linux system for your hardware platform? How to customize the functionality and appearance of a Linux system? How to ensure the security and stability of Linux system? These problems can be solved by using the Yocto project. The Yocto Project is an open source collaborative project that helps you create custom Linux systems regardless of your hardware architecture. The Yocto project provides a flexible set of tools and resources that allow you to build your own Linux distribution from scratch, or modify and optimize based on existing Linux distributions. This article will introduce you to how to use Yocto to create a minimal Linux distribution on Ubuntu, as well as the basic concepts and workflow of Yocto.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Basic conditions for development machine

Minimum 4-6 GB RAM

The latest version of Ubuntu system (this article uses 16.04 LTS)

The remaining disk space is at least 60-80 GB

Install the following packages before creating a Linux distribution

Download the latest Yocto (Poky is its minimum development environment) stable branch

apt-get update
apt-get install wget git-core unzip make gcc g++ build-

essential subversion sed autoconf automake texi2html texinfo coreutils diffstat python-

pysqlite2 docbook-utils libsdl1.2-dev libxml-parser-perl libgl1-mesa-dev libglu1-mesa-

dev xsltproc desktop-file-utils chrpath groff libtool xterm gawk fop
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

As shown below, the software package to be installed in the development environment is nearly 1GB in size.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

In this tutorial, the morty stable branch of poky is cloned on the system.

git clone -b morty git://git.yoctoproject.org/poky.git
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Enter the poky directory, and then run the following command to set (set/export) some environment variables for the Yocto development environment.

source oe-init-build-env

As shown below, after running the open embedded (oe) build environment script, the path in the terminal will automatically switch to the build directory for subsequent configuration and construction of the release version.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

The screenshot above shows the file local.conf created in the conf directory. This is the configuration file used by Yocto to set the target machine details and target architecture of the SDK.

As shown below, the target machine set here is qemux86-64.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

As shown in the screenshot below, uncomment the following parameters in local.conf.

DL_DIR ?= "${TOPDIR}/downloads"
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu
TMPDIR ?= "${TOPDIR}/tmp"
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu
PACKAGE_CLASSES ?= "package_rpm"
SDKMACHINE ?= "i686"
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

As shown below, set an empty password and some subsequent parameters in local.conf for Yocto-based Linux. Otherwise, users will not be able to log in to the new release.

EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

We are not planning to use any graphical tools to create Linux OS, such as toaster (hob is no longer supported).

Yocto compilation and build process

Now run the following bitbake tool command to start downloading and compiling the software package for the selected target machine.

bitbake core-image-minimal
Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

It is very important to run the above command under a normal Linux user and not using the root user. As shown in the screenshot below, when you run the bitbake command under the root user, the error shown below will occur.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Run the script that exports environment variables (oe-init-build-env) again, and re-execute the same command to start the download and compilation process.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

As shown below, the first step in building a script component is to parse the configuration (recipe).

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

The screenshot below shows the parsing process of the build script. It also shows the details of the build system used to build your new yocto-based distribution.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

After downloading the SDK and necessary libraries, the next step is to download and compile the software package. The screenshot below shows the tasks performed to build a new distribution. This step will take 2-3 hours as the required packages must first be downloaded and then compiled for the new Linux distribution.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

The screenshot below shows the completion of the task list.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

The new image compiled for the target machine type qemux86-64 is located in build/tmp/deploy/images/qemux86-64:

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

As shown below, the above command will generate an error if run on Putty.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Run the above command again on the Ubuntu platform via rdp.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Open a new screen for qemu running the new Yocto-based Linux distribution.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

The following shows the login interface of the new release, and also displays the version number of the yocto project used. The default username is root and the password is blank.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

Finally use the root username and empty password to log in to the new release. As shown in the screenshot below, basic commands (data, ifconfig, and uname) are run on this minimal version of Linux.

Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu

The goal of this article is to understand the process of creating a new Linux distribution using Yocto.

Through this article, you have learned how to use Yocto to create a minimal Linux distribution on Ubuntu, as well as the basic concepts and workflow of Yocto. You can use Yocto to customize a suitable Linux system for your embedded devices or other scenarios to meet your needs and preferences. Of course, this is only part of the many features and options provided by the Yocto project. If you want to learn more about the Yocto project and embedded Linux development, you still need to continue to explore and practice. I hope this article can be helpful to your study and work. You are also welcome to share other practical Yocto skills you use or discover.

The above is the detailed content of Yocto Getting Started Tutorial: Build Your Customized Linux System on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete