Just now I found the site toolchains.bootlin.com to download suitable prebuilt toolchain, it provides detailed GCC
/GDB
/Linux Header
versions.
Before knowing this site, I tried buildroot
and crosstool-ng
to build my own toolchain, here is to share the experience.
But to be honest the toolchains.bootlin.com seems better, because it built tools for us, and you can choose version of GCC
and GDB
, while buildroot
and crosstool-ng
can’t.
Buildroot
Buildroot is a framework to build embedded Linux software on Linux. It is made up of makefile
and Kconfig
configuration files. L
ike compiling Linux kernel, configure buildroot
and edit menuconfig
to compile a complete Linux system software (including boot, kernel, rootfs and libs) that can be directly burned and run on the machine.
Download buildroot
.
1 | $ wget http://buildroot.uclibc.org/downloads/snapshots/buildroot-snapshot.tar.bz2 |
Configure buildroot
.
1 | $ sudo apt-get install libncurses-dev patch |
When interface shows up like this,
Set Target Architecture
as MIPS (little endian)
(depending on your target);
Set Kernel Headers
as your host Linux version,because it will run on your pc.
Install it.
1 | $ sudo apt-get install texinfo |
Compiled files will be found in directory output
. Cross compile utils will be in buildroot/output/host/usr/bin
, and the compiler is mips-linux-gcc
.
Configure environment variables and test.
1 | $ gedit ~/.bashrc |
Crosstool-NG
You can visit official site for its introduction and documentation.
I installed it by source code
1 | $ git clone https://github.com/crosstool-ng/crosstool-ng |
If you are root
user, you’ll get
1 | $ ./ct-ng build |
To solve it, add things to ./ct-ng
1 | $ vim ./ct-ng |
It can be operated like buildroot
1 | $ cd /some/place/bin |
Or a more convenient way, use the templates/samples
1 | $ ./ct-ng list-samples # show templates |
Now the ct-ng
downloads what it needs to .build
dir according to .config
(made automatically).
However these are not what produced. Check your home dir u will find x-tools
1 | $ ls |
These are the built toolchain.
The truth is, the binarys compiled by it cannot run on old kernels (encounter FATAL:kernel too old
in QEMU
), that might because the libs (~/x-tools/mips-malta-linux-gnu/mips-malta-linux-gnu/sysroot/lib/ld-2.32.so
) it use are latest.
So for old devices or QEMU
, better use buildroot, or try toolchains.bootlin.com.
Compile GDB&GDBserver
It is for dynamic analysis, and I almost messed up by this. Get source code on FTP
First see how to set configuration
1 | $ ./configure --target=mipsel-linux --host=mipsel-linux --program-prefix=mipsel-linux --prefix=`echo $PWD`/bin CC=/path/to/buildroot/output/host/bin/mipsel-linux-gcc CXX=/path/to/buildroot/output/host/bin/mipsel-linux-g++ AR=/path/to/buildroot/output/host/bin/mipsel-linux-ar LD=/path/to/buildroot/output/host/bin/mipsel-linux-ld RANLIB=/path/to/buildroot/output/host/bin/mipsel-linux-ranlib STRIP=/path/to/buildroot/output/host/bin/mipsel-linux-strip CFLAGS="-w -static" CXXFLAGS="-w -static" LDFLAGS="-static" |
Recommended versions includes 7.10
…
Versions too high cause configure: error: ***A compiler with support for c++11 language features is required
, while lower versions gives configure: error: no termcap library found
.
However problems still come out, if your toolchain is so latest, or if some other libraries are required.
The built gdbservers are off the shelf, you can use them or things built by others directly.