Add a new application to openWRT
From Ubicom Developer
This application note shows how to add a simple package to OpenWrt. With an example, it describes how to integrate a simple application into the OpenWrt build system. The example is a simple application package called simple. The simple application prints 1 to 99.
Contents |
Create a New Package
Change to the package directory:
$ cd openwrt/package
Create a new directory named simple:
$ mkdir simple $mkdir simple/src $cd simple/src
Add source files
Create main.c in simple/src directory.
#include <stdio.h>
int main(void)
{
int i=0;
while (i < 100) {
printf(" Hello world %d \n",i);
i++;
}
return 0;
}
Create Makefile as shown below to compile main.c in simple/src directory. Note that lines in Makefile must be indented with tabs.
# build executable on typing make all: simple %.o: %.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -I. -Iinclude -o $@ $^ simple: main.o $(CC) -o $@ $^ -L. clean: rm -f *.o simple
Compile on Local PC
--- Optional step ---
The file main.c can be compiled using a compiler on the host PC to see if there are any errors in the code and if the Makefile is working fine.
$ make
The created application can be run and tested on the host PC to see if it is working fine.
./simple Hello world 0 Hello world 1 ... Hello world 99
Please note that we have not cross-compiled for the target system yet. So, the application is built using GLIBC instead of libc intended for the target. This means that the created application will run only on your host PC but not on the target. Finally run clean to clear the object files and executables created as they are not cross compiled.
$make clean
Integrate to OpenWrt Build System
Create a top level Makefile in package/simple directory. This Makefile will intergrate the package to the openWRT build system along with the menuconfig.
Change to package/simple directory:
$cd ..
Create the following Makefile:
# # Top level makefile for simple application # include $(TOPDIR)/rules.mk PKG_NAME:=simple PKG_VERSION:=1.0.0 PKG_RELEASE:=1 include $(INCLUDE_DIR)/package.mk define Package/simple SECTION:=utils CATEGORY:=Utilities TITLE:=simple -- prints simple 1 to 99 endef define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR) endef define Build/Configure endef TARGET_CFLAGS += $(FPIC) define Package/simple/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/simple $(1)/bin/ endef $(eval $(call BuildPackage,simple))
Some of you might notice that this Makefile has eliminated several items such as downloading sources from Internet, checking md5sum etc because the application sources are present locally.
Compile
To compile the application, first the application needs to be selected for building. This can be accomplished by running menuconfig at the top level directory of openWRT.
$make menuconfig
Select the simple application under the "Utilites" sub item:
OpenWrt Configuration
Utilities
<*> simple
Compile the distribution by typing the following command at the top level directory:
$ make V=99
The above V=99 option gives a verbose output. It allows you to get back a more information about the build and see what happened if the compilation fails with an error.
Verify if the application is created in the build directory and if relevant files are included in the romfs image.
Verify
Load the image to the target. The application will be present in the /bin directory on the target.
Common errors
Some of the common problems are as follows
menuconfig does not show the new package
This problem happens if openwrt/packages/tmp is already present. Delete tmp directory and retry make menuconfig.
Applet not found
This problem typically happens when the application was built for the host PC instead of the target. One way to verify is to go to the openwrt/build-dir/simple-1.0.0 directory and do the following:
ubicom32-elf-objdump -x simple
Check the output and verify that the architecture of the created application is ubicom32vX and that the libc is not the GLIBC of the host PC but that of target.
More information
Refer to the below post about adding packages in openWrt.
https://forum.openwrt.org/viewtopic.php?pid=31794
http://nbd.name/openwrt.html

