Yocto 系统配置

Mic*_*ael 0 systemd bitbake yocto nxp-microcontroller

我正在尝试在启动时启动服务,但是我在构建时遇到问题。\n这是我的自定义层中的树结构

\n
michael@michael-VirtualBox:~/Documents/simple_daemon/sources/meta-simpledaemon$ tree\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 conf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 layer.conf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 COPYING.MIT\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 recipes-example\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 example\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 example_0.1.bb\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 simpledaemon\n        \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 files\n        \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 simpledaemon.service\n        \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 simpledaemon_git.bb\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
IMAGE_INSTALL_append = " bbexample "\nIMAGE_INSTALL_append = " simpledaemon "\nIMAGE_INSTALL_append = " packagegroup-core-ssh-openssh "\nIMAGE_INSTALL_append = " openssh-sftp-server "\n\n\nDISTRO_FEATURES_append = " systemd"\nVIRTUAL-RUNTIME_init_manager = " systemd"\nDISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\nVIRTUAL-RUNTIME_initscripts = ""\n
Run Code Online (Sandbox Code Playgroud)\n

我的.bb文件如下:

\n
# Recipe created by recipetool\n# This is the basis of a recipe and may need further editing in order to be fully functional.\n# (Feel free to remove these comments when editing.)\n\n# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is\n# your responsibility to verify that the values are complete and correct.\nLICENSE = "MIT"\nLIC_FILES_CHKSUM = "file://LICENSE;md5=ca119cf6dcda0f0883a416a3e7f94cc2"\n\nSRC_URI = "git://github.com/MichaelBMiner/simpledaemon;protocol=https"\n\n# Modify these as desired\nPV = "1.0+git${SRCPV}"\nSRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4"\n\ninherit systemd\n\nS = "${WORKDIR}/git"\n\nSYSTEMD_SERVICE_${PN} = "simpledaemon.service"\ndo_compile () {\n    ${CC} ${LDFLAGS} simpledaemon.c -o simpledaemon\n}\ndo_install () {\n    install -d ${D}${bindir}\n    install -m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}\n    install -d ${D}${systemd_unitdir}/system\n    install -m 0644 ${WORKDIR}/simpledaemon.service ${D}${systemd_unitdir}/system sed -i -e     's,@BINDIR@,${bindir},g' ${D}${systemd_unitdir}/system/simpledaemon.service\n}\n\n# NOTE: if this software is not capable of being built in a separate build directory\n# from the source, you should replace autotools with autotools-brokensep in the\n# inherit line\ninherit autotools\n\n# Specify any options you want to pass to the configure script using EXTRA_OECONF:\nEXTRA_OECONF = ""\n
Run Code Online (Sandbox Code Playgroud)\n

我的 simpledaemon.service 如下:

\n
[Unit]\nDescription=Example service\n[Service]\nType=forking\nExecStart=@BINDIR@/simple-service\n[Install]\nWantedBy=multi-user.target\n
Run Code Online (Sandbox Code Playgroud)\n

我从《使用 Yocto Project Cookbook Second Edition 进行嵌入式 Linux 开发》一书中获得了所有这些信息。

\n

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

\n

当我运行时bitbake出现错误Didn't find service unit 'simpledaemon.service', specified in SYSTEMD_SERVICE_simpledaemon.。这告诉我这是一个路径错误,我只能假设是由我的 GitHub 结构引起的。有人能解释一下吗?

\n

Jus*_*tin 8

您的食谱存在一些问题,导致您出现错误:

1.正确使用SRCREV

SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4"
Run Code Online (Sandbox Code Playgroud)

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

2.删除autotools已经描述的步骤:

./configure由于您的源代码使用 autotools 并且 Yocto 配方继承了 autotools 类,因此 Yocto 将自动运行, make,的等效项make install来配置/编译/安装此包。

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

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

do_install () {
    install -d ${D}${bindir}
    install -m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}
Run Code Online (Sandbox Code Playgroud)

3.用于do_install_append安装systemd服务

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

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

inherit autotools systemd
Run Code Online (Sandbox Code Playgroud)

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

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
}
Run Code Online (Sandbox Code Playgroud)

你的原文也有很多错误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"


完整食谱:

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
}
Run Code Online (Sandbox Code Playgroud)

调试技巧

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

bitbake -e your-recipe-or-image-name
Run Code Online (Sandbox Code Playgroud)

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

您可以在手册中的“查看变量值”下阅读有关此技术的更多信息。