In the previous chapters, you learned how to develop applications that work on Intel Galileo. You learned how to deploy applications to Intel Galileo with the help of Eclipse IDE or by using the SCP command-line tool to transfer application binary files. During the course of this chapter, we will work on how we can make our application or applications start at boot time and run as a background process or service on Intel Galileo Yocto Linux operating system.
While we arrived around the end of the development process, we would like to run our application in Intel Galileo when the board boots up with no user command to start it. We want the Smart Home application to run automatically because managing a home from just a command line terminal interface is not so user friendly. Therefore, for this, we will also need to define some features for the Smart Home application to send commands to and receive data from.
Let's start with what we can do to make Smart Home application start as a background process in Intel Galileo.
Customizing Linux means changing the default system configurations and adding or removing applications and kernel modules to the default Linux build for Intel Galileo. While following the steps described in the Chapter 1, Getting Started with Intel Galileo, we didn't make any changes, and so we only built the default full image defined for Intel Galileo.
In the previous chapters, we briefly mentioned adding the OpenCV
library and added the cp210x
kernel module to our default Linux image. The OpenCV
library is an open source package and it was already delivered with the Intel Galileo board support package. In this section, we will make the required configurations and changes to build a structure to add our own application to the Linux image.
To add a new application, we need to add a Yocto Project recipe to the Intel Galileo Yocto Project. If you have developed a whole software stack with a number of applications, services, and libraries, it would be better to create your own directory like meta-clanton-distro
and add the required configuration files to the directory. Finally, we need to add the new directory in the setup.sh
file to the BBLAYERS
variable. Configuration files make the BitBake script read the whole directory under the defined directory, parse the recipes, and build all of them. We will only deploy one application to the Intel Galileo default Yocto Linux image. Therefore, we will work only on the existing recipes and create our own Yocto Project recipe. Before going forward, it will be a good practice to review Chapter 1, Getting Started with Intel Galileo, to remember the steps you have initialized for the Yocto Project build environment. The build directory (BUILD_DIR)
was /home/onur/galileo_build
, and the Yocto Project files were stored in meta-clanton_v1.0.1
.
Let's go into the build directory to create a new file and start writing the recipe, as shown in the following commands:
$ cd $BUILD_DIR/meta-clanton_v1.0.1
/meta-oe/meta-oe/recipes-support
. Directories such as recipes-multimedia, recipes-core, recipes-extended, and others, can also be selected. How you classify your application depends on you. Now create a directory using the following command:$ mkdir meta-oe/meta-oe/recipes-support/smarthome
.bb
file with which we will define our application for the build process; save it empty with Ctrl + O:$ nano meta-oe/meta-oe/recipes-support/smarthome_0.0.1.bb
We defined the first lines of smarthome_0.0.1.bb
file which are given here:
DESCRIPTION = "Home Automation Application for Intel Galileo" SECTION = "base" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://COPYING;md5=c5bb609535f48d5cd02fe14a780f3d8c" DEPENDS += "opencv"
SRC_URI
variable. Paths can be a Git, SVN repository, HTTP, FTP, or a local path. In the sample recipes, we defined the source in a local path. We also need to enter the checksum and sha256sum
values. We added the following lines to our recipe:SRC_URI = "file:///home/onur/tmp/galileo_ha/smarthome-0.0.1.tar.gz" SRC_URI[md5sum] = "46ef1371208ee57f89cbfa793a689eba" SRC_URI[sha256sum] = "dd4d8cd85c86c440173e60af36e227fbc2cffb151877ebaed8d474625cd889cd"
S = "${WORKDIR}/${PN}-${PV}" inherit autotools gettext
/usr/bin
. The following definition will carry out extra installation steps for auto start descriptions. We will add the following lines at the end of the smarthome_0.0.1.bb
file:do_install_append(){ mkdir ${D}/etc mkdir ${D}/etc/init.d mkdir ${D}/etc/rcS.d install -m 0755 ${S}/scripts/startha.sh ${D}${sysconfdir}/init.d ln -sf ../init.d/startha.sh ${D}${sysconfdir}/rcS.d/S99startha.sh }
As you see in the previous installation definition, we also have a startup script to execute at boot time. We have included the script to the project source folder under scripts
folder as startha.sh
. The startup script is defined as given in the following command:
#!/bin/sh # Start the Home Automation Application echo "Starting Home Automation Application" > /var/log/homelog /usr/bin/smart_home &> /var/log/homelog
DESCRIPTION = "Home Automation Application for Intel Galileo" SECTION = "base" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://COPYING;md5=c5bb609535f48d5cd02fe14a780f3d8c" DEPENDS += "opencv" SRC_URI = "file:///home/onur/tmp/galileo_ha/smarthome-0.0.1.tar.gz" SRC_URI[md5sum] = "46ef1371208ee57f89cbfa793a689eba" SRC_URI[sha256sum] = "dd4d8cd85c86c440173e60af36e227fbc2cffb151877ebaed8d474625cd889cd" S = "${WORKDIR}/${PN}-${PV}" inherit autotools gettext do_install_append(){ mkdir ${D}/etc mkdir ${D}/etc/init.d mkdir ${D}/etc/rcS.d install -m 0755 ${S}/scripts/startha.sh ${D}${sysconfdir}/init.d ln -sf ../init.d/startha.sh ${D}${sysconfdir}/rcS.d/S99startha.sh }
meta-clanton_v1.0.1
folder to build Smart Home application and create the new image:$ source poky/oe-init-build-env yocto_build $ bitbake image-full-galileo
You can follow the defined steps in Chapter 1, Getting Started with Intel Galileo, to copy the created files to an SD card and boot the image on Intel Galileo.
You can apply the preceding steps to any application you have to add into the custom Linux image. To gain more expertise, you can read the Yocto Project Developer's Manual at http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html.