Run on Startup
Now that the application has been completed and verified, the next step is to configure it to run a lightshow during the device’s startup. T his involves using init scripts and setting up an overlay in the file system.
File Structure
Init scripts are ideal for automating startup tasks. Given that the filesystem is mostly read-only, an overlay will be used. Start by creating the necessary folder structure in the project root:
project_root
└── externals
└── myproj
└── board
└── actia
└── acu6
└── rootfs_overlay
Create the “board” directory and all subsequent folders underneath it. Replace “actia” with your company name as appropriate, but remember to keep it consistent throughout the exercise.
Creating Overlay Files and Folders
Next, create the files and folders that will be overlaid onto the target system:
rootfs_overlay
└── etc
└── init.d
└── S99led-lightshow
The last file, S99led-lightshow, should be created but left empty for now. This file will later be used to configure the startup script for the LED lightshow.
Add Overlay to Buildroot
To incorporate the new overlay into Buildroot, you need to update the Buildroot configuration to recognize the overlay directory you’ve created.
Updating Buildroot Configuration
Open the Buildroot configuration interface by executing make menuconfig in the terminal.
Within the configuration interface, type “/” and search for the variable BR2_ROOTFS_OVERLAY.
Press “1” to go to System configuration, and then press “Enter” to select the variable in order to update it.
Add the path to your newly created overlay directory to this variable, i.e. $(BR2_EXTERNAL_MYPROJ_PATH)/board/[your chosen company name]/acu6/rootfs_overlay, alongside any existing paths.
Save the configuration changes before exiting the configuration interface.
This process ensures that Buildroot is aware of the custom overlay, and it will include it in the filesystem of the generated system image.
Init Script
Create a simple script that will run led-example 3 late in the startup sequence. Populate the file S99led-lightshow with the following script:
#!/bin/sh
case "$1" in
start)
echo "Starting LED roll..."
led-example 3 &
;;
stop)
:;;
restart|reload)
:;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
After creating the script, ensure it has execute permissions. Run the command chmod +x S99led-lightshow to make the script executable.
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
make buildroot-led-example-dirclean: Clean the build directory to ensure a fresh start.
make: Compile the application with the new changes.
make flash: Flash the compiled program onto the target device.
Observing the Results
After the flash, once the target device has finished booting with the new image, observe the LEDs. If the setup is correct, the LEDs should light up automatically as per the script’s configuration. This indicates that the init script is functioning correctly and the application is successfully running on startup.