Difference between revisions of "How-to add a user space application to uClinux"

From Klaus' wiki
Jump to: navigation, search
Line 90: Line 90:
  
 
<source lang="c">
 
<source lang="c">
 +
#include <stdio.h>
  
 +
int main ()
 +
{
 +
printf("Hello World");
 +
return 0;
 +
}
 
</source>
 
</source>
  

Revision as of 14:59, 13 February 2011

First as root user goto the uClinux-dist directory.

The examples below are all for an hellowworld applications. Replace helloworld with the wanted application name.

Edit user/Makefile and add the line with "helloworld" exactly as shown below.

dir_  =
 
dir_$(CONFIG_USER_HELLOWORLD_HELLOWORLD)    += helloworld
 
dir_$(CONFIG_JFFS_FS)                       += mtd-utils
dir_$(CONFIG_JFFS2_FS)                      += mtd-utils

Create a directory for the application

$ mkdir user/helloworld

Next add support in the config help file. Edit config/Configure.help and add the helloworld part as shown below. NOTE: there must be two spaces before text in the comments, which cannot be more than seventy characters long.

CONFIG_USER_APPWEB_DYNAMIC
  Build AppWeb with the ability to dynamically load AppWeb modules.
  AppWeb modules are a convenient way to add your application code
  to AppWeb.
 
CONFIG_USER_HELLOWORLD_HELLOWORLD
  A user space application saying hello to the world.
 
CONFIG_USER_AGETTY_AGETTY
  Install "agetty" in /bin
  Approx. binary size: 19k

Edit the fine config/config.in. Add a line as shown below:

mainmenu_option next_comment
comment 'Miscellaneous Applications'
 
bool 'helloworld'               CONFIG_USER_HELLOWORLD_HELLOWORLD
bool '7za'                      CONFIG_USER_P7ZIP_7ZA

The application can now be found in top of the Miscellaneous Application menu If the directory contains several binaries another line can be added, where the last "HELLOWORLD" is the name of the binary file to be included.

Next a proper Makefile must be established in user/helloworld.

   EXEC = helloworld
   OBJS = helloworld.o
 
   all: $(EXEC)
 
   $(EXEC): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
 
   romfs:
        $(ROMFSINST)    /bin/$(EXEC)
 
   clean:
        -rm -f $(EXEC) *.elf *.gdb *.o

If there are more binaries to be produced use the skeleton to create a Makefile

   EXECS = helloworld goodbyeworld
   OBJS =  helloworld.o goodbyeworld.o
 
   all: $(EXECS)
 
   $(EXECS): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $@.o $(LDLIBS)
 
   romfs:
        $(ROMFSINST) -e CONFIG_USER_HELLOWORLD_HELLOWORLD             /bin/helloworld
        $(ROMFSINST) -e CONFIG_USER_HELLOWORLD_GOODBYEWORLD           /bin/goodbyeworld

NOTE: Remember not to copy directly from this page. All indentations are done with tab's not spaces!

Finally create the program.

#include <stdio.h>
 
int main ()
{
	printf("Hello World");	
	return 0;
}

Now when all this are in place run

$ make menuconfig

After checking the application build a new kernel and filesystem image. Check that helloworld are in romfs/bin !

Happy hacking on your own applications from here.