George
George

Reputation: 693

Run application at start up with Yocto Dunfell

I have coded a toggle.c application in C that toggles on and off a GPIO of the BeagleBone Black board. Practically it causes an external LED to flash.

I wish to prepare a Yocto image which includes the executable binary of the application and it launches the application automatically when starting up, thus causing the LED to flash.

I have followed along the examples I found on the web. My Yocto image includes the compiled binary of the application inside /usr/bin. I can execute it from command line, all fine.

But my Yocto generated image does not start the binary automatically. LED does not flash when starting Yocto generated Linux Image.

My workflow was:

toggle.service file

[Unit]
Description= A start script from a toggle.c program

[Service]
ExecStart=/usr/bin/toggle

[Install]
WantedBy=multi-user.target

toggle_0.1.bb

DESCRIPTION = "This is a program to toggle GPIO  on/off at an interval of 1s"
PRIORITY = "optional"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://toggle.c"
S = "${WORKDIR}"
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} toggle.c -o toggle
}
do_install() {
install -d ${D}${bindir}
install -m 0755 toggle ${D}${bindir}
}

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

SRC_URI_append = " file://toggle.service "
FILES_${PN} += "${systemd_unitdir}/system/toggle.service"

do_install_append() {
  install -d ${D}/${systemd_unitdir}/system
  install -m 064 ${WORKDIR}/toggle.service ${D}/${systemd_unitdir}/system
}

I tried the same thing with diferent kind of image recipes: core-image-minimal, core-image-base, core-image-full-cmdline. All the same. They do not hold the normal Linux files for executing apps at start-up like /etc/init.d/rc.local.

Please point me towards a solution that would work for me. Thank you very much.

Upvotes: 0

Views: 3749

Answers (1)

George
George

Reputation: 693

I finally found a solution for my problem, but I sorted it out using the update-rc.d class , instead of systemd. For some reason, even though I added systemd to my image by modifying conf/local.conf with DISTRO_FEATURES_append = " systemd" , still I had no access to systemctl commands for debugging within the Yocto Project image.

My working solution is:

DESCRIPTION = "This is a recipe to launch executable program out of toggle.c at start up."
PRIORITY = "optional"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://toggle.c"
S = "${WORKDIR}"
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} toggle.c -o toggle
}
do_install() {
install -d ${D}${bindir}
install -m 755 toggle ${D}${bindir}
install -d ${D}${sysconfdir}/init.d
install -m 755 toggle ${D}${sysconfdir}/init.d/toggle
}
 
inherit update-rc.d
 
INITSCRIPT_NAME="toggle"
INITSCRIPT_PARAMS= "defaults 10"

For more information about update-rc.dand services, I recommend checking https://www.jamescoyle.net/cheat-sheets/791-update-rc-d-cheat-sheet.

Upvotes: 1

Related Questions