Open Ethernet Networking (OpEN) API Guide and Reference Manual  3.6.0.3
Compiling Applications with RPMs

In this section we discuss how to build applications that use the RPMs supplied by Broadcom.

Fake Roots

When building an application that uses an RPM (e.g. openssl), the application must be able to include those other package's header files and link with their libraries. To facilitate this, a fake root should be used that mimics the root of the target system (the switch) and which includes all header files and libraries.

Creating a fake root

To create a fake root we use the rpm command to install a binary module but change the default root location. The easiest way to do this in the Broadcom environment is to use the supplied crtarget.sh script. This installs all available RPMs into the specified fake root directory.

The crtarget.sh script is located in the rpms.<toolchain>.<cpu>-<version>/src/tools directory of the RPM tar ball. The crtarget.sh script should be executed in the directory where the binary RPMs were extracted.

The example below assumes that the rpms.brl_3.8.e500_v2-1.0.1.7.tar.bz2 tar ball is in use, and will install a fake root into the /tmp/myfakeroot directory. Note that the fake root must be installed into a subdirectory of /tmp since this location avoids any issues with file permissions. The script must be executed as the root user on the build machine where the tool chain was installed (not on the switch).

  unix% su
  # tar zxf rpms.brl_3.8.e500_v2-1.0.1.7.tar.bz2
  # cd rpms.brl_3.8.e500_v2-1.0.1.7/output/RPMS
  # ../../src/tools/crtarget.sh /tmp/myfakeroot yes brl_3.8.e500_v2
  Installing initial-1-4.brl_3.8.e500_v2.rpm to /tmp/myfakeroot
  Installing brcm-misc-1-4.brl_3.8.e500_v2.rpm to /tmp/myfakeroot
  ...
  Installing pam-1.1.1-10.1.el6.brl_3.8.e500_v2.rpm to /tmp/myfakeroot
  warning: %post(pam-1.1.1-10.1.el6.ppc) scriptlet failed, exit status 127
  Installing pam-devel-1.1.1-10.1.el6.brl_3.8.e500_v2.rpm to /tmp/myfakeroot
  # exit
  unix%

Note that any %post warnings can be ignored, since these are from scripts that expect to be executed on the target architecture (the switch).

For more information on the crtarget.sh parameters execute crtarget.sh -h.

Once the above has been executed, a /tmp/myfakeroot directory structure will be created. This directory will contain a bin, etc, mnt, sbin and var set of subdirectories which contain binaries, system configuration, includes/libraries etc.

Testing the Fake Root

To test the fake root you can create and build a simple application that uses one of the supplied packages. For example, the following creates a C application that uses the PAM package. This assumes the brl_3.8.e500_v2 tool chain is in use and on the path. If another tool chain is in use then change powerpc-broadcom-linux-gnuspe-gcc to the name of the compiler.

  unix% mkdir test
  unix% cd test
  unix% cat > test.c
  #include <security/pam_client.h>
  int main (int argc, char *argv[])
  {
    return 0;
  }
  unix% powerpc-broadcom-linux-gnuspe-gcc -O2 test.c \
  > -I /tmp/myfakeroot/mnt/fastpath/usr/include \
  > -L /tmp/myfakeroot/mnt/fastpath/usr/lib \
  > -lpam -lpam_misc
  unix%

If the fake root has been installed correctly then the above will compile without error. If the fake root is not installed correctly then the compile should fail with a missing header file error, or a missing library error, or some other compile error.

The above example is a simple case of when the fake root is required. More complex examples require more extensive compiler flags.

Compiling Applications with the Fake Root

The settings below illustrate the environment variables that are used to cross compile the RPMs that come with the OpEN ADK.

  export CFLAGS="-I$DIR_FAKEROOT/mnt/fastpath/usr/include -Wl,-rpath-link,$DIR_FAKEROOT/mnt/fastpath/usr/lib -L$DIR_FAKEROOT/mnt/fastpath/usr/lib"
  export CPPFLAGS="-I$DIR_FAKEROOT/mnt/fastpath/usr/include -Wl,-rpath-link,$DIR_FAKEROOT/mnt/fastpath/usr/lib"
  export LDFLAGS="-L$DIR_FAKEROOT/mnt/fastpath/usr/lib -Wl,-rpath-link,$DIR_FAKEROOT/mnt/fastpath/usr/lib"
  export SHARED_LDFLAGS=$LDFLAGS

Once the fake root has been created, your application should be compiled with these extra parameters so that it can access the header files and libraries of the RPMs. Note that you must install the RPMs on the switch before your application can run.