?

Log in

No account? Create an account
Doing silly things with cross-compilers, part 1 (installing MinGW) - 'Twas brillig, and the slithy toves did gyre and gimble in the wabe — LiveJournal [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

Doing silly things with cross-compilers, part 1 (installing MinGW) [Saturday 14th January 2012 at 5:56 pm]
Thomas

boggyb
[Tags|, ]
[Feeling |accomplishedaccomplished]
[Playing |Orinoco Flow ~ Celtic Woman/The Very Best of Pure Moods - Disc 1]

Since getting that NAS, I've been poking around and looking at adding some useful programs to the existing firmware. The initial one I want to run on it is smartmontools, so I can see just what start the hard disks are in and try and prod the second one into actually responding.

As with most embedded stuff, it runs Linux. So getting my own code to run is merely a case of building a cross-compiler that'll run on an actual system and produces output that works on the NAS' armv5l-linux architecture. Actually, since this is a NAS with actual disks I'm not limited to the pokey little flash chip that most embedded stuff has (this device has 16MB of flash - most routers have 8MB or even only 4MB!) and so I could run the compiler on the NAS itself. Unfortunately, it doesn't come with one, and to build a compiler you first need a compiler. Hence the need for a cross-compiler. Since the target is Linux that'd normally mean I'd also need to install a Linux development environment, which I'd rather not have to do - Linux and I don't get on well.

Now, something I tripped across recently is a page on the MinGW website, containing instructions for building a cross-compiler hosted under MinGW. The useful part of this for me is that MinGW along with MSYS is a port of a whole bunch of Linux tools to Windows. So in theory I should be able to use that to build and run my cross-compiler on Windows. This is completely against the normal way of doing things, but the wiki page is proof that it should be possible.

Unfortunately the instructions are rather out of date, so I'm having to make it up as I go along (using a vaguely recent set of instructions for a GNU/Linux ARM toolchain and an older Linux/ARM howto for more recent details). I intend to document this as I go along, partially as a set of notes to myself, partially in the hope that the next person to try this finds it useful, but mainly so you can all point and laugh when it inevitably fails in some spectacular fashion.

Part 1: Installing MinGW

I actually started doing this a couple of weeks ago, so since I've only just started writing this up I'll have to guess at what I did here. Most of this is basic setup to get everything laid out.

To start with I installed MinGW, selecting at least the MSYS and MinGW Developer Toolkit options (I think I just selected everything) and installing it into C:\MinGW. This gives a Windows-hosted GNU toolchain, targeting Windows.

Next, download the src packages for binutils and gcc from the MinGW site and save them in C:\MinGW\var\cache\mingw-get\packages (try and get the version that matches the bin or dll package that's already in that folder). Next, get the dev package for gmp, mpc and mpfr and save them to the same place (gcc needs these). Finally, get the dll package for libgmpxx.

Start a MinGW shell up. Enter the following commands to set up some useful shell variables and create the necessary directories:

TARGET=armv5l-linux
PREFIX=/cross/n2100
SYSROOT=$PREFIX/sysroot
export ARCH=arm
export CROSS_COMPILE=${TARGET}-
export PATH=$PATH:${PREFIX}/bin
mkdir -p /cross/src
mkdir -p $PREFIX/build
mkdir -p $PREFIX/src

I'm using the following directory structure:

/cross
root of all the cross-compilation stuff. This should be equivalent to C:\MinGW\msys\1.0\cross
/cross/src
general source files
/cross/n2100
target folder, in this case for the Thecus n2100 NAS
/cross/n2100/src
source files specific to this target
/cross/n2100/sysroot
kernel headers and suchlike for the target
/cross/n2100/build
somewhere to actually build everything (since gcc in particular won't build correctly unless you build in a different location to the sources)

Unpack the dev and dll packages that were downloaded earlier. These need to go into /mingw, not / (so of course I unpacked them into / first):

cd /mingw
tar -xvf /mingw/var/cache/mingw-get/packages/libgmpxx-5.0.1-1-mingw32-dll-4.tar.lzma
tar -xvf /mingw/var/cache/mingw-get/packages/gmp-5.0.1-1-mingw32-dev.tar.lzma
tar -xvf /mingw/var/cache/mingw-get/packages/mpc-0.8.1-1-mingw32-dev.tar.lzma
tar -xvf /mingw/var/cache/mingw-get/packages/mpfr-2.4.1-1-mingw32-dev.tar.lzma

At this point everything should be ready to actually start building stuff.

Link | Previous Entry | Share | Next Entry[ Penny for your thoughts? ]