Run on Startup
Now that the application has been completed and verified, the next step is to
configure it to run a lightshow during device startup. This is done by
installing an init script from the led-example package.
File Structure
Init scripts are a practical way to automate startup tasks. In this example, the script is installed directly from the Buildroot package. Start by creating the necessary folder structure in the project root:
project_root
└── externals
└── myproj
└── package
└── led-example
└── S61led-lightshow
Create the package/led-example directory if it does not already exist.
Creating the Init Script
Create a file named S61led-lightshow in
externals/myproj/package/led-example:
package
└── led-example
└── S61led-lightshow
Populate S61led-lightshow with the following script:
#!/bin/sh
#
# Start the LED lightshow during startup and exit automatically after
# a short demo run.
#
DAEMON=/usr/bin/led-example
PIDFILE=/var/run/led-lightshow.pid
STARTUP_DEMO_MAX_TICKS=3
DAEMON_ARGS="$STARTUP_DEMO_MAX_TICKS"
case "$1" in
start)
echo "Starting LED lightshow..."
if [ -f "$PIDFILE" ] && ! kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
rm -f "$PIDFILE"
fi
start-stop-daemon -S -q -b -m -p "$PIDFILE" -x "$DAEMON" -- $DAEMON_ARGS
;;
stop)
echo "Stopping LED lightshow..."
start-stop-daemon -K -q -p "$PIDFILE" -x "$DAEMON"
status=$?
rm -f "$PIDFILE"
exit $status
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
As mentioned in Getting Started, the S61 prefix follows the SysV init-script naming
convention where startup scripts in /etc/init.d are run in numeric order. S61 runs
after S60hello-acu6 if that demo is still installed.
In this example, the startup script passes max_ticks=3 to led-example.
That makes the boot-time lightshow a short bounded demo run which exits on its
own after a few sequence steps, instead of continuing indefinitely in the
background.
Install the Init Script from led-example.mk
Next, update externals/myproj/package/led-example/led-example.mk so the
package installs the init script into /etc/init.d on the target system.
Add the following block before the $(eval $(generic-package)) line:
define LED_EXAMPLE_INSTALL_INIT_SYSV
$(INSTALL) -D -m 0755 $(LED_EXAMPLE_PKGDIR)/S61led-lightshow \
$(TARGET_DIR)/etc/init.d/S61led-lightshow
endef
Verification
After creating and configuring the init script, the next step is to build and flash the image to verify the functionality.
Build and Flash the Image
Clean the build directory:
make buildroot-led-example-dircleanCompile the application:
makeFlash the compiled program onto the target device:
make flash
Observing the Results
After flashing the image and allowing the device to boot, observe the LEDs. If the setup is correct, the LEDs should start automatically according to the script configuration and then stop on their own after the short demo run. This confirms that the init script is working and that the application starts during boot with the intended bounded behavior.