首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Yocto系统配置

Yocto系统配置
EN

Stack Overflow用户
提问于 2022-01-21 17:44:38
回答 2查看 1.1K关注 0票数 0

我试图启动一个服务的启动,但我有问题的建设。这是我自定义层中的树结构。

代码语言:javascript
运行
复制
michael@michael-VirtualBox:~/Documents/simple_daemon/sources/meta-simpledaemon$ tree
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-example
    ├── example
    │   └── example_0.1.bb
    └── simpledaemon
        ├── files
        │   └── simpledaemon.service
        └── simpledaemon_git.bb

在我的local.conf中,我在末尾添加了以下内容:

代码语言:javascript
运行
复制
IMAGE_INSTALL_append = " bbexample "
IMAGE_INSTALL_append = " simpledaemon "
IMAGE_INSTALL_append = " packagegroup-core-ssh-openssh "
IMAGE_INSTALL_append = " openssh-sftp-server "


DISTRO_FEATURES_append = " systemd"
VIRTUAL-RUNTIME_init_manager = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""

我的.bb文件如下:

代码语言:javascript
运行
复制
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=ca119cf6dcda0f0883a416a3e7f94cc2"

SRC_URI = "git://github.com/MichaelBMiner/simpledaemon;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4"

inherit systemd

S = "${WORKDIR}/git"

SYSTEMD_SERVICE_${PN} = "simpledaemon.service"
do_compile () {
    ${CC} ${LDFLAGS} simpledaemon.c -o simpledaemon
}
do_install () {
    install -d ${D}${bindir}
    install -m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}
    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${WORKDIR}/simpledaemon.service ${D}${systemd_unitdir}/system sed -i -e     's,@BINDIR@,${bindir},g' ${D}${systemd_unitdir}/system/simpledaemon.service
}

# NOTE: if this software is not capable of being built in a separate build directory
# from the source, you should replace autotools with autotools-brokensep in the
# inherit line
inherit autotools

# Specify any options you want to pass to the configure script using EXTRA_OECONF:
EXTRA_OECONF = ""

我的simpledaemon.service如下:

代码语言:javascript
运行
复制
[Unit]
Description=Example service
[Service]
Type=forking
ExecStart=@BINDIR@/simple-service
[Install]
WantedBy=multi-user.target

我从“使用第二版嵌入式Linux开发”一书中获得了所有这些信息。

在我尝试添加这个新服务之前,我的所有构建都是成功的。这本书没有提到systemd服务的init脚本。我还从GitHub中提取代码,而不是在构建目录中提取代码(您可以查看回购)。

当我运行bitbake时,会得到错误Didn't find service unit 'simpledaemon.service', specified in SYSTEMD_SERVICE_simpledaemon.。这告诉我,这是一个路径错误,我只能假设它是由我的GitHub结构产生的。有人能在这上面照点光吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-01-23 10:42:47

你的食谱中有几个问题会导致你的错误:

1.使用正确的SRCREV

SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4“

上面的SRCREV是指在添加.service文件之前在存储库中提交。将此更改为最新提交,2140a0646b3ffc6595c50ac549dc6f1220f66c28

2.删除自动工具已经描述的步骤:

由于您的源代码使用自动工具,而Yocto食谱继承了autotools类,所以Yocto将自动运行等效的./configuremakemake install来配置/编译/安装这个包。

因此,可以删除整个do_compile任务和手动安装二进制文件的do_install的前几行:

do_compile () {{CC} ${LDFLAGS} simpledaemon.c -o simpledaemon } do_install () { -d ${D}${bindir}安装-m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}

3.使用do_install_append安装systemd服务

食谱文件末尾的inherit autotools会导致do_install任务被覆盖,因为autotools类将其设置为autotools样式的方法。

由于您需要自动工具do_install来运行,还需要一些您自己的代码(安装systemd服务),所以您可以向上移动继承,并将其与systemd代码组合:

代码语言:javascript
运行
复制
inherit autotools systemd

然后,定义一个do_install_append函数来附加安装systemd服务所需的额外步骤:

代码语言:javascript
运行
复制
do_install_append () {
    install -d ${D}${systemd_system_unitdir}
    install -m 0644 ${S}/simpledaemon.service ${D}${systemd_system_unitdir}
    sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_system_unitdir}/simpledaemon.service
}

原始do_install中也有一些错误:

  1. simpledaemon.service文件是从${S}安装的,它是源目录(即git目录),而不是${WORKDIR}
  2. sed命令应该在新行上
  3. (优化)您可以使用${systemd_system_unitdir}代替${systemd_unitdir}/system

4.删除未使用的EXTRA_OECONF = ""

EXTRA_OECONF设置为空将覆盖它拥有的任何默认值,这通常是由Yocto发行版定义的。如果您确实需要./configure的额外参数,可以考虑使用PACKAGECONFIG或最后使用EXTRA_OECONF += "--foo-bar"

完整配方:

代码语言:javascript
运行
复制
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=ca119cf6dcda0f0883a416a3e7f94cc2"

SRC_URI = "git://github.com/MichaelBMiner/simpledaemon;protocol=https"

PV = "1.0+git${SRCPV}"
SRCREV = "2140a0646b3ffc6595c50ac549dc6f1220f66c28"

inherit systemd autotools

S = "${WORKDIR}/git"

SYSTEMD_SERVICE_${PN} = "simpledaemon.service"

do_install_append () {
    install -d ${D}${systemd_system_unitdir}
    install -m 0644 ${S}/simpledaemon.service ${D}${systemd_system_unitdir}
    sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_system_unitdir}/simpledaemon.service
}

调试提示

调试菜谱的一种有用方法是将以下命令的输出转储到文件中并检查它:

代码语言:javascript
运行
复制
bitbake -e your-recipe-or-image-name

如果您检查bitbake -e simpledaemon的输出以获取原始菜谱,并查找do_install的最终定义(搜索以do_install开头的行)。很明显,解析之后,函数不包含安装服务代码的步骤。

您可以在手册中(在查看变量值下)阅读更多有关此技术的内容。

票数 5
EN

Stack Overflow用户

发布于 2022-01-22 04:19:31

您能在示例simpledaemon中移动dir dir吗?

您可以使用git.bb作为参考。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70805499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档