wiki:PortingYourApp

Version 1 (modified by Nicolas Pouillon, 15 years ago) (diff)

--

In this document, we'll port an existing app to MutekH. We'll choose a standard publicly available application: bc.

bc is a command-line arbitrary precision calculator well known in the unix world. It uses standard APIs, makes reasonable use of I/O, and has a quite verifiable result.

Getting the source tree

Let's begin getting the source, and unpack it:

$ wget http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz
$ tar xzvf bc-1.06.tar.gz

Creating our source tree

Now create another directory, and extract the meaningful sources

$ mkdir mutekh_port
$ cd mutekh_port
$ mkdir src lib h
$ cp ../bc-1.06/bc/*.[ch] bc
$ cp ../bc-1.06/lib/*.[ch] lib
$ cp ../bc-1.06/h/*.h src

Let's create the Makefiles:

  • bc/Makefile
    objs = bc.o execute.o global.o load.o main.o scan.o storage.o util.o
    
    DIR_CFLAGS=-I$(srcdir)/../lib -I$(srcdir)/../h -I$(srcdir)/.. -U__MUTEK__
    scan.o_CFLAGS=-DEINTR=-1024
    
  • lib/Makefile
    objs = getopt.o getopt1.o number.o getenv.o
    
    DIR_CFLAGS=-I$(srcdir)/../lib -I$(srcdir)/../h -I$(srcdir)/.. -U__MUTEK__ -DHAVE_CONFIG_H
    
  • Makefile
    subdirs = bc lib
    

Providing glue code

Now let's create some glue code:

  • As this is userland-specific, MutekH does not define
    • getenv()
    • signal()
    • sys/types.h We will have to provide them.

Add a lib/getenv.c file:

#include <hexo/types.h>

char *getenv(const char *env)
{
	return NULL;
}

Add a signal.h file:

#define SIGINT 0

static inline int signal(int sig, void *handler)
{
	return -1;
}

Create a sys directory, and a sys/types.h file containing:

#define isatty(x) 1
#define fileno(x) 0
#define fopen(x,y) NULL

#include <hexo/types.h>

The MutekH configuration file

FInally, let's create a configuration file. For instance, with the mutekh_tutorial soclib platform, we may use the following config:

# Application license
CONFIG_LICENSE_APP_GPL

# Platform types
CONFIG_ARCH_SOCLIB

# Processor types
CONFIG_CPU_ARM
CONFIG_CPU_ARM_SOCLIB

# Mutek features
CONFIG_PTHREAD
CONFIG_MUTEK_CONSOLE

CONFIG_LIBC_STREAM
CONFIG_LIBC_STREAM_STD

CONFIG_HEXO_INTTYPES_DEPRECATED undefined

# Device drivers
CONFIG_DRIVER_CHAR_SOCLIBTTY
CONFIG_DRIVER_ICU_SOCLIB

# Code compilation options
CONFIG_COMPILE_DEBUG
CONFIG_COMPILE_OPTIMIZE 2

# New source code module to be compiled
CONFIG_MODULES bc:%CONFIGPATH

That's all, we finished porting our app !

Compiling and running

user@host … caba-vgmn-mutekh_tutorial $ make CONFIG=config_soclib_arm APP=/path/to/mutek_port/src MUTEKH_DIR=path/to/mutekh
…
    LD o    .../caba-vgmn-mutekh_tutorial/mutekh/kernel-soclib-arm.o
    LD out  .../caba-vgmn-mutekh_tutorial/mutekh/kernel-soclib-arm.out
soclib-cc -P -p .../caba-vgmn-mutekh_tutorial/platform_desc  -o system.x
[-------------------------------------------------------------------------=] 0 left 
user@host … caba-vgmn-mutekh_tutorial $ ./simulation.x

Attachments (1)

Download all attachments as: .zip