If you have a prebuilt or newly created custom user application myapp located in your PetaLinux project at <plnx-proj-root>/project-spec/meta-user/recipes-apps/, you may want to execute it at system startup. The steps to enable that are:
If you have prebuilt application and you have not included in PetaLinux Root file system, see Including Prebuilt Applications. If you want to create custom application and install it in PetaLinux Root file system, see Creating and Adding Custom Applications. If your auto run application is a blocking application which never exits, launch this application as a daemon.
- Create and install a new application named
myapp-init
cd <plnx-proj-proot> petalinux-create -t apps --template install -n myapp-init --enable
- Edit the file project-spec/meta-user/recipes-apps/myapp-init/myapp-init.bb.
The file should look like the
following:
# # This file is the myapp-init recipe. # SUMMARY = "Simple myapp-init application" SECTION = "PETALINUX/apps" LICENSE = "MIT" LIC_FILES_CHKSUM ="file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://myapp-init \ " S = "${WORKDIR}" FILESEXTRAPATHS_prepend := "${THISDIR}/files:" inherit update-rc.d INITSCRIPT_NAME = "myapp-init" INITSCRIPT_PARAMS = "start 99 S ." do_install() { install -d ${D}${sysconfdir}/init.d install -m 0755 ${S}/myapp-init ${D}${sysconfdir}/init.d/myapp-init } FILES_${PN} += "${sysconfdir}/*"
- To run myapp as daemon, edit the file project-spec/meta-user/recipes-apps/myapp-init/files/myapp-init.The file should look like below:
#!/bin/sh DAEMON=/usr/bin/myapp-init start () { echo " Starting myapp-init" start-stop-daemon -S -o --background -x $DAEMON } stop () { echo " Stoping myapp-init" start-stop-daemon -K -x $DAEMON } restart() { stop start } [ -e $DAEMON ] || exit 1 case "$1" in start) start; ;; stop) stop; ;; restart) restart; ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit $?
- Run
petalinux-build
.