新建一个layer层,开发调试应用程序(add a new meta-layer and build a application)

这里主要是做了个测试,如何添加一个layer层,会发生哪些变化,然后编译一个简单的c application,以及整体编译后放到什么目录里去。

可以先在源码 poky 中进行验证  branch dunfell

生成最小系统

source oe-init-build-env      
默认会生成一个build文件,在该文件中生成所有的编译文件  也即poky中提到的 meson 系统(源码和编译分开来,如果要重新编一个不同配置的文件, 可以重新输入这样的指令  source oe-init-build-env build-test1)
 

poky/build$ tree -L 1
.
├── bitbake-cookerdaemon.log
├── cache
├── conf
├── downloads
├── sstate-cache
├── tmp
└── workspace

6 directories, 1 file

bitbake  core-image-minimal 编译完整的最小系统

Create a new layer, first create a empty layer


cd  .. 退出到build上一层
bitbake-layer create-layer meta-myhello

poky/meta-myhello$ tree -L 2
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-example    这是个例子,可以在里面添加修改
    └── example

生成了以后,再进入到build层,把新生成的meta-myhello添加到当前的conf中去,bitbake-layers add-layer ../meta-myhello
然后在这个目录下的conf/bblayers.conf 文件的末尾就多了刚才的 meta-myhello

poky/build$ cat conf/bblayers.conf
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /pokey_codes/poky/meta \
  /pokey_codes/poky/meta-poky \
  /poky/meta-yocto-bsp \
  /poky/build/workspace \
  /poky/meta-myhello \
  "

单独编译调试新建的layer meta-myhello
新建c文件files/myhello.c,然后修改bb文件example_0.1.bb

poky/meta-myhello$ tree -L 4
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-example
    └── example
        ├── example_0.1.bb
        └── files
            └── myhello.c

4 directories, 5 files

poky/meta-myhello$ cat recipes-example/example/example_0.1.bb
SUMMARY = "bitbake-layers recipe"
LICENSE = "MIT"

python do_display_banner() {
    bb.plain("***********************************************");
    bb.plain("*                                             *");
    bb.plain("*  Example recipe created by bitbake-layers   *");
    bb.plain("*                                             *");
    bb.plain("***********************************************");
}

DESCRIPTION = "Simple helloworld application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"     //这个文件需要添加,似乎每个branch下的MD5都可以用这个,COMMON_LICENSE好像是不变的

SRC_URI = "file://myhello.c"        //这个是固定的,但是会寻找相关目录下的myhello.c,之前是放在example/files/myhello.c, 修改bbfile导致编译报错,后来又改成exmaple/file/myhello.c,导致bitbake example的时候找不到myhello.c,重新把file改为files后就可以编译成功。

S = "${WORKDIR}"

do_compile() {
        ${CC} myhello.c ${LDFLAGS} -o helloworld
}

do_install() {
        install -d ${D}${bindir}
        install -m 0755 helloworld ${D}${bindir}
}
poky/build$ bitbake example
Loading cache: 100% |#################################################################################################################| Time: 0:00:00
Loaded 1330 entries from dependency cache.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION           = "1.46.0"
BUILD_SYS            = "x86_64-linux"
NATIVELSBSTRING      = "universal"
TARGET_SYS           = "x86_64-poky-linux"
MACHINE              = "qemux86-64"
DISTRO               = "poky"
DISTRO_VERSION       = "3.1.15"
TUNE_FEATURES        = "m64 core2"
TARGET_FPU           = ""
meta
meta-poky
meta-yocto-bsp
workspace
meta-myhello         = "dunfell:8183149d3e06375e0453e52a85aabb1f8b27f701"

Initialising tasks: 100% |############################################################################################################| Time: 0:00:00
Sstate summary: Wanted 7 Found 0 Missed 7 Current 128 (0% match, 94% complete)
NOTE: Executing Tasks
WARNING: example-0.1-r0 do_fetch: Failed to fetch URL file://myhello.c, attempting MIRRORS if available
ERROR: example-0.1-r0 do_fetch: Fetcher failure: Unable to find file file://myhello.c anywhere. The paths that were searched were:
    poky/meta-myhello/recipes-example/example/example-0.1/poky
    poky/meta-myhello/recipes-example/example/example/poky
    poky/meta-myhello/recipes-example/example/files/poky
    meta-myhello/recipes-example/example/example-0.1/qemux86-64
    poky/meta-myhello/recipes-example/example/example/qemux86-64

ERROR: example-0.1-r0 do_fetch: Bitbake Fetcher Error: FetchError('Unable to fetch URL from any source.', 'file://myhello.c')
ERROR: Logfile of failure stored in: poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/log.do_fetch.12203
ERROR: Task (poky/meta-myhello/recipes-example/example/example_0.1.bb:do_fetch) failed with exit code '1'
NOTE: Tasks Summary: Attempted 529 tasks of which 528 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  poky/meta-myhello/recipes-example/example/example_0.1.bb:do_fetch
Summary: There was 1 WARNING message shown.
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.
poky/build$

编译生成的文件存放在这个目录,可以用于放到板子里去调试:
poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0$ ls
configure.sstate          example.spec     myhello.c       pkgdata              recipe-sysroot                           sysroot-destdir
debugsources.list         helloworld       package         pkgdata-pdata-input  recipe-sysroot-native                    temp
deploy-rpms               image            packages-split  pkgdata-sysroot      source-date-epoch
deploy-source-date-epoch  license-destdir  patches         pseudo               sstate-install-deploy_source_date_epoch

poky/build/tmp/work/core2-64-poky-linux$ find ./ -name "*helloworld*"
./gstreamer1.0/1.16.3-r0/gstreamer-1.16.3/tests/examples/helloworld
./gstreamer1.0/1.16.3-r0/gstreamer-1.16.3/tests/examples/helloworld/helloworld.c
./findutils/4.7.0-r0/findutils-4.7.0/xargs/testsuite/inputs/helloworld.xi
./example/0.1-r0/packages-split/example/usr/bin/helloworld
./example/0.1-r0/packages-split/example-dbg/usr/bin/.debug/helloworld
./example/0.1-r0/helloworld
./example/0.1-r0/image/usr/bin/helloworld
./example/0.1-r0/package/usr/bin/.debug/helloworld
./example/0.1-r0/package/usr/bin/helloworld

如果在build/conf/local.conf中添加command, 则在image_install中会把helloworld这个application也打包进系统里,IMAGE_INSTALL = "example"

因为好多地方也都使用了 recipises-example,在新建的meta-myhello层中,其实可以修改这个recipise-example,放到一个新的目录下进行develop, command : bitbake myhello

poky/meta-myhello$ tree -L 4
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-myhello
    └── myhello       //一定要新建这个文件 myhello, 然后把c文件和bb放在这个文件下,否则bitbake myhello会找不到myhello_0.1.bb,然后无法执行下去
        ├── files
        │   └── myhello.c
        └── myhello_0.1.bb


后续多个文件的编译,或者makefile编译或者meson编译,就只要修改files/ 以及 bb文件了。

生成的bin文件在这个目录下可以找到

poky/build/tmp/work/core2-64-poky-linux/myhello/0.1-r0$ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值