0
votes

I would like to prepare GNU toolchain for bare metal ARM to use it with Geany IDE. There are some tutorials like this one: Building the GNU ARM Toolchain for Bare Metal but I do not understand few steps.

First of all, everyone who uses Linux OS implicitly has gcc, binutils and gdb so why to download others? Secondly all tutorials tell me to configure gcc with something like that: *./configure --target=arm-elf. What does it even do ? Does it just force me to call gcc in command line using arm-elf-gcc instead of gcc or does it change some internal options of my gcc ?

So far I have prepared makefile but I am still not sure about compiler options. I have not changed any gcc configure options and I call compiler with such flags:

CFLAGS = -Wall -std=c99 -march=armv7-m -mtune=cortex-m0

Can I prepare toolchain just with calling gcc with proper arguments or do I need to make some changes in gcc configuration ?

1
Did you at least try those options with your compiler? Did it work? Does that give you a clue as to why the prep. steps are necessary?Mat
I would suggest you go away and investigate "cross-compiling"...Joe
I have not try so far because every tutorial I have seen included configuring --target=arm-elf without explanation what it actually does to the compiler and I am not if my way with just calling gcc with arguments is even possible.Al Bundy

1 Answers

6
votes

GCC and its target

GCC is always configured to emit binaries for a specific target. So normally the gcc which is already available on Linux has the target "i486-linux-gnu". You can't cross-compile to an ARM target using this compiler.

So you need to install another GCC configured for that target; then GCC and the other programs normally have a prefix indicating the target: In your case the prefix is arm-none-eabi, and then you call that GCC using arm-none-eabi-gcc. You can have multiple GCC installations, they do not interact (if they interact, you have probably screwed up something - always install in separate directories, if you do it manually).

Installing

  • If your Linux distribution provides a package, you could just install that one (on Debian this is "gcc-arm-none-eabi").
  • You can download a pre-compiled package: GNU Tools for ARM Embedded Processors.
  • You can try to compile one. Not really easy, if you want correct multi-libs.

If your Linux distribution provides a package > 4.8.0, you should try that one. If you want to have multiple versions installed (and be able to switch between them easily), the second option is possibly better. I stopped compiling a GCC for ARM when the second option was available.

Cross-compiling

  • In your Makefile you have to make sure that the cross-compiler is used. You could use $(CC) in your Makefile, and assign it like this:
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
  • Compiler flags for Cortex-M0 are -mcpu=cortex-m0 -mthumb -mfloat-abi=soft which is by convention assigned to CFLAGS
CFLAGS += -mcpu=cortex-m0 -mthumb -mfloat-abi=soft

Then a (simple) rule to compile .c to .o looks like

%.o: %.c
    $(CC) $(CFLAGS) -o $@ -c $<

Tutorials which use the arm-elf- prefix are out-dated. Currently arm-none-eabi- is in use.