This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

arm-elf-gcc compiling for cortex-M4

How to use GNU ARM binutils for cortex-M4? When I try to compile with -mcpu=cortex-M4 -march=armV7e-m I get 'bad value in switches'.

Parents
  • Hi jvanmont - sorry for the late reply.

    I use gcc-4.8.3 myself; I can use the same arm-none-eabi-gcc to build for Cortex-M0, Cortex-M3 and Cortex-M4.

    Building gcc-4.8.3 is a bit more difficult than building a v4.5 and earlier.

    -I recommend getting the launchpad version, if you're able to build it. The only reason I had to build my own, is that I'm on a PowerPC based Mac, which none of the well-known toolchains will work for.

    If you are using a PowerMac (not Mac Pro), please let me know.

    In order to use the --with-multilib-list, you will need to apply two patches: t-arm-elf.patch and cortex-m0-trap.S.patch (they're attached to this post).

    If you want to build gcc-4.8.3, then I'll give you some hints for preparing the sources.

    To build gcc, do not compile mpfr, mpc and gmp; instead make symlinks to the parent directories, otherwise you'll be waiting half a day until it's built.

    If you're building for Mac (or your /usr directory is not writable by you), then you'll need to prefix the 'make install' by sudo.

    I also recommend using parallel-builds to save you 3-4 hours.

    For instance 'make -j8' instead of just 'make'. The number after -j is twice the number of cores that your computer has.

    Patch sources, so we'll get support for all Cortex-M architectures (and ARM7TDMI):

    ( cd "source/gcc-4.8.3/"; patch -p1 < "archives/t-arm-elf.patch" )

    ( cd "source/newlib-2.1.0/"; patch -p1 < "archives/cortex-m0-trap.S.patch" )

    Create symlinks to used libraries:

    ln -s "source/gmp-5.1.3" "source/gcc-4.8.3/gmp"

    ln -s "source/mpfr-3.1.2" "source/gcc-4.8.3/mpfr"

    ln -s "source/mpc-1.0.2" "source/gcc-4.8.3/mpc"

    ln -s "source/libelf-0.8.13" "source/gcc-4.8.3/libelf"

    ln -s "source/newlib-2.1.0/newlib" "source/gcc-4.8.3/newlib"

    These are my build-lines for binutils:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --disable-nls --disable-libssp --with-gcc --with-gnu-as --with-gnu-ld --enable-multilib --enable-interwork --enable-plugins --with-system-zlib

    make && make install

    My build-lines for bootstrap gcc:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --disable-nls --with-gcc --with-gnu-as --with-gnu-ld --with-dwarf2 --enable-multilib --enable-interwork --with-newlib --disable-libssp --with-system-zlib --disable-decimal-float --disable-libffi --disable-libmudflap --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r --disable-libstdcxx-pch --without-headers --enable-languages="c,c++"

    make all-gcc && make install-gcc

    Temporarily add the newly built gcc to the PATH environment variable:

    export PATH="$PATH:/usr/local/arm-none-eabi/bin"

    My build-lines for newlib:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --enable-interwork --enable-multilib --disable-libssp --disable-nls --enable-newlib-io-long-long --enable-newlib-register-fini --disable-newlib-supplied-syscalls

    make CFLAGS_FOR_TARGET="-D__IEEE_BIG_ENDIAN -D__IEEE_BYTES_LITTLE_ENDIAN -D__BUFSIZ__=64" && env "PATH=$PATH" make install || env "PATH=$PATH" make install

    (yes, the crazy double-install is most likely necessary, because a directory is missing on the first try)

    Show the architectures that your multilib supports; this should include all Cortex-M, plus ARM7TDMI:

    arm-none-eabi-gcc -print-multi-lib

    My build-lines for final gcc:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --disable-nls --with-gcc --with-gnu-as --with-gnu-ld --with-dwarf2 --enable-multilib --enable-interwork --with-newlib --disable-libssp --with-system-zlib --disable-decimal-float --disable-libffi --disable-libmudflap --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r --disable-libstdcxx-pch --with-headers=yes --enable-languages="c,c++"

    make all -Wno-error=deprecated-declarations && make install

    If you need more information, please send me a personal message.

Reply
  • Hi jvanmont - sorry for the late reply.

    I use gcc-4.8.3 myself; I can use the same arm-none-eabi-gcc to build for Cortex-M0, Cortex-M3 and Cortex-M4.

    Building gcc-4.8.3 is a bit more difficult than building a v4.5 and earlier.

    -I recommend getting the launchpad version, if you're able to build it. The only reason I had to build my own, is that I'm on a PowerPC based Mac, which none of the well-known toolchains will work for.

    If you are using a PowerMac (not Mac Pro), please let me know.

    In order to use the --with-multilib-list, you will need to apply two patches: t-arm-elf.patch and cortex-m0-trap.S.patch (they're attached to this post).

    If you want to build gcc-4.8.3, then I'll give you some hints for preparing the sources.

    To build gcc, do not compile mpfr, mpc and gmp; instead make symlinks to the parent directories, otherwise you'll be waiting half a day until it's built.

    If you're building for Mac (or your /usr directory is not writable by you), then you'll need to prefix the 'make install' by sudo.

    I also recommend using parallel-builds to save you 3-4 hours.

    For instance 'make -j8' instead of just 'make'. The number after -j is twice the number of cores that your computer has.

    Patch sources, so we'll get support for all Cortex-M architectures (and ARM7TDMI):

    ( cd "source/gcc-4.8.3/"; patch -p1 < "archives/t-arm-elf.patch" )

    ( cd "source/newlib-2.1.0/"; patch -p1 < "archives/cortex-m0-trap.S.patch" )

    Create symlinks to used libraries:

    ln -s "source/gmp-5.1.3" "source/gcc-4.8.3/gmp"

    ln -s "source/mpfr-3.1.2" "source/gcc-4.8.3/mpfr"

    ln -s "source/mpc-1.0.2" "source/gcc-4.8.3/mpc"

    ln -s "source/libelf-0.8.13" "source/gcc-4.8.3/libelf"

    ln -s "source/newlib-2.1.0/newlib" "source/gcc-4.8.3/newlib"

    These are my build-lines for binutils:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --disable-nls --disable-libssp --with-gcc --with-gnu-as --with-gnu-ld --enable-multilib --enable-interwork --enable-plugins --with-system-zlib

    make && make install

    My build-lines for bootstrap gcc:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --disable-nls --with-gcc --with-gnu-as --with-gnu-ld --with-dwarf2 --enable-multilib --enable-interwork --with-newlib --disable-libssp --with-system-zlib --disable-decimal-float --disable-libffi --disable-libmudflap --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r --disable-libstdcxx-pch --without-headers --enable-languages="c,c++"

    make all-gcc && make install-gcc

    Temporarily add the newly built gcc to the PATH environment variable:

    export PATH="$PATH:/usr/local/arm-none-eabi/bin"

    My build-lines for newlib:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --enable-interwork --enable-multilib --disable-libssp --disable-nls --enable-newlib-io-long-long --enable-newlib-register-fini --disable-newlib-supplied-syscalls

    make CFLAGS_FOR_TARGET="-D__IEEE_BIG_ENDIAN -D__IEEE_BYTES_LITTLE_ENDIAN -D__BUFSIZ__=64" && env "PATH=$PATH" make install || env "PATH=$PATH" make install

    (yes, the crazy double-install is most likely necessary, because a directory is missing on the first try)

    Show the architectures that your multilib supports; this should include all Cortex-M, plus ARM7TDMI:

    arm-none-eabi-gcc -print-multi-lib

    My build-lines for final gcc:

    ./configure --target=arm-none-eabi --prefix=/usr/local/arm-none-eabi --disable-nls --with-gcc --with-gnu-as --with-gnu-ld --with-dwarf2 --enable-multilib --enable-interwork --with-newlib --disable-libssp --with-system-zlib --disable-decimal-float --disable-libffi --disable-libmudflap --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r --disable-libstdcxx-pch --with-headers=yes --enable-languages="c,c++"

    make all -Wno-error=deprecated-declarations && make install

    If you need more information, please send me a personal message.

Children