Building uClibc Print

 

The Emcraft Linux distribution provides the uClibc library prebuilt for the Cortex-M architecture. You can just link your applications with the provided library and never worry about having to build the library from scratch. In the installation tree, the library is available in the following directory relative to the top of the installation:

-bash-3.2$ pwd
/home/vlad/test/linux-cortexm-2.0.0
-bash-3.2$ cd A2F/uclibc/
-bash-3.2$

In some situations however, our customers asks us how to rebuild the library. Typically, they want to do that in order to enable some additional functionality available from the library but not included in the prebuilt configuration.

This application note explains how to build the uClibc library.

First step is to activate the cross development environment on the host. This is done by running the ACTIVATE.sh script from the top of the installation tree:

-bash-3.2$ pwd
/home/vlad/test/linux-cortexm-2.0.0
-bash-3.2$ . ./ACTIVATE.sh
-bash-3.2$

Go to the uClibc directory:

-bash-3.2$ cd A2F/uclibc/
-bash-3.2$

Copy the default configuration file to the working config that will be used by the build procedure:

-bash-3.2$ cp dot_config_pthreads .config
-bash-3.2$

Note: Users of the Emcraft A2F-SOM please use dot_config_pthreads-no-ldrex.

Edit the config file to provide the correct path to the header files. To do that, search for KRNL_HDR and replace it with ../root/usr/include/:

-bash-3.2$ vi .config
...
# UCLIBC_HAS_FENV is not set
KERNEL_HEADERS="../root/usr/include/"
UCLIBC_UCLINUX_BROKEN_MUNMAP=y
...

Proceed to update the library configuration file to your liking. The example below enables the RPC related build-time options in the configuration:

...
# UCLIBC_HAS_IPV6 is not set
UCLIBC_HAS_RPC=y
UCLIBC_HAS_FULL_RPC=y
UCLIBC_HAS_REENTRANT_RPC=y
# UCLIBC_USE_NETLINK is not set
...

Remember to save your edits when exiting the editor.

Build the internal configuration file that will be used to by the library build procedure:

-bash-3.2$ make -s ARCH_CFLAGS= 'CPU_CFLAGS=-mthumb -march=armv7 -mfix-cortex-m3-ldrd' oldconfig
#
# configuration written to ./.config
#
-bash-3.2$

Build the updated library. Ignore the compiler warnings:

-bash-3.2$ make ARCH_CFLAGS= 'CPU_CFLAGS=-mthumb -march=armv7 -mfix-cortex-m3-ldrd' -j2 -s
...
-bash-3.2$

Install the newly build library wherever you would like to install it. You can of course install it to the same directory where it is installed in the Emcraft distribution, as shown in the below command:

-bash-3.2$ make ARCH_CFLAGS= 'CPU_CFLAGS=-mthumb -march=armv7 -mfix-cortex-m3-ldrd' -s PREFIX=$INSTALL_ROOT/A2F/root install
-bash-3.2$

If you would like to preserve the original library and install the updated library to some other directory, specify the target directory with PREFIX in the above command.

Whenever you have installed the updated library, provide the correct path to it with the -L and -I compiler flags when building your application. For instance, for the installation command above, you need to specify the following when building your application:

-bash-3.2$ arm-uclinuxeabi-gcc -o test test.c -mcpu=cortex-m3 -mthumb -I$INSTALL_ROOT/A2F/root/usr/include -L$INSTALL_ROOT/A2F/root/usr/lib
-bash-3.2$