Configuring a Buildroot Package
When setting up a Buildroot package for your ACU6 project, it’s essential to start by initializing the configuration to the default settings of the ACU6. This step forms the foundation for your package setup.
Initialization Process
Reset Configuration to Default: From the project root, run the command make defconfig. This action resets the configuration to the ACU6 default settings.
Package Placement: The new package should be placed in the myproj directory within the externals folder. Thanks to the project template, part of the infrastructure for this is already in place.
Understanding the File Structure for Buildroot Package
Properly organizing the file structure is a key aspect of setting up a new package in your ACU6 project. This structure serves as the blueprint for your package’s configuration and integration.
File Structure Overview
Your main externals directory should contain the myproj folder. Within myproj, you’ll have several important files and subdirectories:
Config.in - Configuration interface file.
configs directory with myproj_defconfig file.
external.desc - Describes the external module.
external.mk - This is the master makefile. It automatically locates any .mk files in directories under the package folder.
package directory, which should include:
hello-acu6 folder.
Creating a New Package
For the new package named led-example, create a corresponding folder named led-example inside the package directory.
package directory
└── led-example folder
Creating a Skeleton Package for Buildroot in ACU6 Project
The initial step in crafting a new package, such as led-example, for the Buildroot environment involves setting up a basic structure. This process is a standard part of Buildroot package creation and doesn’t involve any ACU6-specific modifications.
Skeleton Package Structure
Required Files: Create the following empty files and directories in the led-example package:
Config.in - Configuration script for the Buildroot system.
files directory containing:
led_example.c - The C source file for your package.
Makefile - Used to compile your C source file.
led-example.mk - Makefile script specific to the led-example package.
Configuring the Config.in File for the led-example Package
When setting up the led-example package in your Buildroot project, it’s crucial to correctly configure the Config.in file. This file plays a key role in defining the package options within the Buildroot system.
The Config.in file should contain the following configuration for the led-example package:
config BR2_PACKAGE_LED_EXAMPLE
bool "led-example"
select BR2_PACKAGE_ACTIA_LIB
help
LED example
The select BR2_PACKAGE_ACTIA_LIB line is particularly important as it ensures the inclusion of the ACTIA_LIB, necessary for communication with the base system.
Creating and Configuring the led-example.mk Makefile for Buildroot Integration
The led-example.mk Makefile is a critical component in integrating your led-example package with the Buildroot build system. This Makefile follows the standard format used for generic Buildroot packages, ensuring smooth incorporation into the overall build process.
Key Points for the Makefile
Standard Buildroot Makefile: The led-example.mk file should adhere to the standard conventions of a Buildroot Makefile. This includes specifying the build rules and dependencies for the led-example package.
Integration with Buildroot: This Makefile plays a pivotal role in connecting the package to Buildroot’s build procedure, ensuring that it is correctly compiled and integrated into the final system image.
LED_EXAMPLE_VERSION = 0.1
LED_EXAMPLE_SITE = $(LED_EXAMPLE_PKGDIR)/files
LED_EXAMPLE_SITE_METHOD = local
LED_EXAMPLE_LICENSE = Actia Software License Agreement
LED_EXAMPLE_LICENSE_FILES = EULA COPYING
LED_EXAMPLE_REDISTRIBUTE = NO
LED_EXAMPLE_INSTALL_TARGET = YES
LED_EXAMPLE_DEPENDENCIES = actia-lib
define LED_EXAMPLE_BUILD_CMDS
$(TARGET_CONFIGURE_OPTS) $(MAKE) -C $ $(@D)
endef
define LED_EXAMPLE_INSTALL_TARGET_CMDS
$(MAKE) -C $(@D) install DESTDIR=$(TARGET_DIR) PREFIX=/usr
endef
$(eval $(generic-package))
When configuring your led-example.mk Makefile for the Buildroot package, it’s essential to pay attention to the naming of variables and the declaration of dependencies. This ensures that your package correctly utilizes necessary resources and communicates effectively with other system components.
Specific Configurations
Variable Naming: Be mindful of the naming conventions used for variables in the Makefile. These names should be clear, consistent, and reflective of their function.
Defining Dependencies: A crucial line in the Makefile is:
LED_EXAMPLE_DEPENDENCIES = actia-lib
This line specifies that actia-lib is a dependency, which is necessary for using Inter-Process Communication (IPC) with the ACU6 system.
Starting with a Basic Source File for led-example
As an initial step in your led-example package development, begin by creating a simple source file named led_example.c in the files directory. This file will serve as the foundation for your application’s functionality and can be expanded upon as development progresses.
Basic led_example.c Structure
Start with a basic structure in your led_example.c file:
#include <stdio.h>
int main(void)
{
printf("Under construction\n");
return 0;
}
This code simply prints “Under construction” when executed, indicating that the application is in the early stages of development.
Detailed Makefile for led-example Package
Crafting a comprehensive Makefile in the files directory is crucial for the led-example package in your Buildroot project. This Makefile outlines the necessary details for compiling the source file and creating the executable, while adhering to standard practices.
Complete Makefile Content
TARGET_BIN = led-example
CFLAGS += -MMD -MP -Wall -Wextra -pedantic -Werror -Wno-error=deprecated-declarations
LIBS += -lactia
C_SRCS = led_example.c
OBJS += $(patsubst %.c, $(BUILD_DIR)/%.o, $(C_SRCS))
OBJS += $(patsubst %.S, $(BUILD_DIR)/%.o, $(ASM_SRCS))
DEPS = $(OBJS:%.o=%.d)
BUILD_DIR = build
.PHONY: all
all: $(BUILD_DIR)/$(TARGET_BIN)
$(BUILD_DIR)/$(TARGET_BIN): $(OBJS)
@echo LINK $@ $(LDFLAGS)
@$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
$(BUILD_DIR)/%.o: %.c
@echo CC $<
@mkdir -p $(@D)
@$(CC) -c $(CFLAGS) $< -o $@
install: all
@install -m 755 $(BUILD_DIR)/$(TARGET_BIN) $(DESTDIR)/$(PREFIX)/bin
clean:
@-rm -rf $(BUILD_DIR)/
-include $(DEPS)
This Makefile includes detailed settings for building the target binary, compiling source files, installation, and clean-up processes.
Adding the led-example Package to the Build Tree
Integrating your led-example package into the Buildroot build tree involves updating key files within the myproj folder. Understanding how these files interact and what modifications are needed is crucial for seamless integration.
Key Files and Modifications
external.mk File: This is the master makefile. It automatically locates any .mk files in directories under the package folder. Therefore, no changes are required in external.mk for led-example.
Config.in File: This file determines which packages are available for selection in the build tree. To include led-example, add the following line: source “$BR2_EXTERNAL_MYPROJ_PATH/package/led-example/Config.in”. This line should be added alongside other similar source lines, such as for the hello-acu6 package.
Verifying the Configuration of the led-example Package
After setting up the led-example package in your Buildroot project, it’s essential to verify that the configuration is correct. This verification process involves a series of commands that will confirm the package is functioning as intended.
Steps for Configuration Verification
Clean the directory: Run make buildroot-led-example-dirclean to ensure a fresh build environment.
Compile the Project: Run make in the project root to compile the project.
Flash the Build: Execute make flash to flash the build onto your target device.
Access the Device: Use SSH to connect to the device by running ssh 198.18.1.3.
Test the Package: Finally, run led-example on the command line of your device.
Expected Output: The phrase “Under construction” should be printed in the command line output. If you see this message, it confirms that the configuration of your led-example package is correct.