Yocto: install files with -dev recipe

Hello,

I’m trying to use the -dev version of a self written recipe.

Let’s say there is a recipe foo.bb which does nothing except from installing a systemd-service in the rootfs:

SUMMARY = "example recipe"
PR = "r0"

SRC_URI += "file://foo.service"

inherit systemd

do_install() {
    install -d ${D}${systemd_unitdir}/system/
    install -m 0644 ${WORKDIR}/foo.service ${D}${systemd_unitdir}/system
}

SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN} = "foo.service"

Now there should be a second systemd service bar.service which shall only be installed when the package foo-dev is added to the image. But this service should not be activated automatically.

I tried by adding the following to foo.bb :

SRC_URI:{PN}-dev += "file://bar.service"

do_install:append:${PN}-dev() {
    install -d ${D}${systemd_unitdir}/system/
    install -m 0644 ${WORKDIR}/bar.service ${D}${systemd_unitdir}/system
}

SYSTEMD_PACKAGES += "${PN}-dev"
SYSTEMD_SERVICE:${PN}-dev = "bar.service"
SYSTEMD_AUTO_ENABLE:${PN}-dev = "disable"

But bar.service isn’t installed to my rootfs and I get the following error when building the image:

ERROR: foo-1.0-r0 do_package: Didn't find service unit 'bar.service', specified in SYSTEMD_SERVICE:foo-dev.

Does somebody know how to solve this problem?

Best regards,
Markus

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Markus,

To address the issue with your Yocto recipe where bar.service is not being installed as part of the foo-dev package, please follow these steps:

  1. Verify File Location: Ensure bar.service is in the correct directory within your layer, ideally alongside foo.service, or ensure it is correctly referenced in your SRC_URI.

  2. Correct SRC_URI Syntax: Modify the syntax for appending to SRC_URI. Instead of SRC_URI:{PN}-dev += "file://bar.service", use:

    SRC_URI_append_${PN}-dev = " file://bar.service"
    

    Note the use of _append and the space before file://bar.service.

  3. Ensure File is Packaged: Confirm that bar.service is included in the foo-dev package by checking the do_package task logs.

  4. Check SYSTEMD_SERVICE Variable: Verify that SYSTEMD_SERVICE:${PN}-dev is set to bar.service, ensuring the build system looks for it in the foo-dev package.

  5. Disable Auto-Enable: You have correctly set SYSTEMD_AUTO_ENABLE:${PN}-dev = "disable", which should prevent bar.service from being enabled by default.

  6. Rebuild the Image: After making these changes, clean and rebuild your image to apply all modifications:

    bitbake -c clean foo
    bitbake foo
    bitbake <your-image>
    

By following these steps, bar.service should be included in the foo-dev package and installed in the root filesystem when the package is added to the image. If issues persist, double-check the file paths and ensure all syntax is correct in your recipe.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

https://community.nxp.com/t5/i-MX-Processors/How-to-automatically-start-services-with-systemd-in-Yocto/m-p/746499.

Hello @Mowlwurf,

I’m not a Yocto expert (and most of our team is busy attending Embedded World right now!), but looking into some recipes that we have in the layers, I have an idea that this might work:


SUMMARY = "example recipe"
PR = "r0"

SRC_URI += "file://foo.service"
SRC_URI += "file://bar.service"

inherit systemd

do_install() {
    install -d ${D}${systemd_unitdir}/system/
    install -m 0644 ${WORKDIR}/foo.service ${D}${systemd_unitdir}/system/
}

do_install:append:foo-dev() {
    install -m 0644 ${WORKDIR}/bar.service ${D}${systemd_unitdir}/system/
}

SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN} = "foo.service"

PACKAGES += "${PN}-dev"
FILES:${PN}-dev += "${systemd_unitdir}/system/bar.service"

SYSTEMD_PACKAGES += "${PN}-dev"
SYSTEMD_SERVICE:${PN}-dev = "bar.service"
SYSTEMD_AUTO_ENABLE:${PN}-dev = "disable"

Could you please give it a try?

Hello @rudhi.tx,

thank you for your response.
I tried your suggestion with the following results:

  • when calling bitbake foo-devI get the error
ERROR: Nothing PROVIDES 'foo-dev'. Close matches:
  foo RPROVIDES foo-dev
  • when adding foo-devto my image and building this image I get
ERROR: foo-1.0-r0 do_package: Didn't find service unit 'bar.service', specified in SYSTEMD_SERVICE:foo-dev.

It seems that the function do_install:append:${PN}-dev()isn’t called by bitbake.

Best regards,
Markus