diff --git a/0001-Adding-windows-support-for-BusPirate.patch b/0001-Adding-windows-support-for-BusPirate.patch
new file mode 100644
index 0000000..a46bb5f
--- /dev/null
+++ b/0001-Adding-windows-support-for-BusPirate.patch
@@ -0,0 +1,254 @@
+From d8db6d57f7c946759478eae88aae554fee4c366e Mon Sep 17 00:00:00 2001
+From: Nicolas "Pixel" Noble <pixel@nobis-crew.org>
+Date: Sat, 22 Jan 2011 03:52:48 +0100
+Subject: [PATCH] Adding windows support for BusPirate.
+
+---
+ src/jtag/drivers/buspirate.c |  135 ++++++++++++++++++++++++++++++++++-------
+ 1 files changed, 112 insertions(+), 23 deletions(-)
+
+diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c
+index 13819ba..d22f0d1 100644
+--- a/src/jtag/drivers/buspirate.c
++++ b/src/jtag/drivers/buspirate.c
+@@ -25,9 +25,13 @@
+ #include <jtag/interface.h>
+ #include <jtag/commands.h>
+ 
++#ifdef WIN32
++#include <windows.h>
++#else
+ #include <termios.h>
+ #include <fcntl.h>
+ #include <sys/ioctl.h>
++#endif
+ 
+ #undef DEBUG_SERIAL
+ /*#define DEBUG_SERIAL */
+@@ -80,7 +84,14 @@ enum {
+ };
+ 
+ 
+-static int buspirate_fd = -1;
++#ifdef WIN32
++typedef HANDLE fdt;
++#define fdtinvalid INVALID_HANDLE_VALUE
++#else
++typedef int fdt;
++#define fdtinvalid -1
++#endif
++static fdt buspirate_fd = fdtinvalid;
+ static int buspirate_pinmode = MODE_JTAG_OD;
+ static int buspirate_baudrate = SERIAL_NORMAL;
+ static int buspirate_vreg;
+@@ -99,20 +110,20 @@ static void buspirate_tap_make_space(int scan, int bits);
+ static void buspirate_reset(int trst, int srst);
+ 
+ /* low level interface */
+-static void buspirate_jtag_reset(int);
+-static void buspirate_jtag_enable(int);
+-static unsigned char buspirate_jtag_command(int, char *, int);
+-static void buspirate_jtag_set_speed(int, char);
+-static void buspirate_jtag_set_mode(int, char);
+-static void buspirate_jtag_set_feature(int, char, char);
+-static void buspirate_jtag_get_adcs(int);
++static void buspirate_jtag_reset(fdt fd);
++static void buspirate_jtag_enable(fdt fd);
++static unsigned char buspirate_jtag_command(fdt fd, char *, int);
++static void buspirate_jtag_set_speed(fdt fd, char);
++static void buspirate_jtag_set_mode(fdt fd, char);
++static void buspirate_jtag_set_feature(fdt fd, char, char);
++static void buspirate_jtag_get_adcs(fdt fd);
+ 
+ /* low level HW communication interface */
+-static int buspirate_serial_open(char *port);
+-static int buspirate_serial_setspeed(int fd, char speed);
+-static int buspirate_serial_write(int fd, char *buf, int size);
+-static int buspirate_serial_read(int fd, char *buf, int size);
+-static void buspirate_serial_close(int fd);
++static fdt buspirate_serial_open(char *port);
++static int buspirate_serial_setspeed(fdt fd, char speed);
++static int buspirate_serial_write(fdt fd, char *buf, int size);
++static int buspirate_serial_read(fdt fd, char *buf, int size);
++static void buspirate_serial_close(fdt fd);
+ static void buspirate_print_buffer(char *buf, int size);
+ 
+ static int buspirate_speed(int speed)
+@@ -217,7 +228,7 @@ static int buspirate_init(void)
+ 	}
+ 
+ 	buspirate_fd = buspirate_serial_open(buspirate_port);
+-	if (buspirate_fd == -1) {
++	if (buspirate_fd == fdtinvalid) {
+ 		LOG_ERROR("Could not open serial port.");
+ 		return ERROR_JTAG_INIT_FAILED;
+ 	}
+@@ -267,7 +278,7 @@ COMMAND_HANDLER(buspirate_handle_adc_command)
+ 		return ERROR_OK;
+ 	}
+ 
+-	if (buspirate_fd == -1)
++	if (buspirate_fd == fdtinvalid)
+ 		return ERROR_OK;
+ 
+ 	/* send the command */
+@@ -703,7 +714,7 @@ static void buspirate_reset(int trst, int srst)
+ }
+ 
+ /*************** jtag lowlevel functions ********************/
+-static void buspirate_jtag_enable(int fd)
++static void buspirate_jtag_enable(fdt fd)
+ {
+ 	int ret;
+ 	char tmp[21] = { [0 ... 20] = 0x00 };
+@@ -750,7 +761,7 @@ static void buspirate_jtag_enable(int fd)
+ 
+ }
+ 
+-static void buspirate_jtag_reset(int fd)
++static void buspirate_jtag_reset(fdt fd)
+ {
+ 	int ret;
+ 	char tmp[5];
+@@ -766,7 +777,7 @@ static void buspirate_jtag_reset(int fd)
+ 		LOG_ERROR("Bad reply :( Please restart manually");
+ }
+ 
+-static void buspirate_jtag_set_speed(int fd, char speed)
++static void buspirate_jtag_set_speed(fdt fd, char speed)
+ {
+ 	int ret;
+ 	char tmp[2];
+@@ -799,7 +810,7 @@ static void buspirate_jtag_set_speed(int fd, char speed)
+ }
+ 
+ 
+-static void buspirate_jtag_set_mode(int fd, char mode)
++static void buspirate_jtag_set_mode(fdt fd, char mode)
+ {
+ 	char tmp[2];
+ 	tmp[0] = CMD_PORT_MODE;
+@@ -807,7 +818,7 @@ static void buspirate_jtag_set_mode(int fd, char mode)
+ 	buspirate_jtag_command(fd, tmp, 2);
+ }
+ 
+-static void buspirate_jtag_set_feature(int fd, char feat, char action)
++static void buspirate_jtag_set_feature(fdt fd, char feat, char action)
+ {
+ 	char tmp[3];
+ 	tmp[0] = CMD_FEATURE;
+@@ -816,7 +827,7 @@ static void buspirate_jtag_set_feature(int fd, char feat, char action)
+ 	buspirate_jtag_command(fd, tmp, 3);
+ }
+ 
+-static void buspirate_jtag_get_adcs(int fd)
++static void buspirate_jtag_get_adcs(fdt fd)
+ {
+ 	uint8_t tmp[10];
+ 	uint16_t a, b, c, d;
+@@ -833,7 +844,7 @@ static void buspirate_jtag_get_adcs(int fd)
+ 		((float)c)/155.1515, ((float)d)/155.1515);
+ }
+ 
+-static unsigned char buspirate_jtag_command(int fd,
++static unsigned char buspirate_jtag_command(fdt fd,
+ 		char *cmd, int cmdlen)
+ {
+ 	int res;
+@@ -869,7 +880,84 @@ static unsigned char buspirate_jtag_command(int fd,
+ }
+ 
+ /* low level serial port */
+-/* TODO add support for WIN32 and others ! */
++#ifdef WIN32
++static HANDLE buspirate_serial_open(char *port)
++{
++	return CreateFile(port, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
++}
++
++static int buspirate_serial_setspeed(HANDLE fd, char speed)
++{
++	DCB dcbSerialParams;
++	dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
++	if (!GetCommState(fd, &dcbSerialParams))
++		return -1;
++
++	dcbSerialParams.BaudRate = (speed == SERIAL_FAST) ? CBR_256000 : CBR_115200;
++	dcbSerialParams.ByteSize = 8;
++	dcbSerialParams.StopBits = ONESTOPBIT;
++	dcbSerialParams.Parity = NOPARITY;
++
++	if (!SetCommState(fd, &dcbSerialParams))
++		return -1;
++
++	return 0;
++}
++
++static int buspirate_serial_write(HANDLE fd, char *buf, int size)
++{
++	DWORD in = size, ret = 0;
++
++	if (!WriteFile(fd, buf, in, &ret, NULL)) {
++		LOG_ERROR("Error sending data");
++		ret = 0;
++	}
++
++	LOG_DEBUG("size = %d ret = %u", size, (unsigned int) ret);
++	buspirate_print_buffer(buf, size);
++
++	if (ret != (unsigned int) size)
++		LOG_ERROR("Error sending data");
++
++	return ret;
++}
++
++static int buspirate_serial_read(HANDLE fd, char *buf, int size)
++{
++	DWORD len = 0;
++	DWORD ret = 0;
++	int timeout = 0;
++
++	while (len < (unsigned int) size) {
++		if (!ReadFile(fd, buf + len, size - len, &ret, NULL))
++			return -1;
++
++		if (ret == 0) {
++			timeout++;
++
++			if (timeout >= 10)
++				break;
++
++			continue;
++		}
++
++		len += ret;
++	}
++
++	LOG_DEBUG("should have read = %d actual size = %u", size, (unsigned int) len);
++	buspirate_print_buffer(buf, len);
++
++	if (len != (unsigned int) size)
++		LOG_ERROR("Error receiving data");
++
++	return len;
++}
++
++static void buspirate_serial_close(HANDLE fd)
++{
++	CloseHandle(fd);
++}
++#else
+ static int buspirate_serial_open(char *port)
+ {
+ 	int fd;
+@@ -954,6 +1042,7 @@ static void buspirate_serial_close(int fd)
+ {
+ 	close(fd);
+ }
++#endif
+ 
+ #define LINE_SIZE      81
+ #define BYTES_PER_LINE 16
+-- 
+1.7.2.3
+
diff --git a/freertos-newlib.patch b/freertos-newlib.patch
new file mode 100644
index 0000000..4ee02fc
--- /dev/null
+++ b/freertos-newlib.patch
@@ -0,0 +1,246 @@
+diff -ur newlib-1.18.0/newlib/libc/include/locale.h newlib-1.18.0-patched/newlib/libc/include/locale.h
+--- newlib-1.18.0/newlib/libc/include/locale.h	2009-06-16 21:45:17.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/include/locale.h	2011-01-19 19:55:58.000000000 +0100
+@@ -51,10 +51,8 @@
+   char int_p_sign_posn;
+ };
+ 
+-#ifndef _REENT_ONLY
+ char *_EXFUN(setlocale,(int category, const char *locale));
+ struct lconv *_EXFUN(localeconv,(void));
+-#endif
+ 
+ struct _reent;
+ char *_EXFUN(_setlocale_r,(struct _reent *, int category, const char *locale));
+Only in newlib-1.18.0-patched/newlib/libc/include: locale.h.orig
+diff -ur newlib-1.18.0/newlib/libc/include/reent.h newlib-1.18.0-patched/newlib/libc/include/reent.h
+--- newlib-1.18.0/newlib/libc/include/reent.h	2009-08-12 20:22:38.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/include/reent.h	2011-01-19 19:49:19.000000000 +0100
+@@ -92,6 +92,7 @@
+ 
+ #include <sys/reent.h>
+ #include <sys/_types.h>
++#include <sys/types.h>
+ #include <machine/types.h>
+ 
+ #define __need_size_t
+@@ -147,7 +148,7 @@
+ extern int _kill_r _PARAMS ((struct _reent *, int, int));
+ extern int _link_r _PARAMS ((struct _reent *, const char *, const char *));
+ extern _off_t _lseek_r _PARAMS ((struct _reent *, int, _off_t, int));
+-extern int _mkdir_r _PARAMS ((struct _reent *, const char *, int));
++extern int _mkdir_r _PARAMS ((struct _reent *, const char *, mode_t));
+ extern int _open_r _PARAMS ((struct _reent *, const char *, int, int));
+ extern _ssize_t _read_r _PARAMS ((struct _reent *, int, void *, size_t));
+ extern int _rename_r _PARAMS ((struct _reent *, const char *, const char *));
+diff -ur newlib-1.18.0/newlib/libc/include/sys/config.h newlib-1.18.0-patched/newlib/libc/include/sys/config.h
+--- newlib-1.18.0/newlib/libc/include/sys/config.h	2009-12-10 18:12:11.000000000 +0100
++++ newlib-1.18.0-patched/newlib/libc/include/sys/config.h	2011-01-19 19:55:07.000000000 +0100
+@@ -140,6 +140,15 @@
+ #define _REENT_SMALL
+ #endif /* __m32c__ */
+ 
++/* For github.com/hugovincent/mbed-freertos */
++#if defined(__thumb__) || defined(__thumb2__) || defined(__arm__)
++#define __DYNAMIC_REENT__
++#define _REENT_SMALL
++#define MALLOC_ALIGNMENT 8
++#define __FILENAME_MAX__ 64
++#define _READ_WRITE_RETURN_TYPE _ssize_t
++#endif
++
+ #ifdef __SPU__
+ #define MALLOC_ALIGNMENT 16
+ #define __CUSTOM_FILE_IO__
+Only in newlib-1.18.0-patched/newlib/libc/include/sys: config.h.orig
+diff -ur newlib-1.18.0/newlib/libc/include/sys/errno.h newlib-1.18.0-patched/newlib/libc/include/sys/errno.h
+--- newlib-1.18.0/newlib/libc/include/sys/errno.h	2009-12-16 20:33:10.000000000 +0100
++++ newlib-1.18.0-patched/newlib/libc/include/sys/errno.h	2011-01-19 19:55:33.000000000 +0100
+@@ -10,10 +10,8 @@
+ 
+ #include <sys/reent.h>
+ 
+-#ifndef _REENT_ONLY
+ #define errno (*__errno())
+ extern int *__errno _PARAMS ((void));
+-#endif
+ 
+ /* Please don't use these variables directly.
+    Use strerror instead. */
+Only in newlib-1.18.0-patched/newlib/libc/include/sys: errno.h.orig
+diff -ur newlib-1.18.0/newlib/libc/include/sys/features.h newlib-1.18.0-patched/newlib/libc/include/sys/features.h
+--- newlib-1.18.0/newlib/libc/include/sys/features.h	2009-07-06 20:59:04.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/include/sys/features.h	2011-01-19 19:49:19.000000000 +0100
+@@ -180,6 +180,13 @@
+ #endif /* !__STRICT_ANSI__ || __cplusplus || __STDC_VERSION__ >= 199901L */
+ #endif /* __CYGWIN__ */
+ 
++/* For github.com/hugovincent/mbed-freertos */
++#if defined(__thumb__) || defined(__thumb2__) || defined(__arm__)
++#define _POSIX_TIMERS					1
++#define _POSIX_MONOTONIC_CLOCK			200112L
++#define _POSIX_REALTIME_SIGNALS			1
++#endif
++
+ #ifdef __cplusplus
+ }
+ #endif
+Only in newlib-1.18.0-patched/newlib/libc/include/sys: features.h.orig
+diff -ur newlib-1.18.0/newlib/libc/include/sys/reent.h newlib-1.18.0-patched/newlib/libc/include/sys/reent.h
+--- newlib-1.18.0/newlib/libc/include/sys/reent.h	2009-12-17 20:43:43.000000000 +0100
++++ newlib-1.18.0-patched/newlib/libc/include/sys/reent.h	2011-01-19 19:49:19.000000000 +0100
+@@ -66,7 +66,7 @@
+  * atexit() support.
+  */
+ 
+-#define	_ATEXIT_SIZE 32	/* must be at least 32 to guarantee ANSI conformance */
++#define	_ATEXIT_SIZE 4	/* must be at least 32 to guarantee ANSI conformance, but here for FreeRTOS, 4 should suffice */
+ 
+ struct _on_exit_args {
+ 	void *  _fnargs[_ATEXIT_SIZE];	        /* user fn args */
+@@ -821,8 +821,6 @@
+ 
+ /* #define _REENT_ONLY define this to get only reentrant routines */
+ 
+-#ifndef _REENT_ONLY
+-
+ #if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__)
+ #ifndef __getreent
+   struct _reent * _EXFUN(__getreent, (void));
+@@ -832,8 +830,6 @@
+ # define _REENT _impure_ptr
+ #endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */
+ 
+-#endif /* !_REENT_ONLY */
+-
+ #define _GLOBAL_REENT _global_impure_ptr
+ 
+ #ifdef __cplusplus
+Only in newlib-1.18.0-patched/newlib/libc/include/sys: reent.h.orig
+diff -ur newlib-1.18.0/newlib/libc/include/sys/signal.h newlib-1.18.0-patched/newlib/libc/include/sys/signal.h
+--- newlib-1.18.0/newlib/libc/include/sys/signal.h	2009-10-13 19:31:49.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/include/sys/signal.h	2011-01-19 19:49:19.000000000 +0100
+@@ -14,6 +14,13 @@
+ 
+ typedef unsigned long sigset_t;
+ 
++/* Temporary hack to get the signal includes in FreeRTOS */
++#if defined(__arm__) || defined(__thumb__) || defined(__thumb2__)
++#define FREERTOS_SIGNAL_HACK
++#define __rtems__
++#include <sys/types.h>
++#endif
++
+ #if defined(__rtems__)
+ 
+ #if defined(_POSIX_REALTIME_SIGNALS)
+@@ -80,7 +87,7 @@
+  *      application should not use both simultaneously.
+  */
+ 
+-typedef void (*_sig_func_ptr)();
++typedef void (*_sig_func_ptr)(int);
+ 
+ struct sigaction {
+   int         sa_flags;       /* Special flags to affect behavior of signal */
+@@ -298,6 +305,10 @@
+ #endif
+ #endif
+ 
++#if defined(FREERTOS_SIGNAL_HACK)
++#undef __rtems__
++#endif
++
+ #ifdef __cplusplus
+ }
+ #endif
+Only in newlib-1.18.0-patched/newlib/libc/include/sys: signal.h.orig
+diff -ur newlib-1.18.0/newlib/libc/locale/locale.c newlib-1.18.0-patched/newlib/libc/locale/locale.c
+--- newlib-1.18.0/newlib/libc/locale/locale.c	2009-10-09 10:25:28.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/locale/locale.c	2011-01-19 19:49:19.000000000 +0100
+@@ -776,8 +776,6 @@
+   return (struct lconv *) &lconv;
+ }
+ 
+-#ifndef _REENT_ONLY
+-
+ #ifndef __CYGWIN__
+ char *
+ _DEFUN(setlocale, (category, locale),
+@@ -794,4 +792,3 @@
+   return _localeconv_r (_REENT);
+ }
+ 
+-#endif
+Only in newlib-1.18.0-patched/newlib/libc/locale: locale.c.orig
+diff -ur newlib-1.18.0/newlib/libc/signal/Makefile.am newlib-1.18.0-patched/newlib/libc/signal/Makefile.am
+--- newlib-1.18.0/newlib/libc/signal/Makefile.am	2006-04-11 21:02:09.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/signal/Makefile.am	2011-01-19 19:49:19.000000000 +0100
+@@ -4,7 +4,7 @@
+ 
+ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+ 
+-LIB_SOURCES = raise.c signal.c
++LIB_SOURCES = signal.c
+ 
+ libsignal_la_LDFLAGS = -Xcompiler -nostdlib
+ 
+@@ -21,7 +21,7 @@
+ 
+ include $(srcdir)/../../Makefile.shared
+ 
+-CHEWOUT_FILES = raise.def signal.def
++CHEWOUT_FILES = signal.def
+ 
+ SUFFIXES = .def
+ 
+diff -ur newlib-1.18.0/newlib/libc/signal/Makefile.in newlib-1.18.0-patched/newlib/libc/signal/Makefile.in
+--- newlib-1.18.0/newlib/libc/signal/Makefile.in	2009-10-21 00:44:09.000000000 +0200
++++ newlib-1.18.0-patched/newlib/libc/signal/Makefile.in	2011-01-19 19:49:19.000000000 +0100
+@@ -55,12 +55,12 @@
+ ARFLAGS = cru
+ lib_a_AR = $(AR) $(ARFLAGS)
+ lib_a_LIBADD =
+-am__objects_1 = lib_a-raise.$(OBJEXT) lib_a-signal.$(OBJEXT)
++am__objects_1 = lib_a-signal.$(OBJEXT)
+ @USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1)
+ lib_a_OBJECTS = $(am_lib_a_OBJECTS)
+ LTLIBRARIES = $(noinst_LTLIBRARIES)
+ libsignal_la_LIBADD =
+-am__objects_2 = raise.lo signal.lo
++am__objects_2 = signal.lo
+ @USE_LIBTOOL_TRUE@am_libsignal_la_OBJECTS = $(am__objects_2)
+ libsignal_la_OBJECTS = $(am_libsignal_la_OBJECTS)
+ libsignal_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+@@ -225,7 +225,7 @@
+ top_srcdir = @top_srcdir@
+ AUTOMAKE_OPTIONS = cygnus
+ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+-LIB_SOURCES = raise.c signal.c
++LIB_SOURCES = signal.c
+ libsignal_la_LDFLAGS = -Xcompiler -nostdlib
+ @USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libsignal.la
+ @USE_LIBTOOL_TRUE@libsignal_la_SOURCES = $(LIB_SOURCES)
+@@ -234,7 +234,7 @@
+ @USE_LIBTOOL_FALSE@noinst_LIBRARIES = lib.a
+ @USE_LIBTOOL_FALSE@lib_a_SOURCES = $(LIB_SOURCES)
+ @USE_LIBTOOL_FALSE@lib_a_CFLAGS = $(AM_CFLAGS)
+-CHEWOUT_FILES = raise.def signal.def
++CHEWOUT_FILES = signal.def
+ SUFFIXES = .def
+ CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str
+ TARGETDOC = ../tmp.texi
+@@ -307,12 +307,6 @@
+ .c.lo:
+ 	$(LTCOMPILE) -c -o $@ $<
+ 
+-lib_a-raise.o: raise.c
+-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-raise.o `test -f 'raise.c' || echo '$(srcdir)/'`raise.c
+-
+-lib_a-raise.obj: raise.c
+-	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-raise.obj `if test -f 'raise.c'; then $(CYGPATH_W) 'raise.c'; else $(CYGPATH_W) '$(srcdir)/raise.c'; fi`
+-
+ lib_a-signal.o: signal.c
+ 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-signal.o `test -f 'signal.c' || echo '$(srcdir)/'`signal.c
+ 
+Only in newlib-1.18.0-patched/newlib/libc/signal: Makefile.in.orig
diff --git a/gcc.patch b/gcc.patch
new file mode 100644
index 0000000..312def9
--- /dev/null
+++ b/gcc.patch
@@ -0,0 +1,12 @@
+diff -ur gcc-linaro-4.5-2010.11-1/gcc/config/arm/lib1funcs.asm gcc-linaro-4.5-2010.11-1-patched/gcc/config/arm/lib1funcs.asm
+--- gcc-linaro-4.5-2010.11-1/gcc/config/arm/lib1funcs.asm	2010-11-08 23:11:38.000000000 +0100
++++ gcc-linaro-4.5-2010.11-1-patched/gcc/config/arm/lib1funcs.asm	2011-01-19 23:20:14.000000000 +0100
+@@ -113,6 +113,8 @@
+ #error Unable to determine architecture.
+ #endif
+ 
++#undef __OPTIMIZE_SIZE__
++
+ /* There are times when we might prefer Thumb1 code even if ARM code is
+    permitted, for example, the code might be smaller, or there might be
+    interworking problems with switching to ARM state if interworking is
diff --git a/summon-arm-toolchain b/summon-arm-toolchain
index d77d3a5..1899256 100755
--- a/summon-arm-toolchain
+++ b/summon-arm-toolchain
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -x
 # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
 # Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
 
@@ -19,10 +19,10 @@ set -e
 # You probably want to customize those
 ##############################################################################
 TARGET=arm-none-eabi		# Or: TARGET=arm-elf
-PREFIX=${HOME}/sat	# Install location of your final toolchain
+PREFIX=/usr/local	# Install location of your final toolchain
 DARWIN_OPT_PATH=/opt/local	# Path in which MacPorts or Fink is installed
 # Set to 'sudo' if you need superuser privileges while installing
-SUDO=
+SUDO=sudo
 # Set to 1 to be quieter while running
 QUIET=0
 # Set to 1 to use linaro gcc instead of the FSF gcc
@@ -34,7 +34,9 @@ LIBSTM32_EN=0
 # Set to 1 to build libopenstm32 an open source library for stm32
 LIBOPENSTM32_EN=1
 # Make the gcc default to Cortex-M3
-DEFAULT_TO_CORTEX_M3=0
+DEFAULT_TO_CORTEX_M3=1
+# Build for a second host - mingw32
+SECOND_HOST=i586-mingw32msvc
 
 ##############################################################################
 # Version and download url settings section
@@ -83,6 +85,8 @@ else
 	GCCFLAGS="--with-arch=armv7-m --with-mode=thumb --with-float=soft"
 fi
 
+GCCFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections -fomit-frame-pointer -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -g -Os -fshort-wchar -fno-unroll-loops -mabi=aapcs"
+
 # Pull in the local configuration, if any
 if [ -f local.sh ]; then
     . ./local.sh
@@ -201,11 +205,11 @@ if [ ! -e openocd-${OOCD}.tar.bz2 ]; then
 	log "Cloning OpenOCD sources..."
 	git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd openocd-${OOCD}
         cd openocd-${OOCD}
+        git am ../../0001-Adding-windows-support-for-BusPirate.patch
 	./bootstrap
+	rm -rf .git
 	cd ..
 	tar cfvj openocd-${OOCD}.tar.bz2 openocd-${OOCD}
-        #git archive --format=tar --prefix=openocd-${OOCD}/ ${OOCD} | \
-        #    bzip2 --stdout > ../openocd-${OOCD}.tar.bz2
         rm -rf openocd-${OOCD}
 fi
 fi
@@ -255,14 +259,11 @@ fi
 fi
 
 cd ${SUMMON_DIR}
-
-if [ ! -e build ]; then
-    mkdir build
-fi
-
 if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
     unpack ${BINUTILS}
-    cd build
+    rm -rf build-${BINUTILS}
+    mkdir -p build-${BINUTILS}
+    cd build-${BINUTILS}
     log "Configuring ${BINUTILS}"
     ../${BINUTILS}/configure --target=${TARGET} \
                            --prefix=${PREFIX} \
@@ -272,19 +273,48 @@ if [ ! -e ${STAMPS}/${BINUTILS}.build ]; then
                            --with-gnu-ld \
                            --disable-nls \
                            --disable-werror \
-			   ${BINUTILFLAGS}
+                          ${BINUTILFLAGS}
     log "Building ${BINUTILS}"
     make ${MAKEFLAGS}
     install ${BINUTILS} install
     cd ..
-    log "Cleaning up ${BINUTILS}"
     touch ${STAMPS}/${BINUTILS}.build
-    rm -rf build/* ${BINUTILS}
 fi
 
+cd ${SUMMON_DIR}
+if [ ${SECOND_HOST} != "" ]; then
+if [ ! -e ${STAMPS}/${BINUTILS}.build.${SECOND_HOST} ]; then
+    unpack ${BINUTILS}
+    rm -rf build-${BINUTILS}.${SECOND_HOST}
+    mkdir -p build-${BINUTILS}.${SECOND_HOST}
+    cd build-${BINUTILS}.${SECOND_HOST}
+    log "Configuring ${BINUTILS}"
+    ../${BINUTILS}/configure --target=${TARGET} \
+                           --host=${SECOND_HOST} \
+                           --prefix=${PREFIX} \
+                           --enable-interwork \
+                           --enable-multilib \
+                           --with-gnu-as \
+                           --with-gnu-ld \
+                           --disable-nls \
+                           --disable-werror \
+                          ${BINUTILFLAGS}
+    log "Building ${BINUTILS}"
+    make ${MAKEFLAGS}
+    make install prefix=${SUMMON_DIR}/${SECOND_HOST}
+    cd ..
+    touch ${STAMPS}/${BINUTILS}.build.${SECOND_HOST}
+fi
+fi
+
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
     unpack ${GCC} boot
-    cd build
+    cd ${GCC}
+    patch -p 1 < ../gcc.patch
+    cd ..
+    mkdir -p build-${GCC}-boot
+    cd build-${GCC}-boot
     log "Configuring ${GCC}-boot"
     ../${GCC}/configure --target=${TARGET} \
                       --prefix=${PREFIX} \
@@ -298,20 +328,35 @@ if [ ! -e ${STAMPS}/${GCC}-boot.build ]; then
                       --with-gnu-ld \
                       --disable-nls \
                       --disable-werror \
-		      --with-system-zlib \
-		      ${GCCFLAGS}
+                      --with-system-zlib \
+                      --disable-libssp \
+                      --enable-target-optspace \
+                      --disable-threads \
+                      --disable-libmudflap \
+                      --disable-libgomp \
+                      --disable-libstdcxx-pch \
+                      --disable-libunwind-exceptions \
+                      --disable-libffi \
+                      --enable-extra-sgxxlite-multilibs \
+                      --enable-libstdcxx-allocator=malloc \
+                      --disable-lto \
+                     ${GCCFLAGS}
     log "Building ${GCC}-boot"
-    make ${MAKEFLAGS} all-gcc
+    make ${MAKEFLAGS} all-gcc CFLAGS_FOR_TARGET="${GCCFLAGS_FOR_TARGET}"
     install ${GCC}-boot install-gcc
     cd ..
     log "Cleaning up ${GCC}-boot"
     touch ${STAMPS}/${GCC}-boot.build
-    rm -rf build/* ${GCC}
 fi
 
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
     unpack ${NEWLIB}
-    cd build
+    cd ${NEWLIB}
+    patch -p 1 < ../freertos-newlib.patch
+    cd ..
+    mkdir -p build-${NEWLIB}
+    cd build-${NEWLIB}
     log "Configuring ${NEWLIB}"
     ../${NEWLIB}/configure --target=${TARGET} \
                          --prefix=${PREFIX} \
@@ -322,20 +367,36 @@ if [ ! -e ${STAMPS}/${NEWLIB}.build ]; then
                          --disable-nls \
                          --disable-werror \
                          --disable-newlib-supplied-syscalls \
-			 --with-float=soft
+                         --disable-libgloss \
+                         --disable-shared \
+                         --enable-newlib-io-long-long \
+                         --enable-target-optspace \
+                         --enable-newlib-multithread \
+                         --enable-newlib-reent-small \
+                         --disable-newlib-atexit-alloc \
+                         --with-float=soft
     log "Building ${NEWLIB}"
-    make ${MAKEFLAGS} CFLAGS_FOR_TARGET="-msoft-float" CCASFLAGS="-msoft-float"
+    NEWLIB_FLAGS="-ffunction-sections -fdata-sections -DPREFER_SIZE_OVER_SPEED -msoft-float"
+    NEWLIB_FLAGS="${NEWLIB_FLAGS} -D__OPTIMIZE_SIZE__ -g -Os -fomit-frame-pointer -fno-unroll-loops"
+    NEWLIB_FLAGS="${NEWLIB_FLAGS} -D__BUFSIZ__=128 -mabi=aapcs -DSMALL_MEMORY -fshort-wchar"
+    NEWLIB_FLAGS="${NEWLIB_FLAGS} -DREENTRANT_SYSCALLS_PROVIDED -D_REENT_ONLY -DSIGNAL_PROVIDED"
+    NEWLIB_FLAGS="${NEWLIB_FLAGS} -DHAVE_NANOSLEEP -DHAVE_FCNTL -DHAVE_RENAME -D_NO_GETLOGIN"
+    NEWLIB_FLAGS="${NEWLIB_FLAGS} -D_NO_GETPWENT -D_NO_GETUT -D_NO_GETPASS -D_NO_SIGSET"
+    make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${NEWLIB_FLAGS}" CCASFLAGS="${NEWLIB_FLAGS}"
     install ${NEWLIB} install
+    if [ ${SECOND_HOST} != "" ]; then
+        make install prefix=${SUMMON_DIR}/${SECOND_HOST}
+    fi
     cd ..
-    log "Cleaning up ${NEWLIB}"
     touch ${STAMPS}/${NEWLIB}.build
-    rm -rf build/* ${NEWLIB}
 fi
 
 # Yes, you need to build gcc again!
+# because now we have the libc headers to build more stuff, including libstdc++
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/${GCC}.build ]; then
-    unpack ${GCC}
-    cd build
+    mkdir -p build-${GCC}
+    cd build-${GCC}
     log "Configuring ${GCC}"
     ../${GCC}/configure --target=${TARGET} \
                       --prefix=${PREFIX} \
@@ -343,25 +404,79 @@ if [ ! -e ${STAMPS}/${GCC}.build ]; then
                       --enable-multilib \
                       --enable-languages="c,c++" \
                       --with-newlib \
+                      --without-headers \
                       --disable-shared \
                       --with-gnu-as \
                       --with-gnu-ld \
-		      --disable-nls \
+                      --disable-nls \
                       --disable-werror \
                       --with-system-zlib \
-	 	     ${GCCFLAGS}
+                      --disable-libssp \
+                      --enable-target-optspace \
+                      --disable-threads \
+                      --disable-libmudflap \
+                      --disable-libgomp \
+                      --disable-libstdcxx-pch \
+                      --disable-libunwind-exceptions \
+                      --disable-libffi \
+                      --enable-extra-sgxxlite-multilibs \
+                      --enable-libstdcxx-allocator=malloc \
+                      --disable-lto \
+                      --enable-cxx-flags="${GCCFLAGS_FOR_TARGET}" \
+                     ${GCCFLAGS}
     log "Building ${GCC}"
-    make ${MAKEFLAGS}
+    make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${GCCFLAGS_FOR_TARGET}"
     install ${GCC} install
     cd ..
-    log "Cleaning up ${GCC}"
     touch ${STAMPS}/${GCC}.build
-    rm -rf build/* ${GCC}
 fi
 
+cd ${SUMMON_DIR}
+if [ ${SECOND_HOST} != "" ]; then
+if [ ! -e ${STAMPS}/${GCC}.build.${SECOND_HOST} ]; then
+    mkdir -p build-${GCC}.${SECOND_HOST}
+    cd build-${GCC}.${SECOND_HOST}
+    log "Configuring ${GCC}"
+    ../${GCC}/configure --target=${TARGET} \
+                      --host=${SECOND_HOST} \
+                      --prefix=${PREFIX} \
+                      --enable-interwork \
+                      --enable-multilib \
+                      --enable-languages="c,c++" \
+                      --with-newlib \
+                      --without-headers \
+                      --disable-shared \
+                      --with-gnu-as \
+                      --with-gnu-ld \
+                      --disable-nls \
+                      --disable-werror \
+                      --with-system-zlib \
+                      --disable-libssp \
+                      --enable-target-optspace \
+                      --disable-threads \
+                      --disable-libmudflap \
+                      --disable-libgomp \
+                      --disable-libstdcxx-pch \
+                      --disable-libunwind-exceptions \
+                      --disable-libffi \
+                      --enable-extra-sgxxlite-multilibs \
+                      --enable-libstdcxx-allocator=malloc \
+                      --disable-lto \
+                      --enable-cxx-flags="${GCCFLAGS_FOR_TARGET}" \
+                     ${GCCFLAGS}
+    log "Building ${GCC}"
+    make ${MAKEFLAGS} CFLAGS_FOR_TARGET="${GCCFLAGS_FOR_TARGET}"
+    make install prefix=${SUMMON_DIR}/${SECOND_HOST}
+    cd ..
+    touch ${STAMPS}/${GCC}.build.${SECOND_HOST}
+fi
+fi
+
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/${GDB}.build ]; then
     unpack ${GDB}
-    cd build
+    mkdir -p build-${GDB}
+    cd build-${GDB}
     log "Configuring ${GDB}"
     ../${GDB}/configure --target=${TARGET} \
                       --prefix=${PREFIX} \
@@ -373,15 +488,37 @@ if [ ! -e ${STAMPS}/${GDB}.build ]; then
     make ${MAKEFLAGS}
     install ${GDB} install
     cd ..
-    log "Cleaning up ${GDB}"
     touch ${STAMPS}/${GDB}.build
-    rm -rf build/* ${GDB}
+fi
+
+cd ${SUMMON_DIR}
+if [ ${SECOND_HOST} != "" ]; then
+if [ ! -e ${STAMPS}/${GDB}.build.${SECOND_HOST} ]; then
+    unpack ${GDB}
+    mkdir -p build-${GDB}.${SECOND_HOST}
+    cd build-${GDB}.${SECOND_HOST}
+    log "Configuring ${GDB}"
+    ../${GDB}/configure --target=${TARGET} \
+                      --host=${SECOND_HOST} \
+                      --prefix=${PREFIX} \
+                      --enable-interwork \
+                      --enable-multilib \
+                      --disable-werror \
+		      ${GDBFLAGS}
+    log "Building ${GDB}"
+    make ${MAKEFLAGS}
+    make install prefix=${SUMMON_DIR}/${SECOND_HOST}
+    cd ..
+    touch ${STAMPS}/${GDB}.build.${SECOND_HOST}
+fi
 fi
 
 if [ ${OOCD_EN} != 0 ]; then
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
     unpack openocd-${OOCD}
-    cd build
+    mkdir build-${OOCD}
+    cd build-${OOCD}
     log "Configuring openocd-${OOCD}"
     CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
     LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
@@ -407,60 +544,105 @@ if [ ! -e ${STAMPS}/openocd-${OOCD}.build ]; then
     make ${MAKEFLAGS}
     install openocd-${OOCD} install
     cd ..
-    log "Cleaning up openocd-${OOCD}"
     touch ${STAMPS}/openocd-${OOCD}.build
-    rm -rf build/* ${OOCD}
+fi
+
+if [ ${SECOND_HOST} != "" ]; then
+cd ${SUMMON_DIR}
+if [ ! -e ${STAMPS}/openocd-${OOCD}.build.${SECOND_HOST} ]; then
+    mkdir build-${OOCD}.${SECOND_HOST}
+    cd build-${OOCD}.${SECOND_HOST}
+    log "Configuring openocd-${OOCD}"
+    CFLAGS="${CFLAGS} ${OOCD_CFLAGS}" \
+    LDFLAGS="${LDFLAGS} ${OOCD_LDFLAGS}" \
+    ../openocd-${OOCD}/configure --enable-maintainer-mode \
+                      --host=${SECOND_HOST} \
+                      --prefix=${PREFIX} \
+                      --enable-dummy \
+		      --enable-parport \
+		      --disable-ft2232_libftdi \
+		      --disable-usb_blaster_libftdi \
+		      --enable-amtjtagaccel \
+		      --disable-zy1000 \
+		      --enable-ep93xx \
+		      --enable-at91rm9200 \
+		      --enable-gw16012 \
+		      --disable-presto_libftdi \
+		      --enable-usbprog \
+		      --enable-jlink \
+		      --enable-vsllink \
+		      --enable-rlink \
+		      --enable-arm-jtag-ew \
+		      --enable-buspirate
+    log "Building openocd-${OOCD}"
+    make ${MAKEFLAGS}
+    make install prefix=${SUMMON_DIR}/${SECOND_HOST}
+    cd ..
+    touch ${STAMPS}/openocd-${OOCD}.build.${SECOND_HOST}
+fi
 fi
 fi
 
 if [ ${LIBSTM32_EN} != 0 ]; then
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/libcmsis-${LIBCMSIS}.build ]; then
     unpack libcmsis-${LIBCMSIS}
     cd libcmsis-${LIBCMSIS}
     log "Building libcmsis-${LIBCMSIS}"
     make arch_prefix=${TARGET} prefix=${PREFIX}
     install libcmsis-${LIBCMSIS} arch_prefix=${TARGET} prefix=${PREFIX} install
+    if [ ${SECOND_HOST} != "" ]; then
+        make arch_prefix=${TARGET} prefix=${SUMMON_DIR}/${SECOND_HOST} install
+    fi
     cd ..
-    log "Cleaning up libcmsis-${LIBCMSIS}"
     touch ${STAMPS}/libcmsis-${LIBCMSIS}.build
-    rm -rf libcmsis-${LIBCMSIS}
+    mv libcmsis-${LIBCMSIS} build-libcmsis-${LIBCMSIS}
 fi
 
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/libstm32-${LIBSTM32}.build ]; then
     unpack libstm32-${LIBSTM32}
     cd libstm32-${LIBSTM32}
     log "Building libstm32-${LIBSTM32}"
     make arch_prefix=${TARGET} prefix=${PREFIX}
     install libstm32-${LIBSTM32} arch_prefix=${TARGET} prefix=${PREFIX} install
+    if [ ${SECOND_HOST} != "" ]; then
+        make arch_prefix=${TARGET} prefix=${SUMMON_DIR}/${SECOND_HOST} install
+    fi
     cd ..
-    log "Cleaning up libstm32-${LIBSTM32}"
     touch ${STAMPS}/libstm32-${LIBSTM32}.build
-    rm -rf libstm32-${LIBSTM32}
+    mv libstm32-${LIBSTM32} build-libstm32-${LIBSTM32}
 fi
 
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/libstm32usb-${LIBSTM32USB}.build ]; then
     unpack libstm32usb-${LIBSTM32USB}
     cd libstm32usb-${LIBSTM32USB}
     log "Building libstm32usb-${LIBSTM32USB}"
     make arch_prefix=${TARGET} prefix=${PREFIX}
     install libstm32usb-${LIBSTM32USB} arch_prefix=${TARGET} prefix=${PREFIX} install
+    if [ ${SECOND_HOST} != "" ]; then
+        make arch_prefix=${TARGET} prefix=${SUMMON_DIR}/${SECOND_HOST} install
+    fi
     cd ..
-    log "Cleaning up libstm32usb-${LIBSTM32USB}"
     touch ${STAMPS}/libstm32usb-${LIBSTM32USB}.build
-    rm -rf libstm32usb-${LIBSTM32USB}
+    mv libstm32usb-${LIBSTM32USB} build-libstm32usb-${LIBSTM32USB}
 fi
 fi
 
 if [ $LIBOPENSTM32_EN != 0 ]; then
+cd ${SUMMON_DIR}
 if [ ! -e ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build ]; then
     unpack libopenstm32-${LIBOPENSTM32}
     cd libopenstm32-${LIBOPENSTM32}
     log "Building libopenstm32-${LIBOPENSTM32}"
     make PREFIX=${TARGET} DESTDIR=${PREFIX}
     install libopenstm32-${LIBOPENSTM32} PREFIX=${TARGET} DESTDIR=${PREFIX} install
+    if [ ${SECOND_HOST} != "" ]; then
+        make PREFIX=${TARGET} DESTDIR=${SUMMON_DIR}/${SECOND_HOST} install
+    fi
     cd ..
-    log "Cleaning up libopenstm32-${LIBOPENSTM32}"
     touch ${STAMPS}/libopenstm32-${LIBOPENSTM32}.build
-    rm -rf libopenstm32-${LIBOPENSTM32}
+    mv libopenstm32-${LIBOPENSTM32} build-libopenstm32-${LIBOPENSTM32}
 fi
 fi
