Introduction

I was finding my old toolchain was unable to compile new kernels, largely because its binutils was out of date. I decided to build a new toolchain and document the method here. I did this on an X86, though it should work from any host in theory.

Stuff to download

How to build

We need three things to build a complete toolchain. These are:

  • binutils (The assembler, linker, and other tools)
  • gcc (The C compiler)
  • The linux kernel headers (required to build gcc)

We also will patch gcc to prevent the building of 'newlib' which cannot work without a compiled glibc (which cannot work until you have a compiler, which cannot work until you have…)

First, we need to build binutils. You need to pick a location your tools will be installed into at this point, path/to/tools. I personally keep this in my home directory, so I dont need to be root to run make install. This prevents me stupidly wiping out my native tools by forgetting to set the target when configuring. I also recommend using absolute paths during the build.

mkdir path/to/tools
tar jxf binutils-2.14.tar.bz2
mkdir build-binutils
cd build-binutils
../binutils-2.14/configure --target=arm-linux --prefix=path/to/tools
make
make install
cd ..

Next, we need to copy the kernel headers into our new toolchains 'include' directory. These headers are needed to compile gcc - we cannot use the native ones (in my case X86), as the headers differ between architectures.

We need to prepare the kernel for building for arm26 before we copy the headers. At this point, it would be a good idea to apply the latest arm26 patch to the kernel, to ensure you get a good copy of the headers.

tar jxf kernel_source.tar.gz
cd kernel_dir
patch -p1 < arm26_patch_du_jour.patch

The next step may be unneccessary on current arm26 kernels, as we no longer have symlinks in include/asm-arm26/ but I havent checked either there or in include/linux/ so best do it anyway.

modify the kernel Makefile so 'SUBARCH' is arm26

make menuconfig and then exit saving 'changes'
make dep

Then drop back out of the kernel directory

cd ..

Now we must copy the kernel headers into our new toolchains include/ directory.

mkdir path/to/tools/arm-linux/include
cp -dR path/to/kernel/include/asm-arm26 path/to/tools/arm-linux/include/asm
cp -dR path/to/kernel/include/linux     path/to/tools/arm-linux/include/linux

Finally, we must build gcc itself, thus:

tar zxf gcc-core-2.95.3.tar.gz
cd gcc-2.95.3
patch -p1 < gcc_inhibit_libc_patch
cd ..
mkdir build-gcc
cd build-gcc
PATH=$PATH:path/to/tools/bin
../gcc-2.95.3/configure --target=arm-linux --prefix=path/to/tools --with-headers=path/to/tools/arm-linux/include
make install
cd ..

At this point you should have a nice fresh toolchain installed in path/to/tools. All that remains is to modify the kernel Makefile so that the line containing CROSS_COMPILE= reads:

CROSS_COMPILE=path/to/tools/bin/arm-linux-

Enjoy your new toolchain!

 
home/projects/linux/arm26linux/cross_build.txt · Last modified: 2008/02/06 23:30 by ian
 
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Debian Driven by DokuWiki