Heterogeneity of Computing Environments Using Cross-Compilation

With the advent of open-source software and the acceptance of these solutions in creating complex systems, the ability to develop applications that can run seamlessly across multiple hardware platforms becomes inherently important. There is a constant need to develop the software on one architecture but have the capability to execute these on other target architectures. One common technique to achieve this is cross-compilation of the application for the target architecture. 

Cross-compilation is significant in embedded systems where the intent is to run applications on specialized hardware like ARM and PowerPC boards. These systems are resource-constrained and hence a direct compilation is not an option. Thus, developers will leverage the common x86 architecture as a host and use toolchains specific to the target hardware, generating binaries compatible with the target hardware. 

This article covers one such case study where cross-compilation of an open-source package was done for PowerPC. The article will cover the details of the tools and toolchains leveraged and a step-by-step tutorial on how cross-compilation was achieved for this architecture. 

The Problem Statement  

Given a target board with PowerPC architecture, the intent was to add L3 routing capabilities to this board. For this purpose, a popular open-source routing protocol suite, FRRouting (FRR), was considered. 

FRR is a protocol suite that enables any Linux machine to behave like a full-fledged router. It is packaged for amd64, arm64, armhf, and i386 but not for PowerPC. This necessitated FRR’s cross-compilation.

Build host target host

CPU Arch 

x86_64 

Powerpc(32-bit) 

Operating System 

Ubuntu 18.4 

QorIQ SDK 

CPU 

12 

2 (e5500) 

RAM 

12GB 

1GB 

Table 1Difference in Build and Target platform

The Cross-Compilation Journey

There are two major stages in cross-compilation: 

Configuring the Build Environment and Pre-Compiled Toolchain

1. Install the required build tools in the environment. Common build tools include autoconf, make, cmake, build-essentials, pkg-config, libtool, etc. 

2. Set up the pre-compiled toolchain specific to the target host environment. CPU/Board vendors provide their own architecture-specific toolchains. The target board-specific toolchain was obtained from the vendor’s product website. 

3. The toolchain comes with an environment file, which is used to set the environment variables like CC, GCC, PKG_CONFIG_PATH, etc, that are required for cross-compilation. Edit the environment file /opt/fsl-qoriq/2.0/environment-setup-ppce5500-fsl-linux and update the path of variables with respect to the path of the toolchain directory. 

Shell

 

Resolving Dependencies in Pre-Compiled Toolchain

Each software has its own set of dependencies(tools/libraries), which needs to be resolved before the cross-compilation.

Depending on the package availability of these tools/libraries in the target architecture, there are two options to resolve them. Either install them directly from available packages or cross-compile them as well from the source.

Specific to the FRR compilation, libpcre2, libyang, clippy, libelf, and json-c libraries need to be built from the source. Aside from these, protobuf and libcap library packages were available for PPC(PowerPC) arch, which can be installed directly into the toolchain.

1. Installing Libraries from Packages

Library packages available for the target architecture can be installed into the toolchain sysroot using two ways:

  1. The first way uses Ubuntu/Debian-based dpkg-debtool for directly installing Debian packages as mentioned below: 
    Shell

     

    Note:

    • Download all dependency packages and install them in order.
    • Library packages may get installed to different directory structure. Copy those library files to the correct directories as per the toolchain.
  2. In the second way debian/rpm packages are extracted and manually placed to the toolchain directory path as mentioned below:
    1. For extracting debian package, use ar and tartools as mentioned below:
      Plain Text

       

      Note: This method is useful for systems without dpkg-deb support.

    2. For rpm package extraction, use rpm2cpiotool as the command below:
      Plain Text

       

    3. Package extraction and file placement with libcap example:

      Shell

       

    4. To verify if the packages/libraries got installed successfully, run the command below:

      Shell

       

      Note: Install pkg-config if not already installed.

2. Cross-Compiling Libraries

Library packages are not available for the target arch and are compiled from the source. Before starting compilation, load the environment file packaged with the toolchain to set all the necessary parameters required for cross-compilation.

Shell

 

Follow the compilation steps given in the library’s README file. Additionally, set the below parameters in the build procedure steps:

  1. Set --host parameter when running ./configurescript
    Shell

     

    Note:

    • <target_host_parameter> is the system for which the library/tool is being built. It can be found in the environment file of the toolchain. It is a common prefix found in $CC, $LD, etc.
    • There will be two types of dependent libraries. One is only required for the compilation process, and the other is a dependency requirement for execution at the target host. Set the --host parameter accordingly.
  2. When using “make install” for building dependent libraries, set DESTDIR to the toolchain sysroot directory.
    Shell

     

Conclusion

The differences in system architectures, libraries, dependencies, and toolchains make cross-compilation a complex technique to execute. To ease out complexities, this article uncovers the phases of cross-compilation. FRR and PowerPC were taken as examples for the desired software and the target hardware, respectively. However, the steps covered in this article provide a reasonable strategy for the cross-compilation of any software on a specific hardware. The environment settings, the toolchain, and the dependencies will vary based on the requirements.

Source:
https://dzone.com/articles/heterogeneity-computing-environments-cross-compilation