[yocto]基于poky项目创建自己的层并且在层中增加自己的配方文件

基于poky项目创建自己的层并且在层中增加自己的配方文件

1.本地获取poky

git clone git://git.yoctoproject.org/poky

建议使用kirkstone分支

git checkout -b remotes/origin/kirkstone

2.新增层

初始化poky环境

source oe-init-build-env

创建新层,meta-test

~/test/poky/build$ bitbake-layers create-layer ../meta-test

把层配置到poky环境中

~/test/poky/build$ bitbake-layers add-layer ../meta-test

检查层是否配置成功

~/test/poky/build$ bitbake-layers show-layers
NOTE: Starting bitbake server...
layer                 path                                                 priority
===================================================================================
core                  /xxx/xxx/poky/meta                                   5
yocto                 /xxx/xxx/poky/meta-poky                              5
yoctobsp              /xxx/xxx/poky/meta-yocto-bsp                         5
meta-test             /xxx/xxx/poky/meta-test                              6

检查层中文件

~/test/poky/meta-test$ tree
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-example
    └── example
        └── example_0.1.bb

3 directories, 4 files

在层中新增文件夹,并且为了便于后序,模仿example在该文件夹下新增hello包

~/test/poky/meta-test$ tree
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
├── recipes-example
│   └── example
│       └── example_0.1.bb
└── recipes-test
    └── hello

5 directories, 4 files

3.在层中添加测试配方文件

3.1 配方文件目标源为本地压缩包

  • 1.创建简单工程
    • hello.h
      #pragma once
      
      #include<stdio.h>
      
      void hello(void);
      
    • hello.c
      #include"hello.h"
      
      void hello(void)
      {
          printf("hello world!!");
      }
      
    • main.c
      #include "hello.h"
      
      int main()
      {
          hello();
          return 0;
      }
      
  • 2.将这三个文件打包
    tar cvfz hello-1.0.tgz .
    
    将包放在recipes-test/hello/hello-1.0中
  • 3.新建配方文件hello-1.0.bb,并将配方文件放在hello工程文件夹中
    SUMMARY = "Hello World"
    DESCRIPTION = "A simple test to learn how to crate a recipe"
    
    SECTION = "examples"
    PRIORITY = "optional"
    
    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
    
    SRC_URI = "file://hello-1.0.tgz"
    
    S = "${WORKDIR}"
    
    do_compile(){
        ${CC} -c hello.c
        ${CC} -c main.c
        ${CC} -o hello hello.o main.o
    }
    
    do_install() {
        install -d ${D}${bindir}
        install -m 0755 hello ${D}${bindir}
    }
    
    recipes-test的文件结构
    recipes-test
        └── hello
            ├── hello-1.0
            │   └── hello-1.0.tgz
            └── hello_1.0.bb
    

3.2 配方文件目标源为在线源

源:https://ftp.gnu.org/gnu/hello/

配方文件:hello_2.12.bb

SUMMARY = "The Test hello"
DESCRIPTION = "T"
HOMEPAGE = "https://ftp.gnu.org/gnu/hello/"

LICENSE = ""
LIC_FILES_CHKSUM = ""

#建议不使用固定版本号便于移植
SRC_URI = "${HOMEPAGE}hello-${PV}.tar.gz"
#SRC_URI = "https://ftp.gnu.org/gnu/hello/hello-{PV}.tar.gz"
#SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz"
#这里三种下载方式都可以使用

#打补丁
#SRC_URI = "https://ftp.gnu.org/gnu/hello/hello-{PV}.tar.gz \
#           file://patch-1.patch;striplevel=3 \  #如果补丁需要多级目录被除去
#           file://patch-2.diff;patchdir=src/common \ #补丁需要被应用进特定的、不是在补丁文件本身内提供的子目录中,那么你增加patchdir选项到SRC_URI
#           "
#把补丁和任何其他本地获取的文件放在菜谱旁边的子目录中,子目录被命名成和菜谱的基名称BPN相同,或者被命名成基名称加版本号BP,或者被命名成files


SRC_URI[sha256sum] = "cf04af86dc085268c5f4470fbae49b18afbc221b78096aab842d934a76bad0ab"
#既可以使用sha256也可以使用MD5进行校验

S = "${WORKDIR}/${BP}"

do_install() {
    install -d {B}/bin/hello ${D}/${bindir}
    install -d {B}/bin/hello.lib ${D}/${libdir}
}

:配方文件中源所指定的包名字为hello-${PV}.tar.gz${PV}为配方文件名的版本号2.12。一定要确保源上存在hello-2.12.tar.gz的包,不然会fetch失败

4.调试

4.1 整体编译

bitbake hello

:因为配方文件使用了gcc编译,而gcc是默认继承autotool类,所以在第一次整体编译时bitbake会从网上下载工具所依赖的各种库,速度较慢。

4.2 分task进行编译

在自己编写配方文件时分task进行执行编译在编译过程中debug

  • fetch
bitbake -c fetch hello

注:fetch task和配方文件中的SRC_URI息息相关,并且可以有多种来源,在使用时一定要确保源地址正确并且和任务文件夹名正确(配方的file变量,本例中为hello/hello-1.0)

常见错误

fetch路径有误

WARNING: hello-1.o-r0 do_fetch: Failed to fetch URL file://hello-1.0.tgz, attempting MIRRORS if available
ERROR: hello-1.o-r0 do_fetch: Fetcher failure: Unable to find file file://hello-1.0.tgz anywhere. The paths that were searched were:
检查包存放路径是否正确
确保路径名字是否正确
确保配方文件名是否和存放压缩包的上层名字对应

fetch下载源错误

ERROR: hello-2.12-r0 do_fetch: Bitbake Fetcher Error: FetchError('Unable to fetch URL from any source.', 'https://ftp.gnu.org/gnu/hello/hello-{PV}.tar.gz')
hello-2.12-r0 do_fetch: Failed to fetch URL https://ftp.gnu.org/gnu/hello/hello-{PV}.tar.gz, attempting MIRRORS if available
ERROR: hello-2.12-r0 do_fetch: Fetcher failure: Fetch command export PSEUDO_DISABLED=1; export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"; export SSH_AGENT_PID="1683"; export SSH_AUTH_SOCK="/run/user/1000/keyring/ssh"; export PATH="/xxx/poky/poky/build/tmp/sysroots-uninative/x86_64-linux/usr/bin:/xxx/poky/scripts:/xxx/poky/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux:/xxx/poky/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/recipe-sysroot/usr/bin/crossscripts:/xxx/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/recipe-sysroot-native/usr/sbin:/xxx/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/recipe-sysroot-native/usr/bin:/xxx/poky/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/recipe-sysroot-native/sbin:/xxx/poky/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/recipe-sysroot-native/bin:/xxx/poky/poky/bitbake/bin:/xxx/poky//poky/build/tmp/hosttools"; export HOME="xxx"; /usr/bin/env wget -t 2 -T 30 --passive-ftp -P /xxx/poky/poky/build/downloads 'https://ftp.gnu.org/gnu/hello/hello-{PV}.tar.gz' --progress=dot -v failed with exit code 8, no output
ERROR: hello-2.12-r0 do_fetch: Bitbake Fetcher Error: FetchError('Unable to fetch URL from any source.', 'https://ftp.gnu.org/gnu/hello/hello-{PV}.tar.gz')
ERROR: Logfile of failure stored in: /xxx/poky/poky/build/tmp/work/core2-64-poky-linux/hello/2.12-r0/temp/log.do_fetch.17456
ERROR: Task (/xxx/poky/poky/meta-test/recipes-test/hello/hello_2.12.bb:do_fetch) failed with exit code '1'
配方文件所指定的源的包名为hello-{PV}.tar.gz,那么在下载时就需要确保提供的源镜像网站是正确的并且存在该包hello-{PV}.tar.gz,也就是需要确保配方文件的版本号和源镜像网站的包进行对应
确保包名无误,确保源网站包存在

源下载校验错误

ERROR: hello-2.12-r0 do_fetch: Checksum failure fetching https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz
ERROR: hello-2.12-r0 do_fetch: Bitbake Fetcher Error: ChecksumError('Checksum mismatch!\nFile: \'/xxx/poky/build/downloads/hello-2.12.tar.gz\' has md5 checksum \'048d95d41f9c0bd3424bf0917f53782d\' when \'67607d2616a0faaf5bc94c59dca7c3cb\' was expected\nIf this change is expected (e.g. you have upgraded to a new version without updating the checksums) then you can use these lines within the recipe:\nSRC_URI[sha256sum] = "cf04af86dc085268c5f4470fbae49b18afbc221b78096aab842d934a76bad0ab"\nOtherwise you should retry the download and/or check with upstream to determine if the file has become corrupted or otherwise unexpectedly modified.', 'https://ftp.gnu.org/gnu/hello/hello-2.12.tar.gz')
SRC_URI[sha256sum]检验值和源包的sha256值不对应
用log提示的正确值替换错误的

compile使用gcc错误

ERROR: hello-1.0-r0 do_compile: ExecutionError('/xxx/poky/build/tmp/work/core2-64-poky-linux/hello/1.0-r0/temp/run.do_compile.830233', 1, None, None)
ERROR: Logfile of failure stored in: /xxx/poky/build/tmp/work/core2-64-poky-linux/hello/1.0-r0/temp/log.do_compile.830233
Log data follows:
| DEBUG: Executing shell function do_compile
| x86_64-poky-linux-gcc: warning: hello: linker input file unused because linking not done
| x86_64-poky-linux-gcc: error: hello: linker input file not found: No such file or directory
| WARNING: exit code 1 from a shell command.
错误 代码编译错误
检查gcc参数是否使用正确
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值