How to Obtain the Mdns.Service File Needed for Building Mdns in Yocto

How does one get everything right to build mDNS in Yocto?

There is already a recipe for mDNS version 878.200.35:
https://git.openembedded.org/meta-openembedded/tree/meta-networking/recipes-protocols/mdns/mdns_878.200.35.bb?h=zeus

Do I need to edit the .patch files needed for building mdns 878.200.35 in Yocto?

Just download the plain files and put them in your layer.

Those files are absolutely valid patches, otherwise they wouldn't be in the upstream layer in the first place.

What's before the first --- is what's going to be the commit title (first line) and commit log of the git commit created when git applies the patch.

The +++ and second --- are to identify the files to which the patch applies. The -- at the end is just to tell git tool to ignore what lies after, which is the version number of git that was used to create said patch (with git format-patch).

run yocto package via systemd service in image

First of all, note that to use systemd service you need to make sure that systemd in DISTRO_FEATURES.

check with:

bitbake -e (YOUR_IMAGE) | grep ^DISTRO_FEATURES=

Because sysvinit is the default init manager, make sure that:

INIT_MANAGER = "systemd"

Here is a simple systemd recipe example (meta-custom/recipes-example/systemd-example/):

  • files/example.service
[Unit]
Description=Systemd Service Example
Before=basic.target

[Service]
Type=simple

# Put the path to the binary installed by do_install()
ExecStart=/usr/bin/example
ExecStop=/bin/killall example
ExecReload=/bin/killall example; /usr/bin/example

# These are optional, you can remove them, or
# read about systemd properties for more control
RemainAfterExit=yes
Restart=on-failure
RestartSec=30s

[Install]
WantedBy=basic.target
  • files/example.c

  • systemd-example_0.1.bb

SUMMARY = "Systemd example recipe"
DESCRIPTION = "Systemd service example for xxx"
LICENSE = "CLOSED"

SRC_URI = "file://example.c"
SRC_URI += "file://example.service"

S = "${WORKDIR}"

do_compile(){
${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/example.c -o ${WORKDIR}/example
}

do_install(){
install -d ${D}/usr/bin

# Install the binary
install -m 0744 ${WORKDIR}/example ${D}/usr/bin

# Install systemd stuff
install -d ${D}${systemd_unitdir}/systemd
install -m 0644 ${WORKDIR}/example.service ${D}${systemd_unitdir}/systemd
}

# Systemd class stuff
inherit systemd
NATIVE_SYSTEMD_SUPPORT = "1"
SYSTEMD_SERVICE_${PN} = "example.service"

No need for SYSTEMD_AUTO_ENABLE = "enable" because it is enable by default.

UPDATE

Now, add the recipe to your image via:

IMAGE_INSTALL_append = " systemd-example"

put that line in your custom image recipe or in local.conf for testing.

When you build the image you will find /usr/sbin/example and it will be automatically executed by the systemd service example.service, to check for the status :

systemctl status example

Yocto Systemd Configuration

There are a few issues with your recipe that lead to your error:

1. Use correct SRCREV:

SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4"

The SRCREV above refers to a commit in your repository before the .service file was added. Change this to the latest commit, 2140a0646b3ffc6595c50ac549dc6f1220f66c28

2. Remove steps already described by autotools:

Since your source code uses autotools and your Yocto recipe inherits the autotools class, Yocto will automatically run the equivalent of ./configure, make, make install to configure/compile/install this package.

Therefore, you can remove your entire do_compile task and the first few lines of do_install where you manually install the binary:

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

do_install () {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}

3. Use do_install_append to install the systemd service

The inherit autotools at the end of your recipe file causes your do_install task to be overridden as the autotools class sets it to an autotools-style method.

Since you need the autotools do_install to run, and also some of your own code (to install the systemd service), you can move the inherit upward and combine it with the systemd one:

inherit autotools systemd

and, then define a do_install_append function to append on the extra steps required to install your systemd 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
}

There were a number of errors in your original do_install too:

  1. The simpledaemon.service file is installed from ${S} which is the source directory (i.e the git directory), not ${WORKDIR}
  2. The sed command should be on a new line
  3. (optimisation) You can use ${systemd_system_unitdir} in place of ${systemd_unitdir}/system

4. Remove unused EXTRA_OECONF = ""

Setting EXTRA_OECONF to empty will override any default value it had, which often is defined by the Yocto distro. If you do need extra arguments to ./configure consider using PACKAGECONFIG or at last resort EXTRA_OECONF += "--foo-bar".



Complete recipe:

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
}


Debugging tip

A useful way to debug recipes is to dump the output of the following command to a file and inspect it:

bitbake -e your-recipe-or-image-name

If you inspect the output of bitbake -e simpledaemon for your original recipe, and look for the final definition of do_install (search for a line beginning with do_install). It was clear that after parsing, the function did not contain your steps to install the service code.

You can read more about this technique in the manual, under Viewing Variable Values.

Yocto Service Not Starting

I finally found the answer!

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

FILESEXTRAPATHS:prepend := "${THISDIR}/files/src:${THISDIR}/files/src/app:${THISDIR}/files/services:"

SRC_URI = "\
file://helloworld.service \
file://helloworld.c \
"

S = "${WORKDIR}"

inherit systemd
SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE_${PN} = "helloworld.service"

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

do_install_append() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/helloworld ${D}${bindir}

install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/helloworld.service ${D}${systemd_unitdir}/system
sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_unitdir}/system/helloworld.service
}


Related Topics



Leave a reply



Submit