1. 程式人生 > 其它 >ycoto---學習2新增程式和指令碼

ycoto---學習2新增程式和指令碼

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任務,編譯工作就是下面這條命令,注意使用${CC}
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], [[email protected]])
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

​ 即可將加入的軟體打包至最終韌體映像中。

本公司成本價甩賣工控主機板,歡迎大家選購:
PCIE匯流排轉八串列埠卡,PCIE匯流排轉IO卡,瑞芯微3568板卡,寒武紀CE3226攝像頭板卡,龍芯CPCI板卡,龍芯3A4000工控板卡,龍芯3A5000工控板卡,海光3250工控板卡,飛騰FT-2000/4板卡

聯絡方式:
電話、微信:15918785568 羅生
Email:[email protected]
公眾號:開發之美


————————————————
版權宣告:本文為CSDN博主「caodongwang」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/zz2633105/article/details/122867225