[ 物联网篇 ] 02 - Yocto Project (YP)快速入门

NXP i.MX 8M Mini 的源码构建系统使用的是Yocto,如果不熟悉Yocto,完全看不懂 i.MX 8M Mini 的相关代码。

废话不多说,直接到Yocto 官网看文档,写Demo。参考官网的文档/部分博客。

  • Yocto Project Quick Start

  • Yocto Project Quick Build

  • Yocto Project Overview and Concepts Manual

  • Yocto Project Reference Manual

  • Yocto Project Development Tasks Manual

  • Yocto基本概念及介绍

  • OpenEmbedded 入门 (一):OpenEmbedded 简介

  • 4 种用于构建嵌入式 Linux 系统的工具

  • Yocto实用技巧

  • Yocto Project开发系列 入门系列,包括调试技巧

Yocto的学习过程比较陡峭。大概看完一遍官网文档,感觉还是云里雾里的,只能边实践边学习。

1. Yocto 是什么 ?

Yocto项目是一个开源协作项目,其重点是嵌入式Linux系统的开发人员。 除此之外,Yocto Project使用基于OpenEmbedded(OE)项目的构建主机,该项目使用BitBake工具构建完整的Linux映像。 BitBake和OE组件组合在一起形成一个参考构建主机,历史上称为Poky。

YoctoBuildroot有异曲同工之妙。两者同为构建嵌入式的编译系统。不同点挺多的,如果之前了解过Buildroot,学习Yocto会事半功倍。两者的不同点这里不做展开说明。

2. Yocto 中的基本概念

熟悉Yocto项目中的一些基本概念 :

[ 物联网篇 ] 02 - Yocto Project (YP)快速入门_第1张图片

通过生活中实际的例子来体现

  • Yocto: 开源项目名称,构建自定义的Linux 系统
  • Poky: Yocto项目中提供一个构建Linux的完成示例。
  • BitBake: OpenEmbedded构建系统的核心工具,负责解析元数据,从中生成任务列表,然后执行这些任务。
  • Layers: 包含相关元数据(即指令集)的存储库,它们告诉OpenEmbedded构建系统如何构建目标。方便项目中各个模块的隔离,有助于项目的维护。例如(meta-skeleton , meta-yocto-bsp) 默认以meta-xxx开头
  • Recipes: 具有.bb后缀的文件,通常,xxx.bb文件包含了软件的信息。
  • Metadata: 元数据是Yocto项目的核心,基本元素的描述与来源。

Yocto中相关的概念比较多,有的时候不太容易理解。这里以生活中一个示例通俗易懂的连贯起来。
Yocto 代表饭店名,知道是做什么的。Pocky代表厨房(如何做出一道美味的菜品), Layers代表菜系(湘菜,川菜,北方菜) Recipes代表具体的菜谱(描述一道菜具体是怎么做的), MetaData代表做菜的原材料。 各种材料准备好了,BitBake代表厨师(看如何做出一道菜的)。

3.Yocto 实战

为了适应不同的环境,这里在Docker 构建Yocto 。

使用Docker容器的CROPS,您可以创建与操作系统无关的Yocto Project开发环境。参考 Yocto Project Development Tasks Manual -> 2.2.2. Setting Up to Use CROss PlatformS (CROPS)。

  • 运行 poky-container
//创建工作目录
mkdir -p /home/myuser/mystuff
// 运行容器
docker run --rm -it -v /home/myuser/mystuff:/workdir crops/poky --workdir=/workdir
  • 容器正常其中之后,开始下载/编译源码Yocto Project Quick Build
// 下载源码
> git clone git://git.yoctoproject.org/poky

//切换到2.6.1版本
> cd poky 
> git fetch --tags
> git tag
> git checkout tags/yocto-2.6.1 -b my-yocto-2.6.1
  • 编译固件
// 设置运行环境
source oe-init-build-env

//编译最小系统
bitbake  core-image-minimal 


  • 余留问题

ubuntu 18.4 系统bitbake core-image-minimal执行之后,编译报错,并没有耗费时间去解决,直接使用docker 容器搭建。

最后通过删除 build / tmp 目录,编译通过。


Loading cache: 100% |############################################################################################################################################| Time: 0:00:00
Loaded 1263 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.40.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "i586-poky-linux"
MACHINE              = "qemux86"
DISTRO               = "poky"
DISTRO_VERSION       = "2.6.1"
TUNE_FEATURES        = "m32 i586"
TARGET_FPU           = ""
meta                 
meta-poky            
meta-yocto-bsp       = "my-yocto-2.6.1:1cab405d88149fd63322a867c6adb4a80ba68db3"

Initialising tasks: 100% |#######################################################################################################################################| Time: 0:00:01
Sstate summary: Wanted 653 Found 0 Missed 653 Current 85 (0% match, 11% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: gcc-cross-i586-8.2.0-r0 do_compile: oe_runmake failed
ERROR: gcc-cross-i586-8.2.0-r0 do_compile: Function failed: do_compile (log file is located at /home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/gcc-cross-i586/8.2.0-r0/temp/log.do_compile.17033)
ERROR: Logfile of failure stored in: /home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/gcc-cross-i586/8.2.0-r0/temp/log.do_compile.17033

|  #define FIRST_PSEUDO_REGISTER FIRST_PSEUDO_REG
|                                ^
| ../../../../../../../work-shared/gcc-8.2.0-r0/gcc-8.2.0/gcc/rtl.h:4302:38: note: in expansion of macro ‘FIRST_PSEUDO_REGISTER’
|  extern tree GTY(()) global_regs_decl[FIRST_PSEUDO_REGISTER];
|                                       ^~~~~~~~~~~~~~~~~~~~~
| Makefile:2671: recipe for target 'build/genrecog.o' failed
| make[1]: *** [build/genrecog.o] Error 1
| make[1]: Leaving directory '/home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/gcc-cross-i586/8.2.0-r0/gcc-8.2.0/build.x86_64-linux.i586-poky-linux/gcc'
| ERROR: oe_runmake failed
| Makefile:4279: recipe for target 'all-gcc' failed
| make: *** [all-gcc] Error 2
| WARNING: exit code 1 from a shell command.
| ERROR: Function failed: do_compile (log file is located at /home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/gcc-cross-i586/8.2.0-r0/temp/log.do_compile.17033)
ERROR: Task (/home/mike/Work/nxp-imx8/test-yocto/poky/meta/recipes-devtools/gcc/gcc-cross_8.2.bb:do_compile) failed with exit code '1'
ERROR: qemu-native-3.0.0-r0 do_compile: oe_runmake failed
ERROR: qemu-native-3.0.0-r0 do_compile: Function failed: do_compile (log file is located at /home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/qemu-native/3.0.0-r0/temp/log.do_compile.17035)
ERROR: Logfile of failure stored in: /home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/qemu-native/3.0.0-r0/temp/log.do_compile.17035
Log data follows:
| DEBUG: Executing shell function do_compile
|   LINK    aarch64-softmmu/qemu-system-aarch64
|   LINK    arm-softmmu/qemu-system-arm
| ../slirp/tcp_subr.o: file not recognized: File truncated
| collect2: error: ld returned 1 exit status
| ../slirp/tcp_subr.o: file not recognized: File truncated
| collect2: error: ld returned 1 exit status
| Makefile:199: recipe for target 'qemu-system-aarch64' failed
| make[1]: *** [qemu-system-aarch64] Error 1
| Makefile:199: recipe for target 'qemu-system-arm' failed
| make[1]: *** [qemu-system-arm] Error 1
| Makefile:481: recipe for target 'subdir-arm-softmmu' failed
| make: *** [subdir-arm-softmmu] Error 2
| make: *** Waiting for unfinished jobs....
| Makefile:481: recipe for target 'subdir-aarch64-softmmu' failed
| make: *** [subdir-aarch64-softmmu] Error 2

...................................

|   CC      mips-softmmu/trace/generated-helpers.o
|   LINK    mips-softmmu/qemu-system-mips
| ../slirp/tcp_subr.o: file not recognized: File truncated
| collect2: error: ld returned 1 exit status
| Makefile:199: recipe for target 'qemu-system-mips' failed
| make[1]: *** [qemu-system-mips] Error 1
| Makefile:481: recipe for target 'subdir-mips-softmmu' failed
| make: *** [subdir-mips-softmmu] Error 2
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.
| ERROR: Function failed: do_compile (log file is located at /home/mike/Work/nxp-imx8/test-yocto/poky/build/tmp/work/x86_64-linux/qemu-native/3.0.0-r0/temp/log.do_compile.17035)
ERROR: Task (virtual:native:/home/mike/Work/nxp-imx8/test-yocto/poky/meta/recipes-devtools/qemu/qemu_3.0.0.bb:do_compile) failed with exit code '1'
NOTE: Tasks Summary: Attempted 765 tasks of which 760 didn't need to be rerun and 2 failed.

Summary: 2 tasks failed:
  /home/mike/Work/nxp-imx8/test-yocto/poky/meta/recipes-devtools/gcc/gcc-cross_8.2.bb:do_compile
  virtual:native:/home/mike/Work/nxp-imx8/test-yocto/poky/meta/recipes-devtools/qemu/qemu_3.0.0.bb:do_compile
Summary: There were 4 ERROR messages shown, returning a non-zero exit code.

  • 编译成功,成功运行 runqemu qemux86
    [ 物联网篇 ] 02 - Yocto Project (YP)快速入门_第2张图片

你可能感兴趣的:([,系统开发,])