Cross Compiler Build Instructions

Holds topics that document the NAS box's features and any related procedures. Stuff in here should eventually make it into a specification or the user guide.
Post Reply
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Cross Compiler Build Instructions

Post by hamishmb »

I started setting up a cross compiler for the NAS today, so we can try to build custom applications for it.

Download Link

You can download a pre-configured, minimal virtual machine image with the cross-compiler ready to use from https://wmtprojectsforum.altervista.org ... NAS%20Box/. You need to extract the archive, and then import the OVA file. The archive is very highly compressed, so this may take a while. Attached is the OVF file containing the machine spec, in case it is used again later when re-compressing this machine. Instructions to re-produce this virtual machine are below.

Documentation link: http://crosstool-ng.github.io/docs/.

For this purpose, I decided to use crosstool-NG: http://crosstool-ng.github.io/. The documentation is a bit light, so I have added some notes here to remind me/anyone else how to set it up if we need an aid memoir.

Environment

The required version of crosstool-ng will not build on anything newer than Ubuntu 14.04. As a result, I have set up an Ubuntu 14.04 Virtual Machine. This was set up using the following instructions.

An internet connection will be required to create the cross-compilation toolchain, as well as plenty of RAM and disk space. I allocated 4GB of RAM and 30GB of disk space to my VM, which seems to be fine.

Create the user "wmt" during the installation. Make sure all available updates are applied after installation.

Dependencies

You need to install the following dependencies:

Code: Select all

sudo apt install -y subversion gcc g++ gcj-4.8 gperf bison cvs flex expat texinfo help2man make libncurses5-dev python3-dev autoconf automake libtool gawk wget bzip2 xz-utils unzip patch libstdc++6
These can be found in the docker configurations inside the "testing" folder in the tarball (in newer versions of crosstool-ng).

Downloading the cross compiler

The latest version of crosstool-ng does not support the glibc, binutils, and kernel versions the NAS box uses. However, v1.17.0 is fairly recent, and produces a newer version of GCC (4.7.2) than the cross compilation tools provided by D-Link.

These instructions are aimed at configuring crosstool-ng v1.17.0 to build for armv5te.

To start with, download crosstool-ng 1.17.0 from https://wmtprojectsforum.altervista.org ... /NAS%20Box or http://crosstool-ng.org/download/crosstool-ng/ and verify the download with the SHA-512 sum (available from same location):

Code: Select all

sha512sum -c /path/to/checksum-file
Next, extract the tarball:

Code: Select all

tar -xf /path/to/tarball
Configuring the cross compiler

I then followed "The Hacker's Way" for the install method, thinking this would be easier. This builds the cross-compiler in the same directory as the source, rather than installing it in your system folders:

Code: Select all

./configure --enable-local
make
This doesn't take very long, as it simply builds the tools needed for the menu configuration. The remainder of the process is similar to building a Linux kernel. Run the following command for help with the build.

Code: Select all

./ct-ng help
Menu configuration

Run

Code: Select all

./ct-ng menuconfig
to get started with this.

Now you need to load the saved configuration I have found to work:
  • Download the latest version of the configuration from the end of this post.
  • Run ./ct-ng menuconfig as above.
  • Select the "Load an Alternate Configuration File" option.
  • Type in the full path to, and name of, the configuration file here, and press ENTER.
  • Select the "Save an Alternate Configuration File" option.
  • Enter ".config", and press ENTER.
  • Press TAB too select the "Exit" option at the bottom of the screen and press ENTER.
  • If asked to save configuration, confirm the save operation.
Patching the build scripts

NOTE: I have now also uploaded these files (and all the other dependencies) to https://wmtprojectsforum.altervista.org ... pendencies in case the download locations change again.

In a few places, these build scripts attempt to download tarballs from sources that have moved. The following changes need to be made:

Linux Kernel Download Location

The kernel is no longer available where the script attempts to download it. Open the file

Code: Select all

scripts/build/kernel/linux.sh
and change the line in the do_kernel_get() function:

Code: Select all

korg_base="http://ftp.kernel.org/pub/linux/kernel/${rel_dir}"
To read:

Code: Select all

korg_base="http://mirrors.edge.kernel.org/pub/linux/kernel/${rel_dir}"
MPC download location

MPC is no longer available where the script attempts to download it. Open the file

Code: Select all

scripts/build/companion_libs/mpc.sh
and change the line in the do_mpc_get() function:

Code: Select all

http://www.multiprecision.org/mpc/download
To read:

Code: Select all

http://www.multiprecision.org/downloads
DUMA download location

The "duma" package is no longer available where the script is looking for it. Open the file

Code: Select all

scripts/build/debug/200-duma.sh
and change the line near the top of the file:

Code: Select all

dl_base="http://downloads.sourceforge.net/project/duma/duma"
To read:

Code: Select all

dl_base="https://sourceforge.net/projects/duma/files/duma"
Now the build is ready to be started.

Starting the build

Run:

Code: Select all

./ct-ng build
This will take a while. On my system (Intel Core i5-4440 CPU and 16GB RAM), it takes around 20-30 minutes to build, ignoring downloading the files.

After the build has finished

The cross-compiler will be found in ~/x-tools/arm-unknown-linux-gnueabi/bin. In order to make using these tools easier, it is advisable to add them to your PATH variable, by adding the following to the end or your ~/.bashrc file:

Code: Select all

export PATH=$PATH:~/x-tools/arm-unknown-linux-gnueabi/bin
These changes will take effect after you close and re-open your terminal. To make them apply now, run:

Code: Select all

source ~/.bashrc
Extra feature: running ARMv5 binaries in the build environment.

This can be done with QEMU. Simple run the command:

Code: Select all

sudo apt install qemu-user-static
And then add:

Code: Select all

export QEMU_LD_PREFIX=/home/wmt/nas-sysroot
export LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib"
To your .bashrc file, and you should be good to go. This is useful for running test suites for programs.

You may need to add the following snippet of code before you run binaries built for the NAS box:

Code: Select all

LD_LIBRARY_PATH="/home/wmt/nas-sysroot/lib:/home/wmt/nas-sysroot/usr/local/lib" 
This is required for certain things, like building NSPR and python-mysqlclient.
Attachments
64-bit NAS Cross-compile Env.ovf.txt
(10.07 KiB) Downloaded 73 times
config-1.17-FINAL.txt
(11.35 KiB) Downloaded 80 times
config-1.17-old.tar.gz
(4.08 KiB) Downloaded 74 times
Last edited by hamishmb on 12/05/2020, 17:33, edited 9 times in total.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Cross Compiler Build Instructions

Post by hamishmb »

NOTE: The locations for some of the dependencies the cross compiler needed had moved, as I documented above previously. Seeing as we have more web space, I have now also uploaded these files to https://wmtprojectsforum.altervista.org ... pendencies in case the download locations change again.
Hamish
Post Reply