summaryrefslogtreecommitdiff
path: root/doc/source/building.rst
blob: 6aed7074eb8327bf62f143bb359932805081c54f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Building the eCos kernel and applications
=========================================

This chapter describes how to build an eCos kernel and compile eCos applications for Colibri VF61.

The build process was tested on the Gentoo, Debian, Ubuntu and Mint Linux distributions.
The procedures described here should also work on other systems, but if you find any way to improve this manual with respect to tested platforms, please e-mail us at contact@antmicro.com.

.. _prerequisites:

Prerequisites
-------------

Toolchain
~~~~~~~~~

This port of eCos was prepared using a pre-built standard eCos toolchain, which can be obtained e.g. from the `GWDG FTP server <ftp://ftp.gwdg.de/pub/misc/sources.redhat.com/ecos/gnutools/i386linux/test/>`_.

.. code-block:: bash
   
   wget ftp://ftp.gwdg.de/pub/misc/sources.redhat.com/ecos/gnutools/i386linux/test/\
   ecos-gnutools-arm-eabi-20120623.i386linux.tar.bz2
   tar xjvf ecos-gnutools-arm-eabi-20120623.i386linux.tar.bz2 
	
Alternatively it is possible to compile eCos software using self-built toolchains as described `on the eCos website <http://ecos.sourceware.org/getstart.html>`_.

To compile eCos and eCos applications, the toolchain's :file:`bin` directory has to be included in the PATH variable.
The proper availability of the toolchain can be checked by finding out if ``arm-eabi-gcc`` is available from the shell.

:program:`ecosconfig`
~~~~~~~~~~~~~~~~~~~~~

The :program:`ecosconfig` tool, available from the `eCosCentric website <http://www.ecoscentric.com/snapshots/ecosconfig-100305.bz2>`_, is used to generate the build tree from the main repository and is a mandatory requirement.
:program:`ecosconfig` requires the tcl compiler to work. 

.. topic:: Installing tcl on Debian-based distributions

   .. code-block:: bash

      sudo apt-get install tcl8.5 # use sudo emerge dev-lang/tcl for Gentoo

Now you can download and use :program:`ecosconfig`. You also need to make :program:`ecosconfig` executable after downloading and extracting it from the archive. It is also a good idea to make it available system-wide by moving it to ``/usr/local/bin``.

.. topic:: Installing ecosconfig

   .. code-block:: bash

      wget http://www.ecoscentric.com/snapshots/ecosconfig-100305.bz2
      bunzip2 ecosconfig-100305.bz2
      chmod +x ecosconfig-100305
      sudo mv ecosconfig-100305 /usr/local/bin/ecosconfig

.. warning::

   :program:`ecosconfig` is a 32bit application, thus if you are using a 64bit OS you have to provide 32bit run-time libraries for compatibility. In a Debian-based Linux distributions these could be installed using the command ``sudo apt-get install ia32-libs``.

.. note::

   The output of :program:`ecosconfig` are :abbr:`.ecc (eCos Configuration)` files which are in essence ``tcl`` scripts storing all the information on what elements will be included in the system image and how they will be configured.
   
.. note::
   
   A `handbook on ecosconfig <http://ecos.sourceware.org/docs-3.0/user-guide/using-ecosconfig-on-linux.html>`_ exists to help in the manual creation of ``.ecc`` files.
   Also, if you want to create custom eCos configuration files, see :doc:`appendix-a`.

Source code
-----------

The source of the port can be downloaded by using the following command:

.. topic:: Downloading the Colibri VF61 eCos source

   .. code-block:: bash

      git clone https://github.com/mgielda/ecos-colibri-vf61.git
      
Preparing an ``.ecc`` file
--------------------------

The actual configuration of the eCos system is maintained and modified through :program:`ecosconfig`.
The following commands will prepare a sample ``.ecc`` file for a kernel with default settings.

.. topic:: Generating the kernel ecc file from scratch

   .. code-block:: bash

      export ECOS_REPOSITORY="{path/to/ecos-colibri-vf61/ecos}/packages"  # modify
      # Create ecos.ecc file based on Colibri VF61 default template
      ecosconfig new col_vf61 default

You now have a ``ecos.ecc`` file that holds the default eCos configuration for Colibri VF61.
The file can be further edited manually with a text editor and/or :program:`ecosconfig` or graphically using :program:`configtool` (see :doc:`appendix-a`), but at this moment it is already enough to compile a sample eCos kernel.

.. _build-kernel:

Building the kernel
-------------------

The eCos kernel is built in two stages:

* first, a so-called *build tree* is generated from the eCos sources by :program:`ecosconfig`.
  The build tree is customized for your build as configured in the ``.ecc`` file used.
  It is best to generate the build tree in a separate directory (here ``build-tree``). 
* then, the source files are compiled

A short shell script is proposed to make the compilation process easier:

.. topic:: Building the eCos kernel

   .. code-block:: bash

      export ECOS_REPOSITORY="{path/to/ecos-colibri-vf61/ecos}/packages"  # modify
      export PATH="{path/to/toolchain}/bin:$PATH"                         # modify

      mkdir -p build-tree
      rm -rf build-tree/*
      cd build-tree

      ecosconfig --config={path/to}/ecos.ecc tree                         # modify
      make
      cd ..

The resulting kernel files can be found in :file:`build-tree/install/lib`.

Application
-----------

With a compiled kernel files in the :file:`build-tree/install/lib` directory (see :ref:`build-kernel`), a user space eCos application can be compiled and linked to it.

A listing for a short sample application (taken from :file:`ecos-colibri-vf61/ecos/examples/hello.c`) is given below.

.. topic:: hello.c - sample application

   .. code-block:: c

      #include <stdio.h>

      int main(void)
      {
          printf("Hello, eCos world!\r\n");
          return 0;
      }

You can compile an eCos program with a procedure similar to the following listing (which you can save for reuse, for example as ``make.sh``):

.. topic:: Building a user space application

   .. code-block:: bash

      export PATH="{path/to/toolchain}/bin:$PATH"                         # modify

      # Set compiler options
      OPT="-Wall -Wpointer-arith -Wstrict-prototypes -Wundef  \
           -Wno-write-strings -mthumb -g -O2 -fdata-sections  \
           -ffunction-sections -fno-exceptions -nostdlib      \
           -mcpu=cortex-m4"

      # Set path to eCos kernel
      BTPATH="{path/to/ecos/build-tree}"                                  # modify

      # Do compilation and link your application with kernel
      arm-eabi-gcc -g -I./ -g -I${BTPATH}/install/include hello.c \
                   -L${BTPATH}/install/lib -Ttarget.ld ${OPT}

      # Use objcopy to generate a binary
      arm-eabi-objcopy -O binary a.out hello.bin