Building Applications

Once you have RTEMS/GeSys up and running, you want to create and run your own applications on the target. Note that rebuilding RTEMS or GeSys is not necessary (that's why it's called a 'generic system').

Creating and Running Non-EPICS Applications

Examples for simple applications can be found in the /afs/slac/package/rtems/4.6.2/examples directory. Creating 'hello_world' is as simple as this:
  1. Create a directory and copy a Makefile template there. Within the framework of the CD, you should use a SSRL-style Makefile, not one that comes with plain RTEMS. The SSRL Makefiles have some extra features.
    cd /afs/slac/package/rtems/4.6.2/examples/hello_world
    cp /afs/slac/package/rtems/4.6.2/target/ssrlApps/config/Makefile.leaf Makefile

    Next, you want to fill-in the template; look for 'xxx' and substitute your values.

  2. Write your source code.
  3. Prior to compiling, you must set the following environment variables
    setenv RTEMS_MAKEFILE_PATH /afs/slac/package/rtems/4.6.2/target/ssrlApps/config
    setenv RTEMS_BSP <your_bsp>
    setenv RTEMS_SITE_DIR <top_of_where_you_want_to_install>

    RTEMS_SITE_DIR defines where your created code will be installed. (Consult the bottom of the Makefile for details - RTEMS_SITE_INSTALLDIR maps to RTEMS_SITE_DIR/$(RTEMS_CPU)-rtems/). Your loadable module will be installed in RTEMS_SITE_DIR/<cpu>-rtems/bin or RTEMS_SITE_DIR/<cpu>-rtems/<bsp>/bin (depending on your makefile variable settings).

  4. Run 'make install';
  5. Assuming your RTEMS_SITE_DIR is /usr/local/rtems and it is exported to the target issue the following commands on the target:
    Cexp> nfsMount(<nfshost>,"/usr/local/rtems","/site")
    Trying to mount xxx.xxx.xxx.xxx:/usr/local/rtems on /mnt
    0x00000000(0)
    Cexp> hwmod=cexpModuleLoad("/site/powerpc-rtems/bin/hello_world.obj")
    0x00394d2c (3755308)
    Cexp> hello_world("World")
    HELLO World
    0x0000000c (12)
    Cexp> cexpModuleUnload(hwmod)
    0x00000000
    Cexp> unmount("/site")0x00000000

The examples were created with RTEMS_SITE_DIR set to /afs/slac/package/rtems/4.6.2/target/ssrlApps, i.e., to load and run the precompiled examples substitute '/usr/local/rtems' by '/afs/slac/package/rtems/4.6.2/target/ssrlApps' in step 5.

I forgot to mention that you should add '/afs/slac/package/rtems/4.6.2/host/i386_linux24/bin' to your shell's PATH to ensure that all tools are found. Note that you should always use the Makefiles to compile code. Never use the cross compiler directly (although on certain CPUs you might get away with it). The reason being that gcc supports various CPU variants and unless your BSP is using the default one you might generate incompatible code. The RTEMS/SSRL Makefiles take care of selecting the proper compiler options for your BSP.

Creating and Running EPICS Applications

The standard EPICS 'exampleApp' can be found under /afs/slac/package/rtems/4.6.2/examples/epics. Here's how this is created. It's ridiculously simple:

  1. Make a directory and chdir there
  2. setenv EPICS_HOST_ARCH linux-x86
  3. Run

    /afs/slac/package/rtems/4.6.2/epics-3.14.6/base/bin/linux-x86/makeBaseApp.pl -t example example
    /afs/slac/package/rtems/4.6.2/epics-3.14.6/base/bin/linux-x86/makeBaseApp.pl -i -t example example

  4. You need to edit 'configure/CONFIG' to limit your CROSS_COMPILER_TARGET_ARCHS to your BSP(s) e.g.,
    CROSS_COMPILER_TARGET_ARCHS=RTEMS-pc586

    This step is necessary because not all pre-built target BSPs are distributed on the CD (RTEMS-svgm is not included by default).

    You can also define an INSTALL_LOCATION in this file.

  5. If you are not using the standard mount point '/afs/slac/package/rtems/4.6.2', you need to read this.
  6. Run 'make'
  7. Off-the shelf EPICS is not (yet) supporting run-time loading under RTEMS. Therefore, the example startup script needs to be modified. A few tweaks to the makefile system (consult configure/os/CONFIG.Common.RTEMS and CONFIG_SITE.Common.RTEMS) were also necessary (consult the patch for details).

    At the top of iocBoot/iocexample/st.cmd I added

    chdir("../../")
    cexpModuleLoad("bin/RTEMS-<your_bsp>/example.obj")

    You're now all set to run the example.

  8. On the target (assuming a NFS server exports '/afs/slac/package/rtems/4.6.2' or your example 'TOP' directory if you build it yourself), issue:

    Cexp>nfsMount(<nfshost>,"/afs/slac/package/rtems/4.6.2","/opt")
    Trying to mount xxx.xxx.xxx.xxx:/afs/slac/package/rtems/4.6.2 on /opt
    0x00000000 (0)
    Cexp> chdir("/opt/examples/epics/iocBoot/iocexample/")
    0x00000000 (0)
    Cexp> < st.cmd-<your-bsp>

    For the demo, there are BSP specific versions of the startup script, e.g., st.cmd-mvme2307, (making sure the correct binary module is loaded). These simply define the correct path to the binary and then include st.cmd.

  9. Your IOC should be up and running at this point, hence you can test from the host:
    setenv PATH /afs/slac/package/rtems/4.6.2/epics/base/bin/linux-x86:$PATH
    caget till:aiExample

    (If using your own build of the exampleApp, you have to substitute your user name, of course).

Links