Yocto - 使用Yocto开发嵌入式Linux系统_04 使用Toaster来创建一个image
Using Toaster to Bake an Image
既然我们已经知道了如何在 Poky 中使用 BitBake 构建图像,那么接下来我们就来学习如何使用 Toaster 构建图像。我们将重点介绍 Toaster 最直接的使用方法,并介绍它的其他功能,让你了解它的能力。
Now that we know how to build an image using BitBake within Poky, we will learn how to do the same using Toaster. We are going to focus on the most straightforward usage of Toaster and also cover what else it can do so that you know about its capabilities.
1, What is Toaster?
Toaster 是一个用于配置和运行构建的网络界面。它与 BitBake 和 Poky 构建系统通信,以管理和收集有关构建、软件包和镜像的信息。
Toaster is a web interface to configure and run builds. It communicates with the BitBake and Poky build system to manage and gather information about the builds, packages, and images.
使用 Toaster 有两种方法:
* 本地使用: 我们可以将 Toaster 作为本地实例运行,适合单用户开发,提供 BitBake 命令行的图形界面和一些构建信息。
* 托管: 适合多用户使用。Toaster 服务器会构建和存储用户的工件。使用托管实例时,其组件可分布在多台机器上。
There are two ways to use Toaster:
* Locally: We can run Toaster as a local instance, suitable for single-user development, providing a graphical interface to the BitBake command lines and some build information.
* Hosted: This is suitable for multiple users. The Toaster servers build and store the users’ artifacts. Its components can be spread across several machines when using a hosted instance.
在本章中,我们将把 Toaster 作为本地实例使用。不过,如果你想将其用作托管实例,请访问以下网站获取说明 - Toaster Manual (Toaster User Manual — The Yocto Project ® 4.0.4 documentation)。
In this chapter, we will use Toaster as a local instance. However, if you want to use it as a hosted instance, please visit the following website for instructions – Toaster Manual ( Toaster User Manual — The Yocto Project ® 4.0.4 documentation ).
注意事项
请记住,每项托管服务都需要注意其安全性。在使用托管实例之前,请考虑这一点。
Note
Bear in mind that every hosted service requires attention to its security. Think about this before using a hosted instance.
2,Installing Toaster
Toaster 使用 Python Django 框架。最简单的安装方法是使用 Python 的 pip 工具。在第 2 章 “构建基于 Poky 的系统”中配置主机时,我们已经安装了该工具。现在,我们可以运行以下命令,在 Poky 源代码目录下安装 Toaster 的其他需求:
Toaster uses the Python Django framework. The easiest way to install it is by using Python’s pip utility. We already installed this when configuring our host machine in Chapter 2, Baking Our Poky-Based System. We can now install the rest of Toaster’s requirements inside the Poky source directory by running the following command:
$ pip3 install --user -r bitbake/toaster-requirements.txt
WARNING: The script sqlformat is installed in '/home/dev/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
3, Starting Toaster
安装好 Toaster 所需配置后,我们就可以启动它的服务器了。为此,我们应进入 Poky 目录并运行以下命令:
Once we have installed Toaster’s requirements, we are ready to start its server. To do this, we should go to Poky’s directory and run the following commands:
$ source oe-init-build-env
$ source toaster start
这些命令需要一些时间才能完成。一切就绪后,网络服务器开始运行。结果如下图所示。
The commands take some time to finish. When everything is set up, the web server is started. The result is shown in the following figure.
[Figure 3.1 – The result of the source toaster startup]
要访问 Toaster 网络界面,请打开你喜欢的浏览器并输入以下内容:
To access the Toaster web interface, open your favorite browser and enter the following:
http://127.0.0.1:8000
注意事项
Toaster 默认从 8000 端口启动。网络端口参数允许你使用不同的端口,例如:$ source toaster start webport=8400。
Note
By default, Toaster starts on port 8000. The webport parameter lets you use a different port – for example, $ source toaster start webport=8400.
接下来,我们可以看到 Toaster 的起始页面:
Next, we can see the starting page of Toaster:
[Figure 3.2 – The Toaster welcome page]
4, Building an image for QEMU
按照第 2 章 “构建基于 Poky 的系统 ”中的相同步骤,我们将构建 QEMU x86-64 仿真的映像。
Following the same steps used in Chapter 2, Baking Our Poky-Based System, we will build an image of the QEMU x86-64 emulation.
由于我们目前没有项目(配置和构建的集合),因此需要启动一个项目。创建项目名称并选择目标版本,如下图所示:
Since we currently don’t have a project, a collection of configurations and builds, we need to start one. Create a project name and choose the target release, as shown in the following screenshot:
[Figure 3.3 – Creating a new project with Toaster]
创建我的第一个项目后,我们可以看到项目主界面,如下图所示:
After creating my-first-project, we can see the main project screen, as shown in the following screenshot:
[Figure 3.4 – The first page of the project]
在 “配置”选项卡上,转到 “机器”,将目标机器更改为 qemux86-64:
While on the Configuration tab, go to Machine and change the target machine to qemux86-64:
[Figure 3.5 – How to choose the target machine]
然后,单击 “图像配方”选项卡,选择要构建的图像。在本例中,正如第 2 章 “构建基于 Poky 的系统 ”中所使用的,我们可以构建 core-image-full-cmdline:
After that, click the Image recipes tab to choose the image you want to build. In this example, as used in Chapter 2, Baking Our Poky-Based System, we can build core-image-full-cmdline:
[Figure 3.6 – How to find an image using Search]
下面的截图显示了构建过程:
The following screenshot shows the build process:
[Figure 3.7 – Toaster during the image build]
构建过程需要一些时间,但之后我们就可以看到构建的图像以及一些统计数据,如下图所示:
The build process takes some time, but after that, we can see the built image along with some statistics, as shown in the following screenshot:
[Figure 3.8 – The image build artifact report]
我们还可以验证生成的文件集,如下图所示:
We can also verify the generated set of files, as shown in the following screenshot:
[Figure 3.9 – The core-image-full-cmdline directory structure as shown in Toaster]
Toaster 是一款功能强大的工具。你可以在本地开发机器或共享服务器上使用它,以图形方式显示构建过程。你可以返回启动 Toaster 的终端,运行 runqemu qemux86-64 core-image-full-cmdline。你将看到如下截图所示:
Toaster is a powerful tool. You can use it on a local development machine or a shared server to get a graphic representation of the build. You can return to the terminal where you started Toaster to run runqemu qemux86-64 core-image-full-cmdline. You will see what is shown in the following screenshot:
[Figure 3.10 – The QEMU screen during the Linux kernel boot]
完成 Linux 启动后,会出现登录提示,如图 3.11 所示。
After finishing the Linux booting, you will see a login prompt, as shown in Figure 3.11.
[Figure 3.11 – The QEMU screen during user login ]
我们可以使用空密码登录 root 账户。
We can log in to the root account using an empty password.