In the earlier post I have explained how to add a kernel module as a new buildroot package. You can check that post here:

In this module I will explain the steps to add a program which is not a kernel module but a user space c program for testing the earlier kernel module.


Following the same way as earlier start with the below step:
Create a new folder under buildroot/package folder.

[code language="cpp"]
cd buildroot
mkdir package/test
[/code]

Now we need to create two files inside the newly created “test” folder: Config.in and test.mk.

[code language="cpp"]
touch package/test/Config.in
touch package/test/test.mk
[/code]

Now let’s populate these files with what will eventually add xyz as a new package.
Config.in

[code language="cpp"]
config BR2_PACKAGE_TEST
bool "test"
depends on BR2_PACKAGE_XYZ
help
This is test library package for XYZ driver.
[/code]

As you can see a new line has been added in the above Config.in file which starts with depends on.
depends on BR2_PACKAGE_XYZ – this is how we specify the dependency between packages. If a package is dependent on another then it will add a config option with depend on . In this case the test application is only relevant if there is the driver package available as it only tests the specific driver XYZ. Hence we have made it a dependency package of XYZ by adding this line in the Config.in.

Also, as we have made this package a dependency package of package XYZ, we have to make a little modification as below:

[code language="cpp"]
config BR2_PACKAGE_XYZ
bool "xyz"
select BR2_PACKAGE_TEST
help
This is sample package.
This selects the test application too.
[/code]

test.mk

[code language="cpp"]
TEST_VERSION = 1.0
TEST_SITE = <strong>../path/to/your/source/code/test</strong>
TEST_SITE_METHOD = local
TEST_INSTALL_TARGET = YES

define TEST_BUILD_CMDS
$(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all
endef

define TEST_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/test $(TARGET_DIR)/bin
$(INSTALL) -D -m 0755 $(@D)//run_test.sh $(TARGET_DIR)/bin
$(TARGET_DIR)/root
endef

$(eval $(generic-package))

[/code]

Now we have to tell the package system that we want to be added. Hence we do the below modification in the package config file:
buildroot/package/Config.in

[code language="cpp"]
menu "Menu-name whatever you like"
source "package/test/Config.in"
endmenu
[/code]

In this example test.mk the source path has been set as ../path/to/your/source/code/test. This is a relative path from the buildroot directory. You can specify any absolute path in your local machine as well. But important thing to remember is any relative path has to be with respect to the buildroot directory.

[code language="cpp"]
SRC=$(wildcard code/*.c)
CFLAGS = -Wall -g
INC=-I./include
all:
$(CC) $(INC) $(CFLAGS) $(SRC) -o test
clean:
[/code]

The structure of the test source code is as below:
.
├── code
│   └── test.c
├── include
│   └── test.h
├── makefile
├── scripts
│   └── run_test.sh
└── test

Now the installation as below:

$(INSTALL) -D -m 0755 $(@D)/test $(TARGET_DIR)/bin – this copies the test binary test to the $(TARGET_DIR)/bin directory and similary:
$(INSTALL) -D -m 0755 $(@D)//run_test.sh $(TARGET_DIR)/bin

Leave a Reply