Skip to content

Compiling for LEON targets

mmunoz-gmv edited this page Aug 28, 2018 · 2 revisions

Compiler and target support

The ESROCOS framework supports the development of robotics applications for LEON targets using RTEMS or the AIR hypervisor. The reference LEON target supported by the framework is the GR740 board from Cobham Gaisler.

ESROCOS applications are modelled using TASTE, which provides a hardware library with several target processors, including the GR740.

AIR is based on RTEMS and uses the same GCC compiler, provided with RTEMS, to build applications. The version supported by ESROCOS is RTEMS 5.1, which is installed by TASTE.

NOTE: Currently the RTEMS 5.1 version is provided by the development branch of the TASTE framework "TASTE-9.1", which will become the baseline TASTE installation in the near future.

Building applications and libraries

Building TASTE applications

TASTE applications targetting the GR740 board should use the following processors in the Deployment View:

  • gr704.rtems51_posix for using RTEMS as RTOS
  • leon3.AIR for using the AIR hypervisor

Once the processor is selected and the desired software functions are allocated to the processor, the TASTE build process takes care of everything and produces a binary that can be loaded in the target board.

The user of ESROCOS can create TASTE models into the workspace. Autoproj builds the models using the TASTE build process. The product of the build may include a combination of executables and scripts for different targets (Linux applications, Linux GUIs, RTEMS, etc.), according to the architecture of the application.

Building libraries

ESROCOS provides a set of reusable software components that can be used to build applications, and provides the means for the final user to create additional reusable components. These components can be TASTE functions or conventional software libraries. In the case of TASTE functions, the implementation is generally platform-agnostic, and it is the Deployment View and the build process that determine the target. Conventional software libraries, however, need to be prepared in order to build for the LEON platform. ESROCOS provides support for this.

The ESROCOS framework uses CMake to build C and C++ libraries. In order to target the RTEMS/LEON platform, the framework provides a specific CMake toolchain definition within the tools/config package. The toolchain to be used by CMake is set using the CMAKE_TOOLCHAIN_FILE variable. The esrocos.core package set includes a Ruby function that can be used in autoproj scripts to manage the toolchain file.

module Esrocos
    ...
    def Esrocos.build_rtems_gailser(pkg, target='leon3')
        ...
    end
end

Where pkg is an autoproj cmake_package and target is a string identifying the target board. The following values are recognized: leon2, at697f, erc32, leon3, leon3std, leon3_sf, leon3_smp, leon3_mp, gr712rc, gr740, gr740mp, ut699, ut700, custom or other. Refer to the Gaisler RCC documentation for details on the different targets.

The Esrocos.build_rtems_gaisler method does the following:

  • Define the CMAKE_TOOLCHAIN_FILE variable (used by CMake) for building the package
  • Define the RTEMS_TARGET variable with the target string passed as an argument to the method
  • Use the directory build_<RTEMS_TARGET> as build directory for the package

An example of a cmake_package enabled to build for RTEMS/LEON is presented below:

cmake_package "types/base_support" do |pkg|
    if(ENV.has_key?('ESROCOS_RTEMS_TARGET'))
        Esrocos.build_rtems_gailser(pkg, ENV['ESROCOS_RTEMS_TARGET'])
    end
end

When building this package, autoproj will check if the environment variable ESROCOS_RTEMS_TARGET is defined and enable the RTEMS build. Otherwise, the native build for Linux is used.

Note that CMake can only build a package for one target at a time. In order to build a package both for Linux and RTEMS, it is necessary to run CMake (or amake) twice, one with ESROCOS_RTEMS_TARGET set and one without.

Once the build for RTEMS is enabled, CMake will manage automatically the compiler selection and the default built options. Nevertheless, the CMakeLists.txt scripts must handle the following aspects:

  • Some software components may depend on libraries or capabilities that are not available in the target platform, and must be explicitly excluded from the build
  • The target platform does not support shared libraries, so these targets must be excluded from the build
  • Some dependencies, include paths, etc. may differ between platforms, and must be managed
  • Different install locations must be selected for Linux and other target platforms, in order to avoid that Linux and RTEMS binaries are mixed in the same directories, or that the build products for one platform are overwritten when switching the target

Within the CMake scripts, the following variables are available to manage the platform-dependent aspects of the build:

  • CMAKE_CROSSCOMPILING is an internal variable of CMake that is set to TRUE whenever CMake is using a toolchain file for cross-compilation
  • RTEMS_TARGET is defined by the Esrocos.build_rtems_gailser method and can be used to build the paths to install the build products

The following conventions are advised:

  • Use the Esrocos.build_rtems_gailser as shown above in order to select the build target using the ESROCOS_RTEMS_TARGET environment variable
  • Install the binary products of the builds for RTEMS in the folders install/<RTEMS_TARGET>/lib or install/<RTEMS_TARGET>/bin
  • Install include files and other elements that are platform-agnostic to their regular location, e.g., install/include

Once a CMake package is prepared to build for RTEMS, it should be built and installed as follows:

$ export ESROCOS_RTEMS_TARGET=gr740
$ amake <PACKAGE>

And to build it again for Linux:

$ unset ESROCOS_RTEMS_TARGET
$ amake <PACKAGE>

Clone this wiki locally