Build Cortex M3 cross compiler on Raspberry Pi 3

Asked by Robby

Hello. I am interested in having a cross compiler tool chain installed on my Raspberry Pi 3. That is, I want the Raspberry Pi 3 to act as a development system for writing code to target a microcontroller/Cortex M3.

I am using the default install OS they deliver with Raspberry Pi 3, Raspbian OS, Jessie. It comes with a version of GCC, so I figured I could use GCC to build the ARM-GCC cross compiler. I downloaded the source, followed the guide of installing the common tools, unzipped everything, and ran 'sudo ./build-prerequisites.sh'. The first problem I ran into is that the makefile for the prerequisites fail with the statement "unknown target arm7l' or something like that.

I then decided to just build the prerequisites manually by going into each directory and doing configure, make, make check, make install. That seemed to work fairly successfully. The make check would pass except for like one or two tests out of like a hundred. I then tried to go back to doing './build-toolchain.sh', and that's where the second problem happened. The configure stage would get to the step where it was checking gmp/mpc/mpfr versions...It would pass on the test that states "searching for header files", but would fail on the step for "checking for version". Which is strange since I could clearly see the library files in one of my lib directories.

Soooooo the next thing I tried was just downloading and building the latest versions of gmp/mpc/mpfr. I just downloaded the source and built as normal. Now when I run './build-toolchain.sh', it gets past the configure stage and into the make stage, calling gcc a billion times. This goes on for a really long time so I was hopeful I'd complete the task, but eventually it error'd out:

This is the last set of lines before the error:

g++ -c -DIN_GCC_FRONTEND -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -Ic -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/c -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../include -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../libcpp/include -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/build-native/host-libs/usr/include -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/build-native/host-libs/usr/include -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/build-native/host-libs/usr/include -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../libdecnumber -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../libdecnumber/dpd -I../libdecnumber -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../libbacktrace -I/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/build-native/host-libs/usr/include -o c/c-decl.o -MT c/c-decl.o -MMD -MP -MF c/.deps/c-decl.TPo /home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/c/c-decl.c
/bin/sh: line 1: 10492 Killed build/genautomata /home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/common.md /home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/config/arm/arm.md insn-conditions.md > tmp-automata.c
Makefile:2138: recipe for target 's-automata' failed
make[1]: *** [s-automata] Error 137
make[1]: *** Waiting for unfinished jobs....
/bin/sh /home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../move-if-change tmp-attrtab.c insn-attrtab.c
/bin/sh /home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../move-if-change tmp-dfatab.c insn-dfatab.c
/bin/sh /home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/src/gcc/gcc/../move-if-change tmp-latencytab.c insn-latencytab.c
echo timestamp > s-attrtab
rm cpp.pod gcov-tool.pod gfdl.pod fsf-funding.pod gcov.pod gcc.pod
make[1]: Leaving directory '/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/build-native/gcc-first/gcc'
Makefile:4095: recipe for target 'all-gcc' failed
make: *** [all-gcc] Error 2

Anybody got any hints to building the cross compiler on the RP3?

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Freddie Chopin (freddie-chopin) said :
#1

You could give my script a try - it should work on any Linux without issues, as long as you install required tools. Take a look at README.md file for details on what will be needed.

https://github.com/FreddieChopin/bleeding-edge-toolchain

Revision history for this message
Thomas Preud'homme (robotux) said :
#2

Hi Robby,

The fact that the log says "Killed" suggests to me that you ran into memory issue. You could try by reducing the number of CPU used (check in build-toolchain.sh where does the value passed to -j option of make comes from) for the compilation and/or setting up a swap.

Best regards.

Revision history for this message
Robby (rdb9879) said :
#3

Thanks for the feedback. Freddie, I did not get a chance to try your bleed edge script but if tonight's build doesn't work out, I am planning on giving it a whirl.

Thomas, I took your advice and increased the swapfile size to 2GB (it defaults to 0.1GB). It's currently been running all day, which hopefully is a good sign that it is going to make it. It's definitely made it further than before.

Thanks again all.

Revision history for this message
Robby (rdb9879) said :
#4

Looks like it built for about 12 hours and then error'd out with "python is missing or unusable" :

checking for XML_StopParser... yes
checking whether to use python... yes
checking for python... /usr/bin/python
checking for python2.7... no
configure: error: python is missing or unusable
Makefile:8724: recipe for target 'configure-gdb' failed
make[1]: *** [configure-gdb] Error 1
make[1]: Leaving directory '/home/pi/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926/build-native/gdb'
Makefile:844: recipe for target 'all' failed
make: *** [all] Error 2

Not sure what the problem is, because I have no problem finding python:

pi@raspberrypi:~/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926 $ which python
/usr/bin/python

pi@raspberrypi:~/tmp/gcc-arm-none-eabi-5_4-2016q3-20160926 $ python -V
Python 2.7.9

Revision history for this message
Robby (rdb9879) said :
#5

I gave up on building gnu arm via downloading source from launchpad.net. I found some arm build scripts that had been modified specifically for the raspberry pi: https://github.com/ARMinARM/arm-toolchain-build-scripts

I gave it a whirl, and it built! I gave a quick hello world example a test (using the flags -mthumb -mcpu=cortex-m3 --march=armv7-m), and it seemed to compile fine and error out on the linker. I believe to truly test it I need to create a makefile and a linker script, etc. So that will be my next goal.

Can you help with this problem?

Provide an answer of your own, or ask Robby for more information if necessary.

To post a message you must log in.