Changes between Initial Version and Version 1 of PortingYourApp


Ignore:
Timestamp:
Oct 8, 2009, 12:20:40 PM (15 years ago)
Author:
Nicolas Pouillon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PortingYourApp

    v1 v1  
     1In this document, we'll port an existing app to MutekH. We'll choose a standard publicly available application: `bc`.
     2
     3bc 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.
     4
     5= Getting the source tree =
     6
     7Let's begin getting the source, and unpack it:
     8{{{
     9$ wget http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz
     10$ tar xzvf bc-1.06.tar.gz
     11}}}
     12
     13= Creating our source tree =
     14
     15Now create another directory, and extract the meaningful sources
     16{{{
     17$ mkdir mutekh_port
     18$ cd mutekh_port
     19$ mkdir src lib h
     20$ cp ../bc-1.06/bc/*.[ch] bc
     21$ cp ../bc-1.06/lib/*.[ch] lib
     22$ cp ../bc-1.06/h/*.h src
     23}}}
     24
     25Let's create the Makefiles:
     26
     27 * `bc/Makefile`
     28   {{{
     29objs = bc.o execute.o global.o load.o main.o scan.o storage.o util.o
     30
     31DIR_CFLAGS=-I$(srcdir)/../lib -I$(srcdir)/../h -I$(srcdir)/.. -U__MUTEK__
     32scan.o_CFLAGS=-DEINTR=-1024
     33}}}
     34 * `lib/Makefile`
     35   {{{
     36objs = getopt.o getopt1.o number.o getenv.o
     37
     38DIR_CFLAGS=-I$(srcdir)/../lib -I$(srcdir)/../h -I$(srcdir)/.. -U__MUTEK__ -DHAVE_CONFIG_H
     39}}}
     40 * `Makefile`
     41   {{{
     42subdirs = bc lib
     43}}}
     44
     45= Providing glue code =
     46
     47Now let's create some glue code:
     48 * As this is userland-specific, MutekH does not define
     49  * `getenv()`
     50  * `signal()`
     51  * `sys/types.h`
     52   We will have to provide them.
     53
     54Add a `lib/getenv.c` file:
     55{{{
     56#include <hexo/types.h>
     57
     58char *getenv(const char *env)
     59{
     60        return NULL;
     61}
     62}}}
     63
     64Add a `signal.h` file:
     65{{{
     66#define SIGINT 0
     67
     68static inline int signal(int sig, void *handler)
     69{
     70        return -1;
     71}
     72}}}
     73
     74Create a `sys` directory, and a `sys/types.h` file containing:
     75{{{
     76#define isatty(x) 1
     77#define fileno(x) 0
     78#define fopen(x,y) NULL
     79
     80#include <hexo/types.h>
     81}}}
     82
     83= The MutekH configuration file =
     84
     85FInally, let's create a configuration file. For instance, with the mutekh_tutorial soclib platform, we may use the following config:
     86{{{
     87# Application license
     88CONFIG_LICENSE_APP_GPL
     89
     90# Platform types
     91CONFIG_ARCH_SOCLIB
     92
     93# Processor types
     94CONFIG_CPU_ARM
     95CONFIG_CPU_ARM_SOCLIB
     96
     97# Mutek features
     98CONFIG_PTHREAD
     99CONFIG_MUTEK_CONSOLE
     100
     101CONFIG_LIBC_STREAM
     102CONFIG_LIBC_STREAM_STD
     103
     104CONFIG_HEXO_INTTYPES_DEPRECATED undefined
     105
     106# Device drivers
     107CONFIG_DRIVER_CHAR_SOCLIBTTY
     108CONFIG_DRIVER_ICU_SOCLIB
     109
     110# Code compilation options
     111CONFIG_COMPILE_DEBUG
     112CONFIG_COMPILE_OPTIMIZE 2
     113
     114# New source code module to be compiled
     115CONFIG_MODULES bc:%CONFIGPATH
     116}}}
     117
     118That's all, we finished porting our app !
     119
     120= Compiling and running =
     121
     122{{{
     123user@host … caba-vgmn-mutekh_tutorial $ make CONFIG=config_soclib_arm APP=/path/to/mutek_port/src MUTEKH_DIR=path/to/mutekh
     124
     125    LD o    .../caba-vgmn-mutekh_tutorial/mutekh/kernel-soclib-arm.o
     126    LD out  .../caba-vgmn-mutekh_tutorial/mutekh/kernel-soclib-arm.out
     127soclib-cc -P -p .../caba-vgmn-mutekh_tutorial/platform_desc  -o system.x
     128[-------------------------------------------------------------------------=] 0 left
     129user@host … caba-vgmn-mutekh_tutorial $ ./simulation.x
     130}}}