Merge branch 'master' of git://git.denx.de/u-boot-nios
diff --git a/board/pandora/pandora.h b/board/pandora/pandora.h
index 5bfa0f9..f0ad16b 100644
--- a/board/pandora/pandora.h
+++ b/board/pandora/pandora.h
@@ -219,7 +219,8 @@
 	MUX_VAL(CP(UART2_RX),		(IEN  | PTD | EN  | M4)) /*GPIO_147,*/\
 								 /*UART2_RX*/\
  /*Serial Interface (Peripheral boot, Linux console, on AV connector)*/\
-	MUX_VAL(CP(UART3_RX_IRRX),	(IEN  | PTD | DIS | M0)) /*UART3_RX*/\
+ /*RX pulled up to avoid noise when nothing is connected to serial port*/\
+	MUX_VAL(CP(UART3_RX_IRRX),	(IEN  | PTU | EN  | M0)) /*UART3_RX*/\
 	MUX_VAL(CP(UART3_TX_IRTX),	(IDIS | PTD | DIS | M0)) /*UART3_TX*/\
  /*LEDs (Controlled by OMAP)*/\
 	MUX_VAL(CP(MMC1_DAT6),		(IDIS | PTD | DIS | M4)) /*GPIO_128*/\
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 8f83598..401bf27 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -129,7 +129,7 @@
 static boot_os_fn do_bootm_integrity;
 #endif
 
-boot_os_fn * boot_os[] = {
+static boot_os_fn *boot_os[] = {
 #ifdef CONFIG_BOOTM_LINUX
 	[IH_OS_LINUX] = do_bootm_linux,
 #endif
@@ -524,7 +524,7 @@
 		}
 			break;
 #endif
-#ifdef CONFIG_OF_LIBFDT
+#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_SYS_BOOTMAPSZ)
 		case BOOTM_STATE_FDT:
 		{
 			ulong bootmap_base = getenv_bootm_low();
diff --git a/doc/uImage.FIT/kernel.its b/doc/uImage.FIT/kernel.its
index d1a5939..ef3ab8f 100644
--- a/doc/uImage.FIT/kernel.its
+++ b/doc/uImage.FIT/kernel.its
@@ -1,6 +1,9 @@
 /*
  * Simple U-boot uImage source file containing a single kernel
  */
+
+/dts-v1/;
+
 / {
 	description = "Simple image with single Linux kernel";
 	#address-cells = <1>;
diff --git a/doc/uImage.FIT/kernel_fdt.its b/doc/uImage.FIT/kernel_fdt.its
index fd6dee2..7e940d2 100644
--- a/doc/uImage.FIT/kernel_fdt.its
+++ b/doc/uImage.FIT/kernel_fdt.its
@@ -1,6 +1,9 @@
 /*
  * Simple U-boot uImage source file containing a single kernel and FDT blob
  */
+
+/dts-v1/;
+
 / {
 	description = "Simple image with single Linux kernel and FDT blob";
 	#address-cells = <1>;
diff --git a/doc/uImage.FIT/multi.its b/doc/uImage.FIT/multi.its
index 1d8c2db..a120da0 100644
--- a/doc/uImage.FIT/multi.its
+++ b/doc/uImage.FIT/multi.its
@@ -1,6 +1,9 @@
 /*
  * U-boot uImage source file with multiple kernels, ramdisks and FDT blobs
  */
+
+/dts-v1/;
+
 / {
 	description = "Various kernels, ramdisks and FDT blobs";
 	#address-cells = <1>;
diff --git a/doc/uImage.FIT/update3.its b/doc/uImage.FIT/update3.its
index 285cf73..a6eaef6 100644
--- a/doc/uImage.FIT/update3.its
+++ b/doc/uImage.FIT/update3.its
@@ -1,6 +1,9 @@
 /*
  * Example Automatic software update file.
  */
+
+/dts-v1/;
+
 / {
 	description = "Automatic software updates: kernel, ramdisk, FDT";
 	#address-cells = <1>;
diff --git a/doc/uImage.FIT/update_uboot.its b/doc/uImage.FIT/update_uboot.its
index e0d27ea..846723e 100644
--- a/doc/uImage.FIT/update_uboot.its
+++ b/doc/uImage.FIT/update_uboot.its
@@ -2,6 +2,9 @@
  * Automatic software update for U-Boot
  * Make sure the flashing addresses ('load' prop) is correct for your board!
  */
+
+/dts-v1/;
+
 / {
 	description = "Automatic U-Boot update";
 	#address-cells = <1>;
diff --git a/drivers/spi/atmel_dataflash_spi.c b/drivers/spi/atmel_dataflash_spi.c
index 614965c..3a648e6 100644
--- a/drivers/spi/atmel_dataflash_spi.c
+++ b/drivers/spi/atmel_dataflash_spi.c
@@ -30,7 +30,8 @@
 #include <dataflash.h>
 
 #define AT91_SPI_PCS0_DATAFLASH_CARD	0xE	/* Chip Select 0: NPCS0%1110 */
-#define AT91_SPI_PCS1_DATAFLASH_CARD	0xD	/* Chip Select 0: NPCS0%1101 */
+#define AT91_SPI_PCS1_DATAFLASH_CARD	0xD	/* Chip Select 1: NPCS1%1101 */
+#define AT91_SPI_PCS2_DATAFLASH_CARD	0xB	/* Chip Select 2: NPCS2%1011 */
 #define AT91_SPI_PCS3_DATAFLASH_CARD	0x7	/* Chip Select 3: NPCS3%0111 */
 
 void AT91F_SpiInit(void)
@@ -57,7 +58,14 @@
 	       ((get_mck_clk_rate() / AT91_SPI_CLK) << 8),
 	       AT91_BASE_SPI + AT91_SPI_CSR(1));
 #endif
-
+#ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS2
+	/* Configure CS2 */
+	writel(AT91_SPI_NCPHA |
+	       (AT91_SPI_DLYBS & DATAFLASH_TCSS) |
+	       (AT91_SPI_DLYBCT & DATAFLASH_TCHS) |
+	       ((get_mck_clk_rate() / AT91_SPI_CLK) << 8),
+	       AT91_BASE_SPI + AT91_SPI_CSR(2));
+#endif
 #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS3
 	/* Configure CS3 */
 	writel(AT91_SPI_NCPHA |
@@ -99,6 +107,12 @@
 		writel(mode | ((AT91_SPI_PCS1_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
 		       AT91_BASE_SPI + AT91_SPI_MR);
 		break;
+	case 2:	/* Configure SPI CS2 for Serial DataFlash AT45DBxx */
+		mode = readl(AT91_BASE_SPI + AT91_SPI_MR);
+		mode &= 0xFFF0FFFF;
+		writel(mode | ((AT91_SPI_PCS2_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
+		       AT91_BASE_SPI + AT91_SPI_MR);
+		break;
 	case 3:
 		mode = readl(AT91_BASE_SPI + AT91_SPI_MR);
 		mode &= 0xFFF0FFFF;
diff --git a/include/image.h b/include/image.h
index 5a424e6..04b62d1 100644
--- a/include/image.h
+++ b/include/image.h
@@ -219,12 +219,10 @@
 	const char	*fit_uname_rd;	/* init ramdisk subimage node unit name */
 	int		fit_noffset_rd;	/* init ramdisk subimage node offset */
 
-#if defined(CONFIG_PPC)
 	void		*fit_hdr_fdt;	/* FDT blob FIT image header */
 	const char	*fit_uname_fdt;	/* FDT blob subimage node unit name */
 	int		fit_noffset_fdt;/* FDT blob subimage node offset */
 #endif
-#endif
 
 #ifndef USE_HOSTCC
 	image_info_t	os;		/* os image info */
diff --git a/include/spi_flash.h b/include/spi_flash.h
index de4f174..1f8ba29 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -24,6 +24,7 @@
 #define _SPI_FLASH_H_
 
 #include <spi.h>
+#include <linux/types.h>
 
 struct spi_flash_region {
 	unsigned int	count;
diff --git a/lib_ppc/Makefile b/lib_ppc/Makefile
index 399b41e..60a7625 100644
--- a/lib_ppc/Makefile
+++ b/lib_ppc/Makefile
@@ -35,7 +35,7 @@
 COBJS-y	+= cache.o
 COBJS-y	+= extable.o
 COBJS-y	+= interrupts.o
-COBJS-y	+= kgdb.o
+COBJS-$(CONFIG_CMD_KGDB) += kgdb.o
 COBJS-y	+= time.o
 
 SRCS	:= $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c)
diff --git a/lib_ppc/kgdb.c b/lib_ppc/kgdb.c
index 78c2f0c..d3eb1f3 100644
--- a/lib_ppc/kgdb.c
+++ b/lib_ppc/kgdb.c
@@ -1,8 +1,5 @@
 #include <common.h>
 #include <command.h>
-
-#if defined(CONFIG_CMD_KGDB)
-
 #include <kgdb.h>
 #include <asm/signal.h>
 #include <asm/processor.h>
@@ -322,5 +319,3 @@
 	     breakinst: .long 0x7d821008\n\
 	    ");
 }
-
-#endif
diff --git a/mkconfig b/mkconfig
index 4c5675b..1075510 100755
--- a/mkconfig
+++ b/mkconfig
@@ -27,6 +27,11 @@
 [ $# -lt 4 ] && exit 1
 [ $# -gt 6 ] && exit 1
 
+if [ "${ARCH}" -a "${ARCH}" != "$2" ]; then
+	echo "Failed: \$ARCH=${ARCH}, should be '$2' for ${BOARD_NAME}" 1>&2
+	exit 1
+fi
+
 echo "Configuring for ${BOARD_NAME} board..."
 
 #
diff --git a/net/net.c b/net/net.c
index cab4b2d..fd13cd9 100644
--- a/net/net.c
+++ b/net/net.c
@@ -197,6 +197,8 @@
 
 static int net_check_prereq (proto_t protocol);
 
+static int NetTryCount;
+
 /**********************************************************************/
 
 IPaddr_t	NetArpWaitPacketIP;
@@ -320,6 +322,7 @@
 	NetArpWaitReplyIP = 0;
 	NetArpWaitTxPacket = NULL;
 	NetTxPacket = NULL;
+	NetTryCount = 1;
 
 	if (!NetTxPacket) {
 		int	i;
@@ -558,17 +561,30 @@
 void NetStartAgain (void)
 {
 	char *nretry;
-	int noretry = 0, once = 0;
+	int retry_forever = 0;
+	unsigned long retrycnt = 0;
 
-	if ((nretry = getenv ("netretry")) != NULL) {
-		noretry = (strcmp (nretry, "no") == 0);
-		once = (strcmp (nretry, "once") == 0);
-	}
-	if (noretry) {
-		eth_halt ();
+	nretry = getenv("netretry");
+	if (nretry) {
+		if (!strcmp(nretry, "yes"))
+			retry_forever = 1;
+		else if (!strcmp(nretry, "no"))
+			retrycnt = 0;
+		else if (!strcmp(nretry, "once"))
+			retrycnt = 1;
+		else
+			retrycnt = simple_strtoul(nretry, NULL, 0);
+	} else
+		retry_forever = 1;
+
+	if ((!retry_forever) && (NetTryCount >= retrycnt)) {
+		eth_halt();
 		NetState = NETLOOP_FAIL;
 		return;
 	}
+
+	NetTryCount++;
+
 #ifndef CONFIG_NET_MULTI
 	NetSetTimeout (10000UL, startAgainTimeout);
 	NetSetHandler (startAgainHandler);
@@ -580,7 +596,7 @@
 	eth_init (gd->bd);
 	if (NetRestartWrap) {
 		NetRestartWrap = 0;
-		if (NetDevExists && !once) {
+		if (NetDevExists) {
 			NetSetTimeout (10000UL, startAgainTimeout);
 			NetSetHandler (startAgainHandler);
 		} else {
diff --git a/tools/.gitignore b/tools/.gitignore
index 03f54ef..cb067a4 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -8,3 +8,4 @@
 /ncp
 /ubsha1
 /inca-swap-bytes
+/*.exe
diff --git a/tools/img2srec.c b/tools/img2srec.c
index f10379f..ec76964 100644
--- a/tools/img2srec.c
+++ b/tools/img2srec.c
@@ -53,6 +53,7 @@
 |*************************************************************************/
 
 #include "os_support.h"
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -63,63 +64,22 @@
 #include <errno.h>
 
 /*************************************************************************
-|  DEFINES
-|*************************************************************************/
-
-#define FALSE           0
-#define TRUE            1
-
-/*************************************************************************
-|  MACROS
-|*************************************************************************/
-
-/*************************************************************************
-|  TYPEDEFS
-|*************************************************************************/
-
-typedef uint8_t   CHAR;
-typedef uint8_t   BYTE;
-typedef uint16_t  WORD;
-typedef uint32_t  DWORD;
-typedef int       BOOL;
-
-/*************************************************************************
-|  LOCALS
-|*************************************************************************/
-
-/*************************************************************************
-|  PROTOTYPES
-|*************************************************************************/
-
-static char *ExtractHex(DWORD *value, char *getPtr);
-static char *ExtractDecimal(DWORD *value, char *getPtr);
-static void ExtractNumber(DWORD *value, char *getPtr);
-static BYTE *ExtractWord(WORD *value, BYTE *buffer);
-static BYTE *ExtractLong(DWORD *value, BYTE *buffer);
-static BYTE *ExtractBlock(WORD count, BYTE *data, BYTE *buffer);
-static char *WriteHex(char *pa, BYTE value, WORD *pCheckSum);
-static char *BuildSRecord(char *pa, WORD sType, DWORD addr,
-			  const BYTE *data, int nCount);
-static void ConvertELF(char *fileName, DWORD loadOffset);
-int main(int argc, char *argv[]);
-
-/*************************************************************************
 |  FUNCTIONS
 |*************************************************************************/
 
-static char* ExtractHex (DWORD* value,  char* getPtr)
+static char* ExtractHex (uint32_t* value,  char* getPtr)
 {
-  DWORD num;
-  DWORD digit;
-  BYTE  c;
+  uint32_t num;
+  uint32_t digit;
+  uint8_t  c;
 
   while (*getPtr == ' ') getPtr++;
   num = 0;
   for (;;) {
     c = *getPtr;
-    if      ((c >= '0') && (c <= '9')) digit = (DWORD)(c - '0');
-    else if ((c >= 'A') && (c <= 'F')) digit = (DWORD)(c - 'A' + 10);
-    else if ((c >= 'a') && (c <= 'f')) digit = (DWORD)(c - 'a' + 10);
+    if      ((c >= '0') && (c <= '9')) digit = (uint32_t)(c - '0');
+    else if ((c >= 'A') && (c <= 'F')) digit = (uint32_t)(c - 'A' + 10);
+    else if ((c >= 'a') && (c <= 'f')) digit = (uint32_t)(c - 'a' + 10);
     else break;
     num <<= 4;
     num += digit;
@@ -129,17 +89,17 @@
   return getPtr;
 } /* ExtractHex */
 
-static char* ExtractDecimal (DWORD* value,  char* getPtr)
+static char* ExtractDecimal (uint32_t* value,  char* getPtr)
 {
-  DWORD num;
-  DWORD digit;
-  BYTE  c;
+  uint32_t num;
+  uint32_t digit;
+  uint8_t  c;
 
   while (*getPtr == ' ') getPtr++;
   num = 0;
   for (;;) {
     c = *getPtr;
-    if      ((c >= '0') && (c <= '9')) digit = (DWORD)(c - '0');
+    if      ((c >= '0') && (c <= '9')) digit = (uint32_t)(c - '0');
     else break;
     num *= 10;
     num += digit;
@@ -150,13 +110,13 @@
 } /* ExtractDecimal */
 
 
-static void ExtractNumber (DWORD* value,  char* getPtr)
+static void ExtractNumber (uint32_t* value,  char* getPtr)
 {
-  BOOL  neg = FALSE;;
+  bool  neg = false;;
 
   while (*getPtr == ' ') getPtr++;
   if (*getPtr == '-') {
-    neg = TRUE;
+    neg = true;
     getPtr++;
   } /* if */
   if ((*getPtr == '0') && ((*(getPtr+1) == 'x') || (*(getPtr+1) == 'X'))) {
@@ -170,38 +130,38 @@
 } /* ExtractNumber */
 
 
-static BYTE* ExtractWord(WORD* value, BYTE* buffer)
+static uint8_t* ExtractWord(uint16_t* value, uint8_t* buffer)
 {
-  WORD x;
-  x = (WORD)*buffer++;
-  x = (x<<8) + (WORD)*buffer++;
+  uint16_t x;
+  x = (uint16_t)*buffer++;
+  x = (x<<8) + (uint16_t)*buffer++;
   *value = x;
   return buffer;
 } /* ExtractWord */
 
 
-static BYTE* ExtractLong(DWORD* value, BYTE* buffer)
+static uint8_t* ExtractLong(uint32_t* value, uint8_t* buffer)
 {
-  DWORD x;
-  x = (DWORD)*buffer++;
-  x = (x<<8) + (DWORD)*buffer++;
-  x = (x<<8) + (DWORD)*buffer++;
-  x = (x<<8) + (DWORD)*buffer++;
+  uint32_t x;
+  x = (uint32_t)*buffer++;
+  x = (x<<8) + (uint32_t)*buffer++;
+  x = (x<<8) + (uint32_t)*buffer++;
+  x = (x<<8) + (uint32_t)*buffer++;
   *value = x;
   return buffer;
 } /* ExtractLong */
 
 
-static BYTE* ExtractBlock(WORD count, BYTE* data, BYTE* buffer)
+static uint8_t* ExtractBlock(uint16_t count, uint8_t* data, uint8_t* buffer)
 {
   while (count--) *data++ = *buffer++;
   return buffer;
 } /* ExtractBlock */
 
 
-static char* WriteHex(char* pa, BYTE value, WORD* pCheckSum)
+static char* WriteHex(char* pa, uint8_t value, uint16_t* pCheckSum)
 {
-  WORD  temp;
+  uint16_t  temp;
 
   static  char ByteToHex[] = "0123456789ABCDEF";
 
@@ -214,13 +174,13 @@
 }
 
 
-static char* BuildSRecord(char* pa, WORD sType, DWORD addr,
-			  const BYTE* data, int nCount)
+static char* BuildSRecord(char* pa, uint16_t sType, uint32_t addr,
+			  const uint8_t* data, int nCount)
 {
-  WORD  addrLen;
-  WORD  sRLen;
-  WORD  checkSum;
-  WORD  i;
+  uint16_t  addrLen;
+  uint16_t  sRLen;
+  uint16_t  checkSum;
+  uint16_t  i;
 
   switch (sType) {
   case 0:
@@ -244,11 +204,11 @@
   *pa++ = (char)(sType + '0');
   sRLen = addrLen + nCount + 1;
   checkSum = 0;
-  pa = WriteHex(pa, (BYTE)sRLen, &checkSum);
+  pa = WriteHex(pa, (uint8_t)sRLen, &checkSum);
 
   /* Write address field */
   for (i = 1; i <= addrLen; i++) {
-    pa = WriteHex(pa, (BYTE)(addr >> (8 * (addrLen - i))), &checkSum);
+    pa = WriteHex(pa, (uint8_t)(addr >> (8 * (addrLen - i))), &checkSum);
   } /* for */
 
   /* Write code/data fields */
@@ -258,25 +218,25 @@
 
   /* Write checksum field */
   checkSum = ~checkSum;
-  pa = WriteHex(pa, (BYTE)checkSum, &checkSum);
+  pa = WriteHex(pa, (uint8_t)checkSum, &checkSum);
   *pa++ = '\0';
   return pa;
 }
 
 
-static void ConvertELF(char* fileName, DWORD loadOffset)
+static void ConvertELF(char* fileName, uint32_t loadOffset)
 {
   FILE*         file;
   int           i;
   int           rxCount;
-  BYTE          rxBlock[1024];
-  DWORD         loadSize;
-  DWORD         firstAddr;
-  DWORD         loadAddr;
-  DWORD         loadDiff = 0;
+  uint8_t          rxBlock[1024];
+  uint32_t         loadSize;
+  uint32_t         firstAddr;
+  uint32_t         loadAddr;
+  uint32_t         loadDiff = 0;
   Elf32_Ehdr    elfHeader;
   Elf32_Shdr    sectHeader[32];
-  BYTE*         getPtr;
+  uint8_t*         getPtr;
   char          srecLine[128];
   char		*hdr_name;
 
@@ -292,11 +252,11 @@
   getPtr = ExtractBlock(sizeof elfHeader.e_ident, elfHeader.e_ident, rxBlock);
   getPtr = ExtractWord(&elfHeader.e_type, getPtr);
   getPtr = ExtractWord(&elfHeader.e_machine, getPtr);
-  getPtr = ExtractLong((DWORD *)&elfHeader.e_version, getPtr);
-  getPtr = ExtractLong((DWORD *)&elfHeader.e_entry, getPtr);
-  getPtr = ExtractLong((DWORD *)&elfHeader.e_phoff, getPtr);
-  getPtr = ExtractLong((DWORD *)&elfHeader.e_shoff, getPtr);
-  getPtr = ExtractLong((DWORD *)&elfHeader.e_flags, getPtr);
+  getPtr = ExtractLong((uint32_t *)&elfHeader.e_version, getPtr);
+  getPtr = ExtractLong((uint32_t *)&elfHeader.e_entry, getPtr);
+  getPtr = ExtractLong((uint32_t *)&elfHeader.e_phoff, getPtr);
+  getPtr = ExtractLong((uint32_t *)&elfHeader.e_shoff, getPtr);
+  getPtr = ExtractLong((uint32_t *)&elfHeader.e_flags, getPtr);
   getPtr = ExtractWord(&elfHeader.e_ehsize, getPtr);
   getPtr = ExtractWord(&elfHeader.e_phentsize, getPtr);
   getPtr = ExtractWord(&elfHeader.e_phnum, getPtr);
@@ -319,16 +279,16 @@
   fseek(file, elfHeader.e_shoff, SEEK_SET);
   for (i = 0; i < elfHeader.e_shnum; i++) {
     rxCount = fread(rxBlock, 1, sizeof sectHeader[0], file);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_name, rxBlock);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_type, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_flags, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_addr, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_offset, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_size, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_link, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_info, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_addralign, getPtr);
-    getPtr = ExtractLong((DWORD *)&sectHeader[i].sh_entsize, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_name, rxBlock);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_type, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_flags, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_addr, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_offset, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_size, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_link, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_info, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_addralign, getPtr);
+    getPtr = ExtractLong((uint32_t *)&sectHeader[i].sh_entsize, getPtr);
     if (rxCount != sizeof sectHeader[0]) {
       fclose(file);
       fprintf (stderr, "*** illegal file format\n");
@@ -342,7 +302,7 @@
     ++hdr_name;
   }
   /* write start record */
-  (void)BuildSRecord(srecLine, 0, 0, (BYTE *)hdr_name, strlen(hdr_name));
+  (void)BuildSRecord(srecLine, 0, 0, (uint8_t *)hdr_name, strlen(hdr_name));
   printf("%s\r\n",srecLine);
 
   /* write data records */
@@ -395,7 +355,7 @@
 
 int main( int argc, char *argv[ ])
 {
-  DWORD offset;
+  uint32_t offset;
 
   if (argc == 2) {
     ConvertELF(argv[1], 0);
diff --git a/tools/mingw_support.c b/tools/mingw_support.c
index 67cd6e1..6379710 100644
--- a/tools/mingw_support.c
+++ b/tools/mingw_support.c
@@ -24,7 +24,9 @@
 #include "mingw_support.h"
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include <errno.h>
+#include <assert.h>
 #include <io.h>
 
 int fsync(int fd)
@@ -77,3 +79,158 @@
 
 	return 0;
 }
+
+/* Reentrant string tokenizer.  Generic version.
+   Copyright (C) 1991,1996-1999,2001,2004,2007 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program 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 2, or (at your option)
+   any later version.
+
+   This program 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 this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Parse S into tokens separated by characters in DELIM.
+   If S is NULL, the saved pointer in SAVE_PTR is used as
+   the next starting point.  For example:
+	char s[] = "-abc-=-def";
+	char *sp;
+	x = strtok_r(s, "-", &sp);	// x = "abc", sp = "=-def"
+	x = strtok_r(NULL, "-=", &sp);	// x = "def", sp = NULL
+	x = strtok_r(NULL, "=", &sp);	// x = NULL
+		// s = "abc\0-def\0"
+*/
+char *strtok_r(char *s, const char *delim, char **save_ptr)
+{
+	char *token;
+
+	if (s == NULL)
+		s = *save_ptr;
+
+	/* Scan leading delimiters.  */
+	s += strspn(s, delim);
+	if (*s == '\0') {
+		*save_ptr = s;
+		return NULL;
+	}
+
+	/* Find the end of the token.  */
+	token = s;
+	s = strpbrk (token, delim);
+	if (s == NULL) {
+		/* This token finishes the string.  */
+		*save_ptr = memchr(token, '\0', strlen(token));
+	} else {
+		/* Terminate the token and make *SAVE_PTR point past it.  */
+		*s = '\0';
+		*save_ptr = s + 1;
+	}
+	return token;
+}
+
+/* getline.c -- Replacement for GNU C library function getline
+
+Copyright (C) 1993, 1996, 2001, 2002 Free Software Foundation, Inc.
+
+This program 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 2 of the
+License, or (at your option) any later version.
+
+This program 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 this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by Jan Brittenson, bson@gnu.ai.mit.edu.  */
+
+/* Always add at least this many bytes when extending the buffer.  */
+#define MIN_CHUNK 64
+
+/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
+   + OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
+   malloc (or NULL), pointing to *N characters of space.  It is realloc'd
+   as necessary.  Return the number of characters read (not including the
+   null terminator), or -1 on error or EOF.
+   NOTE: There is another getstr() function declared in <curses.h>.  */
+static int getstr(char **lineptr, size_t *n, FILE *stream,
+		  char terminator, size_t offset)
+{
+	int nchars_avail;	/* Allocated but unused chars in *LINEPTR.  */
+	char *read_pos;		/* Where we're reading into *LINEPTR. */
+	int ret;
+
+	if (!lineptr || !n || !stream)
+		return -1;
+
+	if (!*lineptr) {
+		*n = MIN_CHUNK;
+		*lineptr = malloc(*n);
+		if (!*lineptr)
+			return -1;
+	}
+
+	nchars_avail = *n - offset;
+	read_pos = *lineptr + offset;
+
+	for (;;) {
+		register int c = getc(stream);
+
+		/* We always want at least one char left in the buffer, since we
+		   always (unless we get an error while reading the first char)
+		   NUL-terminate the line buffer.  */
+
+		assert(*n - nchars_avail == read_pos - *lineptr);
+		if (nchars_avail < 2) {
+			if (*n > MIN_CHUNK)
+				*n *= 2;
+			else
+				*n += MIN_CHUNK;
+
+			nchars_avail = *n + *lineptr - read_pos;
+			*lineptr = realloc(*lineptr, *n);
+			if (!*lineptr)
+				return -1;
+			read_pos = *n - nchars_avail + *lineptr;
+			assert(*n - nchars_avail == read_pos - *lineptr);
+		}
+
+		if (c == EOF || ferror (stream)) {
+			/* Return partial line, if any.  */
+			if (read_pos == *lineptr)
+				return -1;
+			else
+				break;
+		}
+
+		*read_pos++ = c;
+		nchars_avail--;
+
+		if (c == terminator)
+			/* Return the line.  */
+			break;
+	}
+
+	/* Done - NUL terminate and return the number of chars read.  */
+	*read_pos = '\0';
+
+	ret = read_pos - (*lineptr + offset);
+	return ret;
+}
+
+int getline (char **lineptr, size_t *n, FILE *stream)
+{
+	return getstr(lineptr, n, stream, '\n', 0);
+}
diff --git a/tools/mingw_support.h b/tools/mingw_support.h
index 9e45e64..2793674 100644
--- a/tools/mingw_support.h
+++ b/tools/mingw_support.h
@@ -44,5 +44,7 @@
 int fsync(int fd);
 void *mmap(void *, size_t, int, int, int, int);
 int munmap(void *, size_t);
+char *strtok_r(char *s, const char *delim, char **save_ptr);
+int getline(char **lineptr, size_t *n, FILE *stream);
 
 #endif /* __MINGW_SUPPORT_H_ */
diff --git a/tools/mkimage.c b/tools/mkimage.c
index ab6ea32..8a20594 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -229,6 +229,7 @@
 			case 'f':
 				if (--argc <= 0)
 					usage ();
+				params.type = IH_TYPE_FLATDT;
 				params.datafile = *++argv;
 				params.fflag = 1;
 				goto NXTARG;