Difference between revisions of "CmakeEcos"

From KitwarePublic
Jump to navigationJump to search
(Replace content with link to new CMake community wiki)
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
= How to use CMake to cross compile software for eCos =

== Install the eCos host tools ==
This page has moved [https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/cross_compiling/Ecos here].
To build eCos software, you need the host tools for eCos, ecosconfig and optionally configtool. Make sure
both ecosconfig and configtool can be found via the PATH.
There are different way how to get them.
* For some Linux distributions there exist ready-to-use packages, which you can simply install. E.g. for Ubuntu this
is done using "apt-get install ecosconfig".
* Download and install a recent prebuilt version of the hosttools provided by eCosCtentric. You can find it at http://www.ecoscentric.com/devzone/configtool.shtml
* Download and install the binary ecos 2.0 releases you can find at ftp://ecos.sourceware.org/pub/ecos/releases/ecos-2.0 . Ignore the actual eCos sources in the package and use only configtool and ecosconfig which you can find in ecos-2.0/tools/bin/ in the package.
* Download the sources from cvs and build it yourself. You can find instructions at  http://ecos.sourceware.org/anoncvs.html
and at http://www.ecoscentric.com/devzone/configtool.shtml .
== Install a toolchain for building eCos applications ==
You need to install a suitable cross compiling toolchain to be able to build software for eCos. You can download them either from ftp://ecos.sourceware.org/pub/ecos/gnutools or build it yourself following the instructions you can find at http://ecos.sourceware.org/build-toolchain.html . Install the toolchain to any location you like,
e.g. $HOME/ecostoolchains/ . Make sure the compiler is available via PATH, e.g. EXPORT PATH=$HOME/ecostoolchains/arm-elf/bin:$PATH.
== Get the eCos sources and set ECOS_REPOSITORY ==
eCos release 2.0 is very old, it is recommended to use current anonymous cvs.
You can find instructions here:
If you can't access cvs you can also download a weekly snapshot of cvs provided by eCosCentric: http://www.ecoscentric.com/devzone/snapshots.shtml
Once you have the eCos sources installed somewhere on your development machine, e.g. in $HOME/ecos, set the
ECOS_REPOSITORY environment variable. This is required for running ecosconfig and configtool. It has to point to the directory
where the file ecos.db is located, e.g. $HOME/ecos/packages/ .
== Build an eCos ==
eCos is a configurable operating system, so you have to configure the system you want to use.
Here's a simple example for the ARM integrator board:
~/ $ cd src/ecos-arm-integrator
~/src/ecos-arm-integrator/ $ ecosconfig new integrator_arm9 default
~/src/ecos-arm-integrator/ $ ecosconfig tree
~/src/ecos-arm-integrator/ $ make
~/src/ecos-arm-integrator/ $ ls install/
include  lib
~/src/ecos-arm-integrator/ $ ls install/lib
extras.o  libextras.a  libtarget.a  target.ld  vectors.o
The first step will create an ecos.ecc file, which contains the configuration of the operating system. The second step
uses this information to generate makefiles, which you use to build in the final make step. Once make has finished, you will
find an include/ and a lib/ directory created in the install/ subdirectory. This is the target environment which will
be used for compiling your software for this eCos.
== Write a CMake toolchain file ==
For CMake to be able to crosscompile software, it requires you to write a toolchain file, which tells CMake
some information about the toolchain.
With the examples used above it will look like:
# the name of the target operating system
# which compiler to use
# since the compiler can't build a simple program by default without knowing
# where the eCos target library is, the FORCE macros have to be used
# use arm-elf-gcc for C, the compiler id is "GNU", the sizeof(void*) is 4
CMAKE_FORCE_C_COMPILER(/home/alex/src/ecostoolchains/arm-elf/bin/arm-elf-gcc GNU 4)
# use arm-elf-g++ for C++, the compiler id is "GNU", the sizeof(void*) is 4
CMAKE_FORCE_CXX_COMPILER(/home/alex/src/ecostoolchains/arm-elf/bin/arm-elf-g++ GNU)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH  /home/alex/src/ecos-arm-integrator/install /home/alex/ecos-arm-install )
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
Save this file as Toolchain-eCos-arm-elf.cmake to some location where you will put
all your toolchain files, e.g. $HOME.
== Build the software for eCos ==
Let's say you have the classical hello world software with a CMake based buildsystem and want to build this for the eCos
you built above.
include <stdio.h>
int main()
  printf("Hello world\n");
  return 0;
ADD_EXECUTABLE(hello main.c)
Then run CMake on it to generate the buildfiles, the important point is that you tell it to use the toochain file you just wrote:
~/src/helloworld/ $ mkdir build
~/src/helloworld/ $ cd build
~/src/helloworld/build/ $ cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-eCos-arm-elf.cmake -DCMAKE_INSTALL_PREFIX=/home/alex/ecos-arm-install ..
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/src/helloworld/build
~/src/helloworld/build/ $ make
Scanning dependencies of target hello
[100%] Building C object CMakeFiles/hello.dir/main.o
Linking C executable hello.elf
[100%] Built target hello
~/src/helloworld/build/ $ make install
-- Installing /home/alex/ecos-arm-install/bin/hello
So that's all. It actually doesn't matter whether it's just a "hello world" or some complex piece of software,
the only difference is the usage of the toolchain file. If the software has all required configure checks, it should just
build also for eCos.

Latest revision as of 15:41, 30 April 2018

The CMake community Wiki has moved to the Kitware GitLab Instance.

This page has moved here.