* Add automatic update support for LWMON board

* Enable MSDOS/VFAT filesystem support for LWMON board

* Clear Block Lock-Bits when erasing flash on LWMON board.

* Fix return code of "fatload" command

* Disable debugging for TQM5200 board
diff --git a/CHANGELOG b/CHANGELOG
index e7d1e73..64fee4a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,14 @@
 Changes since U-Boot 1.1.1:
 ======================================================================
 
+* Add automatic update support for LWMON board
+
+* Clear Block Lock-Bits when erasing flash on LWMON board.
+
+* Fix return code of "fatload" command
+
+* Enable MSDOS/VFAT filesystem support for LWMON board
+
 * Patch by Martin Krause, 03 Aug 2004:
   change timing for SM501 graphics controller on TQM5200 module
 
diff --git a/Makefile b/Makefile
index 1bf8a65..f955705 100644
--- a/Makefile
+++ b/Makefile
@@ -315,12 +315,12 @@
 	@[ -z "$(findstring AB,$@)" ] || \
 		{ echo "#define CONFIG_TQM5200_AB"	>>include/config.h ; \
 		  echo "... with 64 MB Flash, 64 MB SDRAM, 32 kB EEPROM, 512 kB SRAM" ; \
-		  echo "... with Grafic Controller"; \
+		  echo "... with Graphics Controller"; \
 		}
 	@[ -z "$(findstring AC,$@)" ] || \
 		{ echo "#define CONFIG_TQM5200_AC"	>>include/config.h ; \
 		  echo "... with 4 MB Flash, 128 MB SDRAM" ; \
-		  echo "... with Grafic Controller"; \
+		  echo "... with Graphics Controller"; \
 		}
 	@./mkconfig -a TQM5200 ppc mpc5xxx tqm5200
 
diff --git a/board/lwmon/flash.c b/board/lwmon/flash.c
index 4004865..b894887 100644
--- a/board/lwmon/flash.c
+++ b/board/lwmon/flash.c
@@ -403,6 +403,26 @@
 			/* Disable interrupts which might cause a timeout here */
 			flag = disable_interrupts();
 
+			*addr = 0x00600060;	/* clear lock bit setup */
+			*addr = 0x00D000D0;	/* clear lock bit confirm */
+
+			udelay (1000);
+			/* This takes awfully long - up to 50 ms and more */
+			while (((status = *addr) & 0x00800080) != 0x00800080) {
+				if ((now=get_timer(start)) > CFG_FLASH_ERASE_TOUT) {
+					printf ("Timeout\n");
+					*addr = 0x00FF00FF; /* reset to read mode */
+					return 1;
+				}
+
+				/* show that we're waiting */
+				if ((now - last) > 1000) {	/* every second */
+					putc ('.');
+					last = now;
+				}
+				udelay (1000);	/* to trigger the watchdog */
+			}
+
 			*addr = 0x00500050;	/* clear status register */
 			*addr = 0x00200020;	/* erase setup */
 			*addr = 0x00D000D0;	/* erase confirm */
@@ -427,6 +447,7 @@
 					putc ('.');
 					last = now;
 				}
+				udelay (1000);	/* to trigger the watchdog */
 			}
 
 			*addr = 0x00FF00FF;	/* reset to read mode */
diff --git a/common/cmd_fat.c b/common/cmd_fat.c
index 150a2ea..6844c10 100644
--- a/common/cmd_fat.c
+++ b/common/cmd_fat.c
@@ -86,7 +86,7 @@
 
 	if (argc < 5) {
 		printf ("usage: fatload <interface> <dev[:part]> <addr> <filename> [bytes]\n");
-		return (0);
+		return 1;
 	}
 	dev = (int)simple_strtoul (argv[2], &ep, 16);
 	dev_desc=get_dev(argv[1],dev);
@@ -114,14 +114,15 @@
 
 	if(size==-1) {
 		printf("\n** Unable to read \"%s\" from %s %d:%d **\n",argv[4],argv[1],dev,part);
-	} else {
-		printf ("\n%ld bytes read\n", size);
-
-		sprintf(buf, "%lX", size);
-		setenv("filesize", buf);
+		return 1;
 	}
 
-	return size;
+	printf ("\n%ld bytes read\n", size);
+
+	sprintf(buf, "%lX", size);
+	setenv("filesize", buf);
+
+	return 0;
 }
 
 
diff --git a/include/configs/TQM5200.h b/include/configs/TQM5200.h
index 1f83aa5..7d39f22 100644
--- a/include/configs/TQM5200.h
+++ b/include/configs/TQM5200.h
@@ -27,8 +27,6 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-#define DEBUG 1
-
 /*
  * High Level Configuration Options
  * (easy to change)
@@ -64,7 +62,7 @@
  */
 #define CONFIG_PCI		0
 #define CONFIG_PCI_PNP		1
-#define CONFIG_PCI_SCAN_SHOW	1
+/* #define CONFIG_PCI_SCAN_SHOW	1 */
 
 #define CONFIG_PCI_MEM_BUS	0x40000000
 #define CONFIG_PCI_MEM_PHYS	CONFIG_PCI_MEM_BUS
diff --git a/include/configs/lwmon.h b/include/configs/lwmon.h
index a76ec23..74186a8 100644
--- a/include/configs/lwmon.h
+++ b/include/configs/lwmon.h
@@ -78,12 +78,24 @@
 
 #define CONFIG_BOOTCOMMAND	"run flash_self"
 
+/*
+ * Keyboard commands:
+ * # = 0x28 = ENTER :		enable bootmessages on LCD
+ * 2 = 0x3A+0x3C = F1 + F3 :	enable update mode
+ * 3 = 0x3C+0x3F = F3 + F6 :	enable test mode
+ */
 #define	CONFIG_EXTRA_ENV_SETTINGS					\
 	"kernel_addr=40080000\0"					\
 	"ramdisk_addr=40280000\0"					\
-	"magic_keys=#3\0"						\
+	"magic_keys=#23\0"						\
 	"key_magic#=28\0"						\
 	"key_cmd#=setenv addfb setenv 'bootargs $bootargs console=tty0'\0" \
+	"key_magic2=3A+3C\0"						\
+	"key_cmd2=echo *** Entering Update Mode ***;"			\
+		"if fatload ide 0:3 10000 update.scr;"			\
+			"then autoscr 10000;"				\
+			"else echo *** UPDATE FAILED ***;"		\
+		"fi\0"							\
 	"key_magic3=3C+3F\0"						\
 	"key_cmd3=echo *** Entering Test Mode ***;"			\
 		"setenv add_misc 'setenv bootargs $bootargs testmode'\0" \
@@ -153,6 +165,7 @@
 				CFG_CMD_ASKENV	| \
 				CFG_CMD_DHCP	| \
 				CFG_CMD_DATE	| \
+				CFG_CMD_FAT	| \
 				CFG_CMD_I2C	| \
 				CFG_CMD_EEPROM	| \
 				CFG_CMD_IDE	| \
@@ -276,18 +289,12 @@
  */
 #define CFG_FLASH_BUFFER_SIZE	(2*32)
 
-#if 1
-/* Put environment in flash which is much faster to boot */
+/* Put environment in flash which is much faster to boot than using the EEPROM	*/
 #define CFG_ENV_IS_IN_FLASH	1
 #define CFG_ENV_ADDR	    0x40040000	/* Address    of Environment Sector	*/
 #define CFG_ENV_SIZE		0x2000	/* Total Size of Environment		*/
 #define CFG_ENV_SECT_SIZE	0x40000 /* we have BIG sectors only :-(		*/
-#else
-/* Environment in EEPROM */
-#define CFG_ENV_IS_IN_EEPROM	1
-#define CFG_ENV_OFFSET		0
-#define CFG_ENV_SIZE		2048
-#endif
+
 /*-----------------------------------------------------------------------
  * I2C/EEPROM Configuration
  */
@@ -488,6 +495,8 @@
 /* Offset for alternate registers	*/
 #define CFG_ATA_ALT_OFFSET	0x0100
 
+#define CONFIG_SUPPORT_VFAT		/* enable VFAT support */
+
 /*-----------------------------------------------------------------------
  *
  *-----------------------------------------------------------------------