summaryrefslogtreecommitdiff
path: root/toolchain
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-05-02 20:32:37 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2013-05-02 20:32:37 +0200
commitd1daccfd3f00d73e51dedfc452f103e6aeb77d13 (patch)
tree979cae37faebea15fd9627c567651bc5031412aa /toolchain
New build environment and documentation.
Diffstat (limited to 'toolchain')
-rwxr-xr-xtoolchain/build-toolchain217
-rwxr-xr-xtoolchain/environment-setup14
-rw-r--r--toolchain/openocd-0.5.0-fix.patch94
3 files changed, 325 insertions, 0 deletions
diff --git a/toolchain/build-toolchain b/toolchain/build-toolchain
new file mode 100755
index 0000000..c872e65
--- /dev/null
+++ b/toolchain/build-toolchain
@@ -0,0 +1,217 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use FindBin qw($Bin $Script);
+use File::Path;
+
+my $GNU_MIRROR = 'ftp://ftp.fu-berlin.de/unix/gnu';
+my $NEWLIB_URL = 'ftp://sources.redhat.com/pub/newlib';
+
+my $GCC_VERSION = '4.6.3';
+my $GDB_VERSION = '7.4';
+my $BINUTILS_VERSION = '2.22';
+my $NEWLIB_VERSION = '1.20.0';
+my $OPENOCD_VERSION = '0.5.0';
+
+my $GCC_URL = "$GNU_MIRROR/gcc/gcc-$GCC_VERSION";
+my $GDB_URL = "$GNU_MIRROR/gdb";
+my $BINUTILS_URL = "$GNU_MIRROR/binutils";
+
+my $issue = 'this OS';
+if (open I, "</etc/issue") {
+ $issue = <I>;
+ close I;
+
+ $issue =~ s/\\.*$//g;
+ $issue =~ s/\s+$//g;
+}
+
+if ($issue =~ /^Ubuntu/) {
+
+ if ($issue !~ /^Ubuntu 11.10/) {
+ warn "Notice that this script hasn't been tested on $issue, if it fails, try Ubuntu 11.10 in stead\n";
+ }
+
+ my @missing;
+ for my $p qw'build-essential zlib1g-dev libgmp-dev libmpfr-dev libmpc-dev texinfo libftdi-dev libncurses5-dev libreadline-dev libexpat1-dev' {
+ print "Checking that you have $p\n";
+ push @missing, $p if system("dpkg -s $p > /dev/null");
+ }
+
+ if (@missing) {
+ my $cmd = "sudo apt-get install ".join(' ', @missing);
+ print "You're missing some packages, trying to fix that with: $cmd\n";
+ system($cmd) and die "Failed to install missing packages, please run this command manually: $cmd";
+ }
+
+} else {
+ warn "Notice that this script hasn't been tested on $issue, if it fails, try Ubuntu 11.10 in stead\n";
+}
+
+my @DIRS = (
+ {
+ dir => "binutils-$BINUTILS_VERSION",
+ url => $BINUTILS_URL,
+ cfg => ['--target=arm-none-eabi', '--enable-interwork', '--enable-multilib'],
+ make => 'make all install',
+ },
+
+ {
+ dir => "gcc-$GCC_VERSION",
+ url => $GCC_URL,
+ cfg => ['--target=arm-none-eabi', '--enable-interwork', '--enable-multilib', '--enable-languages=c,c++',
+ '--with-newlib',
+ "--with-headers=../../src/newlib-$NEWLIB_VERSION/newlib/libc/include",
+ '--with-system-zlib',
+ '--with-cpu=cortex-m3', '--with-mode=thumb',
+ ],
+ make=>'make all-gcc install-gcc',
+
+ make2=>'make all install',
+ },
+
+ {
+ dir => "gcc-core-$GCC_VERSION",
+ url => $GCC_URL,
+ },
+
+ {
+ dir => "gcc-g++-$GCC_VERSION",
+ url => $GCC_URL,
+ },
+
+ {
+ dir => "newlib-$NEWLIB_VERSION",
+ file => "newlib-$NEWLIB_VERSION.tar.gz",
+ url => $NEWLIB_URL,
+
+ cfg => ['--target=arm-none-eabi', '--enable-interwork', '--enable-multilib',
+ '--with-cpu=cortex-m3', '--with-mode=thumb', '--disable-newlib-supplied-syscalls'
+ ],
+ make => 'make all install',
+ },
+
+ {
+ dir => "gdb-$GDB_VERSION",
+ url => $GDB_URL,
+
+ cfg2=>['--target=arm-none-eabi', '--enable-interwork', '--enable-multilib'],
+ make2=>'make all install',
+ },
+
+ {
+ dir=> "openocd-$OPENOCD_VERSION",
+ url=>"http://downloads.sourceforge.net/project/openocd/openocd/$OPENOCD_VERSION/openocd-$OPENOCD_VERSION.tar.bz2?use_mirror=autoselect",
+
+ inplace=>1,
+ patch=>'openocd-0.5.0-fix.patch',
+ cfg=>['--enable-ft2232_libftdi', '--enable-jlink',
+ '--enable-buspirate'
+ ],
+ make=>'make all install',
+ },
+);
+
+my $tarDir = "$Bin/tarballs";
+mkdir $tarDir;
+
+# Do all the downloading up front, so we get that out of the way.
+for my $d (@DIRS) {
+ $d->{file} //= "$d->{dir}.tar.bz2";
+
+ my $fn = "$tarDir/$d->{file}";
+ my $url = "$d->{url}/$d->{file}";
+
+ if (-f $fn) {
+ print "You already have $d->{file}, skipping\n";
+ } else {
+ system("wget", "-O", $fn, $url) and die "Failed to fetch $d->{file} from $url";
+ die "Did not find the expected file: $fn" unless -f $fn;
+ }
+}
+
+
+# Unpack, configure, build and install each package.
+my $srcDir = "$Bin/src";
+mkdir $srcDir;
+my $buildDir = "$Bin/build";
+mkdir $buildDir;
+my $installDir = "$Bin/arm-toolchain";
+mkdir $installDir;
+
+$ENV{PATH} = "$ENV{PATH}:$installDir/bin";
+
+# Unpack all at sources once.
+for my $d (@DIRS) {
+ my $fn = "$tarDir/$d->{file}";
+ my $dn = "$srcDir/$d->{dir}";
+
+ if (-d $dn) {
+ print "Already unpacked $d->{dir}, skipping unpack\n";
+ } else {
+ print "Unpacking $fn\n";
+ chdir $srcDir;
+ system("tar", "xf", $fn) and die "Failed to unpack $fn into $srcDir";
+ mkdir $dn;
+
+ if ($d->{patch}) {
+ chdir $dn;
+ system("patch -p 1 < $Bin/$d->{patch}") and die "Failed to apply patch: $d->{patch}";
+ }
+ }
+}
+
+# Do the actual building, first pass
+for my $d (@DIRS) {
+ my $fn = "$tarDir/$d->{file}";
+ my $dn = "$srcDir/$d->{dir}";
+ my $bn = "$buildDir/$d->{dir}";
+
+ next if -f "$bn.done"; # Lazyness ftw.
+
+ rmtree $bn;
+ mkdir $bn;
+ if ($d->{inplace}) {
+ chdir $dn; # Build in the source directory, needed for borken packages
+ } else {
+ chdir $bn; # Build in a separate tree, because it's nice not to mess up the source tree.
+ }
+
+ next unless $d->{make} and $d->{cfg};
+
+ my @cfg = (@{$d->{cfg}}, "--prefix=$installDir");
+ print "Running: $bn> $dn/configure ".join(' ',@cfg)."\n";
+ system("$dn/configure", @cfg) and die "Failed to configure in $bn";
+
+ print "Running: $bn> $d->{make}\n";
+ system($d->{make}) and die "Failed to run $d->{make} in $bn";
+ open D, ">$bn.done";
+ close D;
+}
+
+# Second pass, needed because we need to hit gcc twice, before and after building newlib.
+for my $d (@DIRS) {
+ my $fn = "$tarDir/$d->{file}";
+ my $dn = "$srcDir/$d->{dir}";
+ my $bn = "$buildDir/$d->{dir}";
+
+ next unless $d->{make2};
+
+ next if -f "$bn.done2"; # Lazyness ftw.
+ chdir $bn;
+
+ if ($d->{cfg2}) {
+ my @cfg = (@{$d->{cfg2}}, "--prefix=$installDir");
+ print "Running2: $bn> $dn/configure ".join(' ',@cfg)."\n";
+ system("$dn/configure", @cfg) and die "Failed to configure in $bn";
+ }
+ print "Running2: $bn> $d->{make2}\n";
+ system($d->{make2}) and die "Failed to run2 $d->{make2} in $bn";
+ open D, ">$bn.done2";
+ close D;
+}
+
+print "\n\nAll done, toolchain can be found in $installDir\n";
+print "Add to path with: export PATH=\${PATH}:$installDir/bin\n";
+exit 0;
+
diff --git a/toolchain/environment-setup b/toolchain/environment-setup
new file mode 100755
index 0000000..ebac354
--- /dev/null
+++ b/toolchain/environment-setup
@@ -0,0 +1,14 @@
+if [ -z "$ZSH_NAME" ] && [ "x$0" = "x./environment-setup" ]; then
+ echo "Error: This script needs to be sourced. Please run as \". ./environment-setup\""
+ exit 1
+else
+ if [ -n "$BASH_SOURCE" ]; then
+ SCRIPT_PATH="`dirname $BASH_SOURCE`"
+ fi
+ pushd $SCRIPT_PATH
+ SDK_PATH=$PWD
+ popd > /dev/null
+# export PATH=$SDK_PATH/arm-toolchain/bin:$PATH
+ export PATH=/home/deva/pedal2metal.old/tools/arm-toolchain/bin/:$PATH
+fi
+export PS1="\[\e[32;1m\][p2m]\[\e[0m\]:\w> "
diff --git a/toolchain/openocd-0.5.0-fix.patch b/toolchain/openocd-0.5.0-fix.patch
new file mode 100644
index 0000000..2aa4e20
--- /dev/null
+++ b/toolchain/openocd-0.5.0-fix.patch
@@ -0,0 +1,94 @@
+Only in openocd-0.5.0.fixed: config.h
+Only in openocd-0.5.0.fixed: config.log
+Only in openocd-0.5.0.fixed: config.status
+Only in openocd-0.5.0.fixed/doc: Makefile
+Only in openocd-0.5.0.fixed/jimtcl: config.log
+Only in openocd-0.5.0.fixed/jimtcl: configure.gnu
+Only in openocd-0.5.0.fixed/jimtcl: jimautoconf.h
+Only in openocd-0.5.0.fixed/jimtcl: jim-config.h
+Only in openocd-0.5.0.fixed/jimtcl: Makefile
+Only in openocd-0.5.0.fixed: libtool
+Only in openocd-0.5.0.fixed: Makefile
+Only in openocd-0.5.0.fixed/src: .deps
+Only in openocd-0.5.0.fixed/src/flash: .deps
+Only in openocd-0.5.0.fixed/src/flash: Makefile
+Only in openocd-0.5.0.fixed/src/flash/nand: .deps
+Only in openocd-0.5.0.fixed/src/flash/nand: Makefile
+Only in openocd-0.5.0.fixed/src/flash/nor: .deps
+Only in openocd-0.5.0.fixed/src/flash/nor: Makefile
+Only in openocd-0.5.0.fixed/src/helper: .deps
+Only in openocd-0.5.0.fixed/src/helper: Makefile
+Only in openocd-0.5.0.fixed/src/jtag: .deps
+Only in openocd-0.5.0.fixed/src/jtag/drivers: .deps
+Only in openocd-0.5.0.fixed/src/jtag/drivers: Makefile
+Only in openocd-0.5.0.fixed/src/jtag: Makefile
+Only in openocd-0.5.0.fixed/src: Makefile
+Only in openocd-0.5.0.fixed/src/pld: .deps
+Only in openocd-0.5.0.fixed/src/pld: Makefile
+Only in openocd-0.5.0.fixed/src/rtos: .deps
+Only in openocd-0.5.0.fixed/src/rtos: Makefile
+Only in openocd-0.5.0.fixed/src/server: .deps
+Only in openocd-0.5.0.fixed/src/server: Makefile
+Only in openocd-0.5.0.fixed/src/svf: .deps
+Only in openocd-0.5.0.fixed/src/svf: Makefile
+diff -ur openocd-0.5.0/src/target/armv7m.c openocd-0.5.0.fixed/src/target/armv7m.c
+--- openocd-0.5.0/src/target/armv7m.c 2011-08-09 07:34:19.000000000 +0200
++++ openocd-0.5.0.fixed/src/target/armv7m.c 2012-02-12 15:54:04.000000000 +0100
+@@ -254,7 +254,7 @@
+ struct armv7m_common *armv7m = target_to_armv7m(target);
+ int i;
+
+- *reg_list_size = 26;
++ *reg_list_size = 17;
+ *reg_list = malloc(sizeof(struct reg*) * (*reg_list_size));
+
+ /*
+@@ -264,26 +264,11 @@
+ * - (obsolete) FPA status
+ * - CPSR
+ */
+- for (i = 0; i < 16; i++)
++ for (i = 0; i < 17; i++)
+ {
+ (*reg_list)[i] = &armv7m->core_cache->reg_list[i];
+ }
+
+- for (i = 16; i < 24; i++)
+- (*reg_list)[i] = &arm_gdb_dummy_fp_reg;
+- (*reg_list)[24] = &arm_gdb_dummy_fps_reg;
+-
+-#ifdef ARMV7_GDB_HACKS
+- /* use dummy cpsr reg otherwise gdb may try and set the thumb bit */
+- (*reg_list)[25] = &armv7m_gdb_dummy_cpsr_reg;
+-
+- /* ARMV7M is always in thumb mode, try to make GDB understand this
+- * if it does not support this arch */
+- *((char*)armv7m->arm.pc->value) |= 1;
+-#else
+- (*reg_list)[25] = &armv7m->core_cache->reg_list[ARMV7M_xPSR];
+-#endif
+-
+ return ERROR_OK;
+ }
+
+Only in openocd-0.5.0.fixed/src/target: armv7m.c~
+Only in openocd-0.5.0.fixed/src/target: armv7m.c.orig
+diff -ur openocd-0.5.0/src/target/armv7m.h openocd-0.5.0.fixed/src/target/armv7m.h
+--- openocd-0.5.0/src/target/armv7m.h 2011-08-09 07:34:19.000000000 +0200
++++ openocd-0.5.0.fixed/src/target/armv7m.h 2012-02-12 15:53:02.000000000 +0100
+@@ -30,7 +30,7 @@
+ #include "arm.h"
+
+ /* define for enabling armv7 gdb workarounds */
+-#if 1
++#if 0
+ #define ARMV7_GDB_HACKS
+ #endif
+
+Only in openocd-0.5.0.fixed/src/target: .deps
+Only in openocd-0.5.0.fixed/src/target: Makefile
+Only in openocd-0.5.0.fixed/src/transport: .deps
+Only in openocd-0.5.0.fixed/src/transport: Makefile
+Only in openocd-0.5.0.fixed/src/xsvf: .deps
+Only in openocd-0.5.0.fixed/src/xsvf: Makefile
+Only in openocd-0.5.0.fixed: stamp-h1