1 配方(recipe)文件创建在哪里?
为了最快让未接触过yocto的同学完成helloworld程序添加,这里选择把配方文件加在已有的layers中,并确保该layers会加入编译。
1.1 确认编译机型(machine)
这里以某个bmc的yocto工程为例(任何一个yocto工程都可以,方法都是通用的),在yocto工程目录顶层输入 . setup,注意.号后面有空格符。
~/work/byobmc$ ls
README.md build doc meta-aspeed meta-phosphor meta-skeleton poky setup
bitbake build.sh i-build-bmc.sh meta-byosoft meta-poky oe-init-build-env replace_build.sh tools
bmcbuild build_cci meta meta-openembedded meta-security openbmc-env scripts
~/work/byobmc$ . setup
Target machine must be specified. Use one of:
1u-x91 2u-x201 4u-x201 atx-i1331
. setup命令会列出yocto工程所有meta-*下支持的machine,也就是说每一个machine都可以在meta-*下找到对应的目录。
后续我们就以4u-x201机型为例添加helloworld程序,其对应目录为meta-byosoft/meta-4u-x201。
1.2 确认生效的layers
进入meta-byosoft/meta-4u-x201目录下,输入cat conf/bblayers.conf.sample命令,查看生效的layers,结果如下。
~/work/byobmc/meta-byosoft/meta-4u-x201$ cat conf/bblayers.conf.sample
LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
changes incompatibly
LCONF_VERSION = "8"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= "
##OEROOT##/meta
##OEROOT##/meta-openembedded/meta-oe
##OEROOT##/meta-openembedded/meta-networking
##OEROOT##/meta-openembedded/meta-perl
##OEROOT##/meta-openembedded/meta-python
##OEROOT##/meta-phosphor
##OEROOT##/meta-aspeed
##OEROOT##/meta-byosoft
##OEROOT##/meta-byosoft/meta-4u-x201
"
BBLAYERS_NON_REMOVABLE ?= "
##OEROOT##/meta
##OEROOT##/meta-openembedded/meta-oe
##OEROOT##/meta-openembedded/meta-networking
##OEROOT##/meta-openembedded/meta-perl
##OEROOT##/meta-openembedded/meta-python
##OEROOT##/meta-phosphor
##OEROOT##/meta-aspeed
##OEROOT##/meta-byosoft
##OEROOT##/meta-byosoft/meta-4u-x201
"
BBLAYERS变量指定了哪些layers是有效的,一般来说,最后一个layers是具体与machine相关的(##OEROOT##/meta-byosoft/meta-4u-x201),而其余layers是通用的,所以我们若想添加程序的话,就要考虑清楚是给所有machine添加,还是只给具体的machine添加。
由于我们是测试操作,所以只在4u-x201机型中添加程序,降低影响。注意:请提前确认这个机型能编译通过。
1.3 确认生效配方(recipes)路径
进入meta-byosoft/meta-4u-x201目录下,输入cat conf/bblayers.conf.sample命令,查看生效的配方所在路径,结果如下。
~/work/byobmc/meta-byosoft/meta-4u-x201$ ls
byo_fw_version.ini recipes-bsp recipes-extended recipes-mytest recipes-protocols
classes recipes-connectivity recipes-httpd recipes-phosphor recipes-support
conf recipes-core recipes-kernel recipes-platform sources
~/work/byobmc/meta-byosoft/meta-4u-x201$ cat conf/layer.conf
We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"
We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-//.bb
${LAYERDIR}/recipes-//.bbappend"
...
BBFILES变量指定哪些路径下的配方文件是有效的,其中${LAYERDIR}变量就是layers的目录meta-byosoft/meta-4u-x201,也就是说,meta-byosoft/meta-4u-x201目录下recipes-//.bb和/recipes-//.bbappend配方文件都生效。
所以我们可以在meta-byosoft/meta-4u-x201目录下创建一个配方目录,如recipes-mytest,或者使用现成的目录,如recipes-platform。由于本文只是测试,故新建recipes-mytest目录区分原始配方,后续操作将在recipes-mytest目录下进行,也就是说配方文件将创建在meta-byosoft/meta-4u-x201/recipes-mytest目录下。
2 单文件程序
在meta-byosoft/meta-4u-x201目录下执行mkdir recipes-mytest命令,再进入recipes-mytest目录执行mkdir hello命令,然后进入hello目录下,创建以下目录和文件。
~/work/byobmc/meta-byosoft/meta-4u-x201/recipes-mytest/hello$ tree
.
├── files
│ └── helloworld.c
└── hello.bb
其中helloworld.c文件填入以下内容:
//helloworld.c文件
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello world!\n");
return 0;
}
hello.bb文件填入以下内容:
#hello.bb文件
SUMMARY = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESPATH 为什么不要?思考一下,参考《bitbake工作流程》文章内容~~~
#FILESPATH := "${THISDIR}/files:"
SRC_URI = "file://helloworld.c"
为什么要指定S变量?思考一下,参考《bitbake工作流程》文章内容~~~
S = "${WORKDIR}"
重载do_compile任务,编译工作就是下面这条命令,注意使用$
do_compile() {
{CC} {LDFLAGS} helloworld.c -o helloworld
}
重载do_instal任务,安装编译成果helloworld
do_install() {
install -d {D}{bindir}
install -m 0755 helloworld {D}{bindir}
}
FILES 表示这个软件包,需要打包进映像的文件是helloworld,但决定这个软件包是否参与打包,需要在其他地方配置
FILES 为什么不要?思考一下,参考《bitbake工作流程》文章内容~~~
#FILES_{PN} += " {bindir}/helloworld "
可以看到上面FILESPATH变量和FILES变量并未指定,它们采用默认值即可,不太懂的同学查看该系列文章中的Bitbake工作流程分析。
返回yocto工程顶层目录,执行以下两个命令:
export TEMPLATECONF=meta-byosoft/meta-4u-x201/conf
. openbmc-env
这两个操作是设置环境变量并解析,也就是选择编译机型,之后再执行以下命令:
~/work/byobmc/build$ bitbake -s | grep hello
go-helloworld :0.1-r0
hello :1.0-r0
可以看到hello软件包(程序)已经加入到yocto工程,我们编译一下它,执行bitbake hello命令。
~/work/byobmc$ bitbake hello
Loading cache: 100% |#########################################################################################| Time: 0:00:00
Loaded 3503 entries from dependency cache.
Parsing recipes: 100% |#######################################################################################| Time: 0:00:02
Parsing of 2389 .bb files complete (2378 cached, 11 parsed). 3514 targets, 334 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
...
Initialising tasks: 100% |####################################################################################| Time: 0:00:00
Sstate summary: Wanted 6 Found 6 Missed 0 Current 69 (100% match, 100% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 469 tasks of which 469 didn't need to be rerun and all succeeded.
之后我们就可以在build目录下找到编译成果,不同yocto工程的存放路径可能不同,因此进入build/tmp目录下执行find . -type d -name "hello"命令搜索具体目录,示例如下:
~/work/byobmc/build/tmp$ find . -type d -name "hello"
./deploy/licenses/hello
./work/armv6-openbmc-linux-gnueabi/hello
./work/armv6-openbmc-linux-gnueabi/hello/1.0-r0/packages-split/hello
./work/armv6-openbmc-linux-gnueabi/hello/1.0-r0/license-destdir/hello
./work/x86_64-nativesdk-oesdk-linux/nativesdk-db/1_5.3.28-r1/db-5.3.28/examples/java/src/collections/hello
./work-shared/gcc-8.3.0-r0/gcc-8.3.0/libgo/go/cmd/go/testdata/src/vend/hello
./stamps/armv6-openbmc-linux-gnueabi/hello
./sysroots-components/armv6/hello
由上可以知道hello软件包的成果位于build/tmp/work/armv6-openbmc-linux-gnueabi/hello/1.0-r0/目录下,执行以下命令查看成果。
~/work/byobmc/build/tmp/work/armv6-openbmc-linux-gnueabi/hello/1.0-r0$ ls
configure.sstate hello.spec image packages-split pseudo sysroot-destdir
debugsources.list helloworld license-destdir patches recipe-sysroot temp
deploy-rpms helloworld.c package pkgdata recipe-sysroot-native
~/work/byobmc/build/tmp/work/armv6-openbmc-linux-gnueabi/hello/1.0-r0$ ls image/usr/bin/
helloworld
可以看到编译目录下有源文件helloworld.c,也有编译成果helloworld,安装目录image/usr/bin/下成功安装了成果物。
我们编译整个固件看看,返回yocto工程顶层目录,执行以下:
~/work/byobmc$ export TEMPLATECONF=meta-byosoft/meta-4u-x201/conf
~/work/byobmc$ . openbmc-env
Initializing OE build env
Common targets are:
obmc-phosphor-image
注意obmc-phosphor-image需要根据. openbmc-env命令结果来修改,不同yocto工程的固件名称可能不一样
~/work/byobmc/build$ bitbake obmc-phosphor-image
Loading cache: 100% |#########################################################################################| Time: 0:00:01
Loaded 3503 entries from dependency cache.
Parsing recipes: 100% |#######################################################################################| Time: 0:00:03
Parsing of 2389 .bb files complete (2379 cached, 10 parsed). 3514 targets, 334 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
...
Initialising tasks: 100% |####################################################################################| Time: 0:00:05
Sstate summary: Wanted 208 Found 208 Missed 0 Current 1410 (100% match, 100% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 4543 tasks of which 4543 didn't need to be rerun and all succeeded.
然后我们查看固件最终根文件系统下是否有helloworld程序。
~/work/byobmc$ ls ./build/tmp/work/4u_x201-openbmc-linux-gnueabi/obmc-phosphor-image/1.0-r0/rootfs/usr/bin/hello*
ls: cannot access './build/tmp/work/4u_x201-openbmc-linux-gnueabi/obmc-phosphor-image/1.0-r0/rootfs/usr/bin/hello*': No such file or directory
可以发现并没有helloworld,这是因为配方文件的FILES 变量知识表示hello软件包,需要打包进映像的文件是helloworld,但是否让hello软件包参与最终映像打包,则需要在其他地方配置,这部分内容将在本文最后面讲解。
3 多文件程序
虽然helloworld程序很简单,但为了演示多个文件如何添加,还是将其拆分为两个文件。多个文件编译可分为三种情况构建,分别为Makefile编译构建、cmake编译构建、Autotools编译构建,下面分别介绍三种构建方法。
3.1 Makefile编译构建
我们在meta-byosoft/meta-4u-x201/recipes-mytest目录下创建hellomake目录,并进入该目录下创建以下文件。
~/work/byobmc/meta-byosoft/meta-4u-x201/recipes-mytest/hellomake$ tree
.
├── files
│ ├── Makefile
│ ├── helloworld.c
│ └── main.c
└── hellomake.bb
其中helloworld.c文件内容如下:
//helloworld.c文件
#include <stdio.h>
void myhello(void)
{
printf("Hello world!\n");
}
main.c文件内容如下:
//main.c文件
#include <stdio.h>
extern void myhello(void);
int main(int argc, char *argv[])
{
myhello();
return 0;
}
Makefile文件内容如下:
#Makefile文件
OBJS=main.o helloworld.o
TARGET=hellomake
(TARGET): (OBJS)
(CC) (CFLAGS) (LDFLAGS) ^ -o $(TARGET)
%.o:%.c
(CC) -c -o @ $<
install:
install -d $(DESTDIR)
install -m 0755 (TARGET) (DESTDIR)
uninstall:
{RM} (DESTDIR)/$(TARGET)
clean:
(RM) (TARGET) $(OBJS)
.PHONY: install uninstall clean
hellomake.bb文件内容如下:
#hellomake.bb文件
SUMMARY = "Simple hellomake application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "
file://main.c
file://helloworld.c
file://Makefile
"
S = "${WORKDIR}"
EXTRA_OEMAKE = " 'CC={CC}' 'CFLAGS={CFLAGS}' 'LDFLAGS=${LDFLAGS}' "
EXTRA_OEMAKE_append = " 'DESTDIR={D}/{bindir}' "
#上面这条语句可以不要,下面语句改为oe_runmake DESTDIR={D}/{bindir} install即可
do_install() {
oe_runmake install
}
FILES 表示这个软件包,需要打包进映像的文件是hellomake,但决定这个软件包是否参与打包,需要在其他地方配置
#FILES_{PN} += " {bindir}/hellomake "
进入files目录下执行make命令测试编译无误,然后返回yocto工程目录顶层,执行以下:
~/work/byobmc$ export TEMPLATECONF=meta-byosoft/meta-4u-x201/conf
~/work/byobmc$ . openbmc-env
Initializing OE build env
Common targets are:
obmc-phosphor-image
~/work/byobmc/build$ bitbake -s | grep hello
go-helloworld :0.1-r0
hello :1.0-r0
hellomake :1.0-r0
~/work/byobmc/build$ bitbake hellomake
Loading cache: 100% |#########################################################################################| Time: 0:00:00
Loaded 3504 entries from dependency cache.
Parsing recipes: 100% |#######################################################################################| Time: 0:00:02
Parsing of 2390 .bb files complete (2380 cached, 10 parsed). 3515 targets, 334 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
...
Initialising tasks: 100% |####################################################################################| Time: 0:00:00
Sstate summary: Wanted 12 Found 6 Missed 6 Current 63 (50% match, 92% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 469 tasks of which 455 didn't need to be rerun and all succeeded.
编译成果可参考之前方法查看,同样hellomake成果未参与固件映像打包。
3.2 cmake编译构建
我们在meta-byosoft/meta-4u-x201/recipes-mytest目录下创建hellocmake目录,并进入该目录下创建以下文件。
~/work/byobmc/meta-byosoft/meta-4u-x201/recipes-mytest/hellocmake$ tree
.
├── files
│ ├── CMakeLists.txt
│ └── src
│ ├── helloworld.c
│ └── main.c
└── hellocmake.bb
其中CMakeLists.txt文件内容如下:
#CMakeLists.txt文件
cmake_minimum_required (VERSION 3.0)
project(hellocmake)
set(SRC_LIST ./src/helloworld.c ./src/main.c)
add_executable(hellocmake ${SRC_LIST})
install(TARGETS hellocmake DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin)
helloworld.c文件内容如下:
//helloworld.c文件
#include <stdio.h>
void myhello(void)
{
printf("Hello world!\n");
}
main.c文件内容如下:
//main.c文件
#include <stdio.h>
extern void myhello(void);
int main(int argc, char *argv[])
{
myhello();
return 0;
}
hellocmake.bb文件内容如下:
#hellocmake.bb文件
SUMMARY = "Simple hellocmake application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
#继承cmake类
inherit cmake
SRC_URI = "
file://src/main.c
file://src/helloworld.c
file://CMakeLists.txt
"
S = "${WORKDIR}"
FILES 表示这个软件包,需要打包进映像的文件是hellomake,但决定这个软件包是否参与打包,需要在其他地方配置
#FILES_{PN} += " {sbindir}/hellocmake "
进入hellocmake/files目录下执行cmake .命令,再执行make命令,确保编译无误,然后返回yocto工程目录顶层,执行以下:
~/work/byobmc$ export TEMPLATECONF=meta-byosoft/meta-4u-x201/conf
~/work/byobmc$ . openbmc-env
Initializing OE build env
Common targets are:
obmc-phosphor-image
~/work/byobmc/build$ bitbake -s | grep hello
go-helloworld :0.1-r0
hello :1.0-r0
hellocmake :1.0-r0
hellomake :1.0-r0
~/work/byobmc/build$ bitbake hellocmake
Loading cache: 100% |#########################################################################################| Time: 0:00:00
Loaded 3505 entries from dependency cache.
Parsing recipes: 100% |#######################################################################################| Time: 0:00:01
Parsing of 2391 .bb files complete (2381 cached, 10 parsed). 3516 targets, 334 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
...
Initialising tasks: 100% |####################################################################################| Time: 0:00:00
Sstate summary: Wanted 12 Found 6 Missed 6 Current 67 (50% match, 92% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 502 tasks of which 487 didn't need to be rerun and all succeeded.
编译成果可参考之前方法查看,同样hellocmake成果未参与固件映像打包。
~/work/byobmc/build/tmp/work/armv6-openbmc-linux-gnueabi/hellocmake/1.0-r0$ ls
CMakeLists.txt deploy-rpms license-destdir patches recipe-sysroot sysroot-destdir
build hellocmake.spec package pkgdata recipe-sysroot-native temp
debugsources.list image packages-split pseudo src toolchain.cmake
~/work/byobmc/build/tmp/work/armv6-openbmc-linux-gnueabi/hellocmake/1.0-r0$ ls image/usr/sbin/
hellocmake
3.3 Autotools编译构建
我们在meta-byosoft/meta-4u-x201/recipes-mytest目录下创建helloauto目录,并进入该目录下创建以下文件。
~/work/byobmc/meta-byosoft/meta-4u-x201/recipes-mytest/helloauto$ tree
.
└── files
├── Makefile.am
├── configure.ac
└── src
├── Makefile.am
├── helloworld.c
└── main.c
其中./files/configure.ac文件内容如下:
AC_INIT([helloauto], [1.0], [xxx@yyy.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT
./files/Makefile.am文件内容如下:
#上层目录什么也不做,由src子目录的Makefile.am完成工作
SUBDIRS = src
./files/src/Makefile.am文件内容如下:
bin表示helloauto程序安装在$(prefix)/bin目录下,通常为/usr/bin/,也可以改为sbin,即安装在/usr/sbin/目录下,PROGRAMS表示是一个可执行程序
bin_PROGRAMS = helloauto
表示helloauto程序的源码文件有main.c helloworld.c
helloauto_SOURCES = main.c helloworld.c
./files/src/helloworld.c文件内容如下:
//helloworld.c文件
#include <stdio.h>
#include <config.h> //注意与之前文件差异,多包含一个头文件
void myhello(void)
{
printf("Hello world!\n");
}
./files/src/main.c文件内容如下:
//main.c文件
#include <stdio.h>
#include <config.h> //注意与之前文件差异,多包含一个头文件
extern void myhello(void);
int main(int argc, char *argv[])
{
myhello();
return 0;
}
./helloauto.bb文件内容如下:
#helloauto.bb文件
SUMMARY = "Simple helloauto application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
#继承autotools类
inherit autotools
SRC_URI = "
file://src/Makefile.am
file://src/main.c
file://src/helloworld.c
file://Makefile.am
file://configure.ac
"
S = "${WORKDIR}"
FILES 表示这个软件包,需要打包进映像的文件是helloauto,但决定这个软件包是否参与打包,需要在其他地方配置
#FILES_{PN} += " {bindir}/helloauto "
在helloauto/files目录下执行 autoreconf --install && ./configure && make && ./src/helloauto 命令,确保编译执行无误,然后返回yocto工程目录顶层,执行以下:
~/work/byobmc$ export TEMPLATECONF=meta-byosoft/meta-4u-x201/conf
~/work/byobmc$ . openbmc-env
Initializing OE build env
Common targets are:
obmc-phosphor-image
~/work/byobmc/build$ bitbake -s | grep hello
go-helloworld :0.1-r0
hello :1.0-r0
helloauto :1.0-r0
hellocmake :1.0-r0
hellomake :1.0-r0
~/work/byobmc/build$ bitbake helloauto
Loading cache: 100% |#########################################################################################| Time: 0:00:00
Loaded 3506 entries from dependency cache.
Parsing recipes: 100% |#######################################################################################| Time: 0:00:02
Parsing of 2392 .bb files complete (2382 cached, 10 parsed). 3517 targets, 334 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
...
Initialising tasks: 100% |####################################################################################| Time: 0:00:00
Sstate summary: Wanted 13 Found 7 Missed 6 Current 66 (53% match, 92% complete)
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 480 tasks of which 466 didn't need to be rerun and all succeeded.
编译成果可参考之前方法查看,同样hellocmake成果未参与固件映像打包。
~/work/byobmc/build/tmp/work/armv6-openbmc-linux-gnueabi/helloauto/1.0-r0$ ls
Makefile.am compile configure.ac helloauto.spec missing pseudo temp
Makefile.in config.guess configure.sstate image package recipe-sysroot
aclocal.m4 config.h.in debugsources.list install-sh packages-split recipe-sysroot-native
autom4te.cache config.sub depcomp license-destdir patches src
build configure deploy-rpms m4 pkgdata sysroot-destdir
~/work/byobmc/build/tmp/work/armv6-openbmc-linux-gnueabi/helloauto/1.0-r0$ ls image/usr/bin/
helloauto
4 添加已有的软件包(程序)
如果想添加yocto工程已有的软件包怎么办?执行 bitbake -s 命令可列出已有软件包,找到想要添加的包名,然后配置文件,在其中添加即可,示例如下:
~/work/byobmc/meta-byosoft/meta-4u-x201$ ls conf/local.conf.sample
conf/local.conf.sample
~/work/byobmc/meta-byosoft/meta-4u-x201$vim conf/local.conf.sample
#添加以下内容,其中xxx为包名
CORE_IMAGE_EXTRA_INSTALL += "xxx"
这种方式是永久添加,若只是简单测试,则添加到build/conf/local.conf中即可。
5 添加脚本
有时我们想要添加一些脚本怎么办?这里建议创建一个bb文件来管理一类脚本,比如meta-byosoft/meta-4u-x201/recipes-mytest/scripts/scripts.bb文件中添加一系列脚本,示例如下:
SUMMARY = "examples"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
#${THISDIR}表示bb文件所在路径,即meta-byosoft/meta-4u-x201/recipes-mytest/scripts
FILESPATH := "{THISDIR}/../../sources/{PN}:"
S = "${WORKDIR}"
SRC_URI = "
file://ldapwhoami
file://serialportuserinit
"
do_install() {
install -m 0755 -d {D}{sbindir}
install -m 0755 {S}/ldapwhoami {D}${sbindir}
install -m 0755 {S}/serialportuserinit {D}${sbindir}
}
注意上面FILESPATH变量重新指定了路径,这样的好处是使配方文件与源文件分离,正常情况下,我们都应该这样做,方便管理代码(之前示例将源文件放在配方文件相同目录files下的方式不方便管理代码)。
6 将软件包(程序)添加到最终映像
有两种方法将软件包添加到映像打包。
第一种
在顶层目录下搜索固件名对应的bb文件,在其中添加 IMAGE_INSTALL += “xxx” ,其中xxx为软件包名字,即bb文件名称。
固件名称可通过 . oe-init-build-env命令获取,如下:
~/work/byobmc$ . oe-init-build-env
Common targets are:
obmc-phosphor-image
然后再执行find . -name "obmc-phosphor-image*.bb"命令查找对应bb文件,示例如下:
~/work/byobmc$ find . -name "obmc-phosphor-image*.bb"
./meta-phosphor/recipes-phosphor/images/obmc-phosphor-image.bb
在obmc-phosphor-image.bb文件中添加IMAGE_INSTALL += "xxx"即可,但这种方式添加的软件包将应用到所有项目中,这往往不是我们想要的,因此推荐第二种方式。
第二种
在对应机型的layer.conf 文件中添加,例如meta-byosoft/meta-4u-x201/conf/layer.conf 文件添加如下:
IMAGE_INSTALL_append += "hellomake"
IMAGE_INSTALL_append += "hellocmake"
IMAGE_INSTALL_append += "helloauto"
IMAGE_INSTALL_append += "scripts"
然后删除build/conf目录,再次执行以下命令:
~/work/byobmc$ export TEMPLATECONF=meta-byosoft/meta-4u-x201/conf
~/work/byobmc$ . openbmc-env
Initializing OE build env
Common targets are:
obmc-phosphor-image
~/work/byobmc/build$ bitbake obmc-phosphor-image
即可将加入的软件打包至最终固件映像中。
原作者:caodongwang