Setting up an MSYS environment and cross-compiler

This chapter provides instructions on how to set up an MSYS environment with a cross-compiler that is appropriate for the PCIe hardware, and configuring the environment to correctly build the FM binaries.

The process includes these general steps:

1.Download the required binaries and source code (See Download MinGW and the toolchain source code).

2.Build the cross-compiler (See Build and install the cross-compiler).

3.Add the ProtectServer paths to the MSYS environment (See Set the MSYS environment to include the FMDIR and CPROVDIR directories).

Download MinGW and the toolchain source code

Download the following files:

Filename Source file Location
binutils-2.26.tar.gz binutils 2.26 http://ftp.gnu.org/gnu/binutils/
gcc-5.3.0.tar.gz gcc 5.3.0 http://ftp.gnu.org/gnu/gcc/gcc-5.3.0/
newlib-2.4.0.tar.gz newlib 2.4.0

https://sourceware.org/newlib/

Follow the "Download" link and find the source snapshots in the newlib ftp directory.

Extract the binutils, gcc and newlib source files into the same folder. This will be referred to as the %SRC% folder. Ensure that the %SRC% path has no spaces.

Go to: http://www.mingw.org/ or https://sourceforge.net/projects/mingw/ to download MinGW.

Install MinGW in the default directory (C:\MinGW) or a directory of your choice. This directory will be referred to as %MINGW_HOME%.

NOTE   If you install MinGW in another directory, ensure that the path does not contain spaces. For the automated scripts to work, the %MINGW_HOME% environment variable must also be set to the install directory.

Build and install the cross-compiler

There are two options for this process:

>run the provided script that builds and installs the cross-compiler and sets the MinGW environment, or

>complete the steps manually by following the instructions below.

Automated cross-compiler build

1.Copy the files crossc.cmd and crossgcc.mak from C:\Program Files\SafeNet\Protect Toolkit 5\FM SDK\gcc_fm\ into the %SRC% folder.

2.Run crossc.cmd from a command prompt.

NOTE   If you installed MinGW in another directory other than the default (C:\MinGW), set the %MINGW_HOME% environment variable to that path before running the script.

Manual cross-compiler build

1.Using either the MinGW GUI or the CLI, install the following packages:

mingw32-base

mingw32-gcc-g++

mingw-developer-toolkit

mpc-dev

mpfr-dev

gmp-dev

Using the CLI:

%MINGW_HOME%\bin\mingw-get install mingw32-base mingw32-gcc-g++ mingw-developer-toolkit mpc-dev mpfr-dev gmp-dev

2.Go to the %MINGW_HOME%\msys\1.0\bin directory and run bash -c 'mount --replace "%MINGW_HOME%" /mingw'.

cd %MINGW_HOME%\msys\1.0\bin

bash -c 'mount --replace "%MINGW_HOME%" /mingw'

3.Open an MSYS shell. You might want to create a shortcut on the desktop for easy access. This shell will be used later on to compile the FM binaries.

%MINGW_HOME%\msys\1.0\msys.bat

4.Go to the %SRC% folder.

cd $SRC

5.Set up the build environment.

export TARGET=powerpc-eabi

export PREFIX=/mingw

6.Build the binaries by executing the following msys commands, in this order:

a.Build binutils:

tar xvf binutils-2.26.tar.gz

mkdir binutils_build

cd binutils_build

../binutils-2.26/configure --prefix=$PREFIX --target=$TARGET --disable-nls --disable-shared --with-gcc --with-gnu-as --with-gnu-ld --with-stabs --disable-multilib --enable-thmake all-gccreads

make all

make install

cd ..

b.Build gcc - C only:

tar xvf gcc-5.3.0.tar.gz

mkdir gcc_build

cd gcc_build

../gcc-5.3.0/configure --target=$TARGET --prefix=$PREFIX --with-cpu=440fp --enable-languages=c,c++ --disable-multilib --with-gcc --with-gnu-ld --with-gnu-as --with-stabs --disable-shared --enable-threads --disable-nls --with-newlib

make all-gcc

make install-gcc

cd ..

c.Build newlib:

tar xvf newlib-2.4.0.tar.gz

mkdir newlib_build

cd newlib_build

../newlib-2.4.0/configure --target=$TARGET --prefix=$PREFIX

make

make install

cd ..

d.Build gcc - complete:

cd gcc_build

make all

make install

cd ..

Set the MSYS environment to include the FMDIR and CPROVDIR directories

NOTE   If you installed MinGW in another directory other than the default (C:\MinGW), set the %MINGW_HOME% environment variable to the install directory you selected.

In the %FMDIR%\bin directory, run the setmsysenv.cmd script. This will add the environment variables CPROVDIR and FMDIR to the MSYS environment, allowing you to compile the FM binaries. This only needs to be done once.