how to start your application on boot in yocto

1. Create "recipes-support" folder in your own custom layer
2. Inside the "recipes-support" folder, create a folder for example "test"
3. Inside "test" folder, create "test" recipe, $touch test_0.1.bb
4. Open test_0.1.bb and update it with the following:

SUMMARY = "Test Application"
LICENSE = "CLOSED"

inherit update-rc.d
SRC_URI = "file://test.c \

       "

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

do_install () {
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 ${WORKDIR}/test_service ${D}${sysconfdir}/init.d/test_service

    install -d ${D}${sbindir}
    install -m 0755 ${WORKDIR}/test ${D}${sbindir}/
}

INITSCRIPT_NAME = "test_service"
INITSCRIPT_PARAMS = "start 99 1 2 3 4 5 . stop 20 0 1 6 ."
RDEPENDS_${PN} = "initscripts"
CONFFILES_${PN} += "${sysconfdir}/init.d/test_service"


5. Make sure you create "files" folder and put test.c, and test_service in it

test_service:

case "$1" in
  start)
    echo -n "Starting test application: "
    start-stop-daemon --start --exec  /usr/sbin/test
    echo "done"
    ;;  
  stop)
    echo -n "Stopping test application"
    start-stop-daemon --stop --exec /usr/sbin/test
    echo "done"
    ;;  
  restart)
    $0 stop
    $0 start
    ;;  
  *)  
    echo "Usage: test_service { start | stop | restart }" >&2
    exit 1
    ;;
esac

exit 0




Comments

  1. INITSCRIPT_PARAMS = "start 99 1 2 3 4 5 . stop 20 0 1 6 ." Can you explain more on this?

    ReplyDelete
  2. Here it is, that's init levels
    https://www.linux.com/news/introduction-services-runlevels-and-rcd-scripts/

    ReplyDelete
  3. Hello,
    I tried your example with hello.c to print "hello world" in boot
    My bb file is:
    DESCRIPTION = "A friendly program that prints Hello World!"
    PRIORITY = "optional"
    SECTION = "examples"
    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
    inherit update-rc.d
    SRC_URI = "file://hello.c"
    S = "${WORKDIR}"
    do_compile() {
    ${CC} ${CFLAGS} ${LDFLAGS} hello.c -o hello
    }
    do_install() {
    install -d ${D}${bindir}
    install -m 0755 hello ${D}${bindir}
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 test_service ${D}${sysconfdir}/init.d/test_service
    }

    INITSCRIPT_NAME = "test_service"
    INITSCRIPT_PARAMS = "start 99 1 2 3 4 5 . stop 20 0 1 6 ."
    RDEPENDS_${PN} = "initscripts"
    CONFFILES_${PN} += "${sysconfdir}/init.d/test_service"


    But i have an error in do_install, can you help me?

    ReplyDelete
    Replies
    1. I had the same problem, I have solved it by simply adding test_service into SRC_URI

      SRC_URI = "file://hello.c \
      file://test_service \
      "

      Delete
  4. I'm getting this error.
    ERROR: ParseError at /home/prutha/02_02_2022/poky/meta-mylayer/recipes-support/test/test_0.1.bb:9: unparsed line: 'do_compile ()'

    ReplyDelete

Post a Comment

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto