If we want to have a program running in the OS (operating system), we must know the answers of following questions.
1. How to append a recipe to execute your source code?
2. How to make the program execute automatically after running the OS?
Answer 1:
When you want to compile the source code in YOCTO, and deploythe executable file into the FS(file system).
A. Add the recipe to execute the source code.
B. Change the makefile to deploy your executable file into the FS.
A:
In this part, I will tell you how to add an absolutely newrecipe in YOCTO project.
In a YOCTO project’s directory:
Graph1.
Something that you have to add is the contents highlight inabove graph 1, so the directory Meta-xxx and its own directories or files youhave to add and BBLayer.conf should be revised.
B:
In bbname.bb file, add the command: inherit autotools .
In the Makefile.am of your source code, add the flag: bin_PROGRAM =execute_name .
After changing, the executable file will be installautomatically into the FS.
Answer 2:
After we have the executable file, in this part, I willteach you how to execute the program automatically.
Before introducing the method to start a program in YOCTO,we have to know that how a program will be executed automatically in OS. In common system, the OS will carry out thescripts stored in /etc/init.d after starting.
So the method to execute the program automatically in YOCTO isalso to find way to add the start scripts into /etc/init.d in YOCTO build system, let OS execute the scripts in this directory then to start the programyou added. And there are also two steps you will take to add the script into/ect/init.d.
A. Find initscripts*.bb file.B. Add the initscripts*.bbappend file to install your own scripts.
A:
In proper directory, execute the command :
find ./ –name initscripts*.bb
In our project, the initscript.bb file is located in:
~/openembedded-core/meta/recipes-core/initscripts/initscripts.1.0.bb.
B:
Add the initscripts*.bbappend by the way mentioned like answer 1. The content could be like :
FILESEXTRAPATHS_prepend := "${THISDIR}/initscripts-1.0:"
SRC_URI_append = " \
file://execute_file_name.sh \
"
do_install_append () {
install -m 0755 ${WORKDIR}/ execute_file_name.sh ${D}${sysconfdir}/init.d
# create the 'normal'/non-alias link
ln -sf ../init.d/ execute_file_name.sh ${D}${sysconfdir}/rc3.d/S26 execute_file_name
}
In execute_file_name.sh file, we can write:
#!/bin/sh# Script name can be thecalled name, or something more meaningful.SCRIPTNAME=$0PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin./etc/init.d/init_utilitiesstart_function() {try_command execute_file_name &}stop_function() {# Terminate daemons, remove modules, removedevice nodes hereTELNETD_PID=`ps | grep -v grep | grep"reset_button" | awk '{print $1}'`if [[ "x$TELNETD_PID" =="x" ]]; thenecho " execute_file_name notrunning; cannot kill"elsekill $TELNETD_PIDfi}case $1 in"start")start_function;;"stop")stop_function;;"restart")stop_functionstart_function;;*)echo "Usage: $0{start|stop|restart}"esac
TIPS:
If you cannot find your .sh file under /etc/init.d, you should check the following cases:
1. The name of xxx.bbappend should be the same as xxx.bb file.
2. The name of these directory under the meta-xxx directory, should use character “-” instead of “_”.
3. The script file name exists in xxx.bbappend should be the same as the .sh file name under it’s append file.