Hi Guix, attached is a patch blob providing the “embedded.scm” module. I’m using this cross-compiler semi-successfully to build so-called “patches” for the Axoloti audio development/prototyping board.
I’m using the cross binutils at a particular git commit; the same applies to “gcc-arm-none-eabi”, which takes the GCC sources from SVN. This is done because these revisions are known to work. Axoloti upstream uses a binary cross-compiler toolchain release, which is available here: https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q2-update The module also contains “newlib-arm-none-eabi” and “newlib-nano-arm-none-eabi”, which is used instead of the glibc. In “gnu/packages/bootstrap.scm” I made a tiny change to keep “glibc-dynamic-linker” from failing. Now, I have a problem with this toolchain: it doesn’t seem to work properly. While I can build “patches” for Axoloti that are linked with the pre-compiled firmware from upstream, I cannot seem to create a working firmware binary (that’s ChibiOS with extensions). There are no errors when I build it; it generates an elf file. But when it is uploaded to the board the system won’t boot. I have to flash upstream’s binary firmware with dfu-util to revive the board. Generating “patches” on the other hand works fine. It’s really just this: ~~~~~~~~~~~ /gnu/store/p787lrv17m25v0cdrdzw66r9b7hk1109-gcc-cross-sans-libc-arm-none-eabi-4.9.3-1.224288/bin/arm-none-eabi-g++ -nostdlib -fno-exceptions -fno-rtti -mcpu=cortex-m4 -O3 -fomit-frame-pointer -falign-functions=16 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wunused-parameter -DCORTEX_USE_FPU=TRUE -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb -DTHUMB -std=c++11 -DARM_MATH_CM4 -D__FPU_PRESENT -H -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/CMSIS/Include -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/ports/common/ARMCMx/CMSIS/include -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/ports/common/ARMCMx -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/ports/GCC/ARMCMx -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/ports/GCC/ARMCMx/STM32F4xx -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/kernel/include -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/include -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32F4xx -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/GPIOv2 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/I2Cv1 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/OTGv1 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/RTCv2 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/SPIv1 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/TIMv1 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/os/hal/platforms/STM32/USARTv1 -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/boards/ST_STM32F4_DISCOVERY -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios/ext/fatfs/src -I. -I/gnu/store/ysyi04kr6y4sbp5s6yyvpy3kl2yhppyh-axoloti-patcher-1.0.6/share/axoloti/chibios -Winvalid-pch -MD -MP --include /home/rekado/axoloti/build/xpatch.h -c /home/rekado/axoloti/build/xpatch.cpp -o /home/rekado/axoloti/build/xpatch.o ~~~~~~~~~~~ Since the command that works does not involve the linker as far as I can tell my guess is that the linker is somehow broken (or that maybe linking with “newlib” instead “glibc” doesn’t quite work). I have never before built cross-compilers and I don’t really know what I’m doing. If you have any suggestions I’d be glad to hear them! ~~ Ricardo
>From 18b057d628f849dd11de1756068e2bee5986f584 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus <rek...@elephly.net> Date: Thu, 3 Mar 2016 18:07:30 +0100 Subject: [PATCH 1/2] WIP arm-none-eabi cross-compiler --- gnu/packages/bootstrap.scm | 1 + gnu/packages/embedded.scm | 160 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 gnu/packages/embedded.scm diff --git a/gnu/packages/bootstrap.scm b/gnu/packages/bootstrap.scm index f5bf069..4acbb62 100644 --- a/gnu/packages/bootstrap.scm +++ b/gnu/packages/bootstrap.scm @@ -169,6 +169,7 @@ successful, or false to signal an error." ;; XXX: This one is used bare-bones, without a libc, so add a case ;; here just so we can keep going. + ((string=? system "arm-eabi") "no-ld.so") ((string=? system "xtensa-elf") "no-ld.so") ((string=? system "avr") "no-ld.so") diff --git a/gnu/packages/embedded.scm b/gnu/packages/embedded.scm new file mode 100644 index 0000000..bf6b44d --- /dev/null +++ b/gnu/packages/embedded.scm @@ -0,0 +1,160 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2016 Ricardo Wurmus <rek...@elephly.net> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu packages embedded) + #:use-module (guix utils) + #:use-module (guix packages) + #:use-module (guix download) + #:use-module (guix svn-download) + #:use-module (guix git-download) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (guix build-system gnu) + #:use-module (gnu packages) + #:use-module (gnu packages bison) + #:use-module (gnu packages cross-base) + #:use-module (gnu packages flex) + #:use-module (gnu packages perl) + #:use-module (gnu packages texinfo)) + +(define-public xbinutils-arm-none-eabi + (let ((parent (cross-binutils "arm-none-eabi")) + (commit "136a940ac535e464d2a7a86880ce1f1a5554c484")) + (package (inherit parent) + (source (origin + (method git-fetch) + (uri (git-reference + (url "git://sourceware.org/git/binutils-gdb.git") + (commit commit))) + (file-name (string-append "xbinutils-arm-none-eabi-" + (package-version parent) "-" + (string-take commit 9) "-checkout")) + (patches (origin-patches (package-source parent))) + (sha256 + (base32 + "185sfmhbplidvj8n3h1clqqf6c0wqcigzm3phn9sqfy9arsv3mg8")))) + (native-inputs + `(("texinfo" ,texinfo) + ("perl" ,perl) + ("bison" ,bison) + ("flex" ,flex) + ,@(package-native-inputs parent))) + (arguments + `(,@(substitute-keyword-arguments (package-arguments parent) + ((#:configure-flags flags) + `(cons "--enable-multilib" + (delete "--disable-multilib" ,flags))))))))) + +;; Cannot just use the released GCC sources here, must be from SVN. +(define-public gcc-arm-none-eabi + (let ((xgcc (cross-gcc "arm-none-eabi" + xbinutils-arm-none-eabi)) + (revision 224288)) + (package (inherit xgcc) + (source + (origin + (method svn-fetch) + (uri (svn-reference + (url "svn://gcc.gnu.org/svn/gcc/branches/ARM/embedded-4_9-branch/") + (revision revision))) + (file-name (string-append "gcc-arm-embedded-" + (package-version xgcc) "-" + (number->string revision) "-checkout")) + (sha256 + (base32 + "113r98kygy8rrjfv2pd3z6zlfzbj543pq7xyq8bgh72c608mmsbr")) + (patches (origin-patches (package-source xgcc))))) + (native-inputs + `(("flex" ,flex) + ,@(package-native-inputs xgcc))) + (arguments + `(,@(substitute-keyword-arguments (package-arguments xgcc) + ((#:phases phases) + `(modify-phases ,phases + (add-after 'unpack 'fix-genmultilib + (lambda _ + (substitute* "gcc/genmultilib" + (("#!/bin/sh") (string-append "#!" (which "sh")))) + #t)))) + ((#:configure-flags flags) + `(cons "--with-newlib" + (cons "--enable-multilib" + (delete "--disable-multilib" ,flags)))))))))) + +(define-public newlib-arm-none-eabi + (package + (name "newlib") + (version "2.2.0") + (source (origin + (method url-fetch) + (uri (string-append "ftp://sourceware.org/pub/newlib/newlib-" + version ".tar.gz")) + (sha256 + (base32 + "1gimncxzq663l4gp8zd89ynfzhk2q802mcaiyjpr2xbkn1ix5bgq")))) + (build-system gnu-build-system) + (arguments + `(#:out-of-source? #t + #:configure-flags '("--target=arm-none-eabi" + "--enable-newlib-io-long-long" + "--enable-newlib-register-fini" + "--disable-newlib-supplied-syscalls" + "--disable-nls") + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'fix-shell-shebangs-please + (lambda _ + (setenv "SHELL" (which "sh")) + (setenv "CONFIG_SHELL" (which "sh")) + (substitute* '("libgloss/arm/configure" + "libgloss/arm/cpu-init/Makefile.in" + "libgloss/arm/Makefile.in" + "libgloss/libnosys/Makefile.in" + "libgloss/Makefile.in") + (("/bin/sh") (which "sh"))) + #t))))) + (native-inputs `(("xbinutils" ,xbinutils-arm-none-eabi) + ("xgcc" ,gcc-arm-none-eabi) + ("texinfo" ,texinfo))) + (home-page "http://www.sourceware.org/newlib/") + (synopsis "C library for use on embedded systems") + (description + "Newlib is a C library intended for use on embedded systems. It is a +conglomeration of several library parts, that are easily usable on embedded +products.") + (license (license:non-copyleft + "https://www.sourceware.org/newlib/COPYING.NEWLIB")))) + +(define-public newlib-nano-arm-none-eabi + (package (inherit newlib-arm-none-eabi) + (name "newlib-nano") + (arguments + (substitute-keyword-arguments (package-arguments newlib-arm-none-eabi) + ((#:configure-flags flags) + ``("--target=arm-none-eabi" + "--enable-multilib" + "--disable-newlib-supplied-syscalls" + "--enable-newlib-reent-small" + "--disable-newlib-fvwrite-in-streamio" + "--disable-newlib-fseek-optimization" + "--disable-newlib-wide-orient" + "--enable-newlib-nano-malloc" + "--disable-newlib-unbuf-stream-opt" + "--enable-lite-exit" + "--enable-newlib-global-atexit" + "--enable-newlib-nano-formatted-io" + "--disable-nls")))))) -- 2.6.3