c2kevm-nand: assorted cleanups to make it work with gftv builds.

Removed a lot of dead code in conditionals, and fixed up a bunch of
environment variables to work better with the way our builds work.

The mtd partition layout (and related update and boot_flash macros) are
still not what we want; they still read and write NOR flash, but we want to
switch to using NAND.  This does work, but I recommend booting from TFTP/NFS
for early development.

Change-Id: I2e147d245c7749c69a2956fd3d17c33bb39e191b
diff --git a/include/configs/c2kevm-nand.h b/include/configs/c2kevm-nand.h
index 20721b1..01a6969 100644
--- a/include/configs/c2kevm-nand.h
+++ b/include/configs/c2kevm-nand.h
@@ -40,15 +40,16 @@
 #include <asm/hardware.h>
 
 /* Mindspeed version */
-#define CONFIG_IDENT_STRING	" Mindspeed $Name: uboot_c2k_1_00"
+#define CONFIG_IDENT_STRING	" uboot_c2k_1_00"
 
 /*
  * Linux boot configuration
  */
 
+#define CONFIG_CMDLINE_EDITING		1
 #define CONFIG_CMDLINE_TAG		1	/* enable passing of ATAGs      */
 #define CONFIG_SETUP_MEMORY_TAGS	1
-//#define CONFIG_INITRD_TAG		1
+#define CONFIG_INITRD_TAG		1
 
 #define LINUX_BOOTPARAM_ADDR		(PHYS_SDRAM + MSP_BOTTOM_MEMORY_RESERVED_SIZE + 0x100)
 
@@ -96,56 +97,54 @@
 /*
  * Shell configuration
  */
-#define CONFIG_COMMANDS		(CFG_CMD_FLASH | CFG_CMD_ENV  | CFG_CMD_MEMORY | CFG_CMD_MEMTEST | CFG_CMD_MII  | CFG_CMD_RUN | CFG_CMD_NET | CFG_CMD_NAND | CFG_CMD_JFFS2 |  CFG_CMD_PING | CFG_CMD_NFS  | CFG_CMD_I2C | CFG_CMD_EEPROM /*| CFG_CMD_ELF| CFG_CMD_SPI*/)
+#define CONFIG_COMMANDS		(CFG_CMD_FLASH | CFG_CMD_ENV  | CFG_CMD_MEMORY | CFG_CMD_MEMTEST | CFG_CMD_MII  | CFG_CMD_RUN | CFG_CMD_NET | CFG_CMD_NAND | CFG_CMD_JFFS2 |  CFG_CMD_PING | CFG_CMD_NFS  | CFG_CMD_I2C | CFG_CMD_EEPROM | CFG_CMD_DHCP /*| CFG_CMD_ELF| CFG_CMD_SPI*/)
 
 #define	CFG_LONGHELP					/* undef to save memory		*/
-#define CFG_PROMPT		"Comcerto-2000 > "	/* Monitor Command Prompt */
-#define CFG_CBSIZE		256			/* Console I/O Buffer Size */
+#define CFG_PROMPT		"uboot> "		/* Monitor Command Prompt */
+#define CFG_CBSIZE		4096			/* Console I/O Buffer Size */
 #define CFG_MAXARGS		16			/* max number of command args */
 #define CFG_PBSIZE		(CFG_CBSIZE + sizeof(CFG_PROMPT) + 16)	/* Print Buffer Size */
 
 /*
  * User Interface
  */
+/* TODO(apenwarr): remove usb3_internal_clk=no and console=ttyS0 stuff.
+ *  We should set that inside the kernel itself to make it upgradable without
+ *  changing the bootloader.
+ */
 #define	CONFIG_EXTRA_ENV_SETTINGS				\
-	"hostname=comcerto2000\0"						\
+	"hostname=uboot\0"						\
 	"netdev=eth0\0"									\
-	"nfsargs=setenv bootargs init=${init_process} root=/dev/nfs rw "		\
-		"nfsroot=${serverip}:${rootpath}\0"				\
-	"flashargs=setenv bootargs init=${init_process} root=/dev/mtdblock4 rootfstype=${rootfstype} rw\0"	\
-	"rootfstype=jffs2\0" \
-	"init_process=/etc/preinit\0" \
+	"autoload=n\0" \
+	"flashargs=setenv bootargs rdinit=/bin/sh\0"	\
+	"getip=dhcp; run fixip\0" \
+	"fixip=set serverip ${tftpserver} ${serverip}\0" \
 	"addip=setenv bootargs ${bootargs} "				\
-		"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}"	\
+		"ip=${ipaddr}:${tftpserver}:${gatewayip}:${netmask}"	\
 		":${hostname}:${netdev}:off\0" \
-	"addeth=setenv bootargs ${bootargs} " \
-	"hwaddress=${netdev},${ethaddr}\0" \
-	"addtty=setenv bootargs ${bootargs} console=ttyS0,115200n8\0" \
+	"addeth=setenv bootargs ${bootargs}\0" \
+	"addnfs=setenv bootargs ${bootargs} root=${nfsroot}\0" \
+	"addtty=setenv bootargs ${bootargs} console=ttyS0,115200n8 login=1\0" \
+	"addx=setenv bootargs ${bootargs} usb3_internal_clk=no\0" \
 	"addmtd=setenv bootargs ${bootargs} ${mtdparts}\0" \
+	"zapenv=protect off 1:3-3; erase 1:3-3\0" \
 	"flash_self=run flashargs addip addtty;"		\
 		"bootm ${kernel_addr}\0"				\
-	"boot_nfs=nfs 80600000 ${rootpath}/boot/${kernelfile};run nfsargs addeth addip addtty;"     \
-	        "bootm 80600000\0"						\
-	"boot_flash=run flashargs addeth addtty addmtd; bootm 0xc0080000\0" \
-	"boot_flashold=run flashargs addeth addtty addmtd; fsload /boot/uImage; bootm\0" \
+	"boot_flash=run flashargs addx addeth addip addtty addmtd; bootm 0xc0080000\0" \
+	"boot_tftp=run getip;run flashargs addx addeth addip addtty addmtd addnfs; tftp 02000000 uImage; bootm 02000000\0" \
 	"rootpath=/devel/fs-c2kasic\0" \
 	"kernelfile=uImage\0" \
 	"bootfile=u-boot.bin\0" \
 	"mtdids=" MTDIDS_DEFAULT "\0" \
 	"mtdparts=" MTDPARTS_DEFAULT "\0" \
-	"partition=" MTDPARTITION_DEFAULT "\0" \
-	"mtddevnum=2\0" \
-	"mtddevname=fs\0" \
-	"fsfile=root.jffs2-128k\0" \
- 	"updatefs=tftp 3000000 ${fsfile};protect off 1:35-127\;erase 1:35-127;cp.b 3000000 c0480000 ${filesize}\0" \
- 	"updatekernel=tftp 3000000 ${kernelfile};protect off 1:4-35\;erase 1:4-35;cp.b 3000000 c0080000 ${filesize}\0" \
-	"updateboot=tftp 3000000 ${bootfile};protect off 1:1-3\;erase 1:1-3;cp.b 3000000 c0020000 ${filesize}\0" \
-	"updateuloader=tftp 3000000 uloader.bin;protect off 1:0-1\;erase 1:0-1;cp.b 3000000 c0000000 ${filesize}\0" \
+	"fsfile=rootfs.squashfs\0" \
+	"updatefs=run getip;protect off 1:36-511\;erase 1:36-511\;tftp c0480000 ${fsfile}\0" \
+	"updatekernel=run getip;tftp 3000000 ${kernelfile};protect off 1:4-35\;erase 1:4-35;cp.b 3000000 c0080000 ${filesize}\0" \
+	"updateboot=run getip;tftp 3000000 ${bootfile};protect off 1:1-2\;erase 1:1-2;cp.b 3000000 c0020000 ${filesize}\0" \
+	"updateuloader=run getip;tftp 3000000 uloader.bin;protect off 1:0-0\;erase 1:0-0;cp.b 3000000 c0000000 ${filesize}\0" \
 	""
 
 #define CONFIG_ETHADDR		00:aa:bb:cc:dd:ee
-#define CONFIG_IPADDR		192.168.0.2
-#define CONFIG_SERVERIP		192.168.0.1
 //#define CONFIG_BOOTDELAY	3
 
 #include <cmd_confdefs.h>
@@ -155,11 +154,7 @@
  */
 #define	CONFIG_SYS_LONGHELP			/* undef to save memory		*/
 #define	CONFIG_SYS_PROMPT	"=> "		/* Monitor Command Prompt	*/
-#if defined(CONFIG_CMD_KGDB)
-#define	CONFIG_SYS_CBSIZE	1024		/* Console I/O Buffer Size	*/
-#else
-#define	CONFIG_SYS_CBSIZE	256		/* Console I/O Buffer Size	*/
-#endif
+#define	CONFIG_SYS_CBSIZE	4096		/* Console I/O Buffer Size	*/
 #define	CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE+sizeof(CONFIG_SYS_PROMPT)+16) /* Print Buffer Size */
 #define	CONFIG_SYS_MAXARGS	16		/* max number of command args	*/
 #define CONFIG_SYS_BARGSIZE	CONFIG_SYS_CBSIZE	/* Boot Argument Buffer Size	*/
@@ -200,6 +195,7 @@
 
 #define CFG_MAX_FLASH_SECT		1024	/* max # of sectors on one chip */
 #undef CFG_FLASH_PROTECTION
+#define CFG_DIRECT_FLASH_TFTP		1	/* tftp direct to NOR flash */
 
 #define PHYS_FLASH1			0xC0000000 //EXP_CS0_BASEADDR	/* Flash Bank #1 */
 #define PHYS_FLASH1_SECT_SIZE		0x00020000	/* 128 KiB sectors */
@@ -268,11 +264,8 @@
 /*
  * NAND Configuration
  */
-#if (CONFIG_COMMANDS & CFG_CMD_NAND)
 #define CONFIG_SYS_MAX_NAND_DEVICE      1         /* Max number of NAND devices */
-
 #define CONFIG_SYS_NAND_SELF_INIT
-
 #define CONFIG_SYS_NAND_ONFI_DETECTION
 
 /* NAND debugging */
@@ -283,6 +276,7 @@
 #define CONFIG_MTD_DEBUG
 #define CONFIG_MTD_DEBUG_VERBOSE 1
 
+#define CONFIG_CMD_MTDPARTS 1
 
 #define EXP_CS0_BASE_VAL	0x0
 #define EXP_CS0_SEG_SIZE_VAL    0x7FFF
@@ -311,26 +305,19 @@
 #define CONFIG_SYS_NAND_BASE_LIST       { COMCERTO_EXP_CS4_BASE_ADDR }
 #define CONFIG_SYS_NAND_BASE       COMCERTO_EXP_CS4_BASE_ADDR
 
-//In case MLC NAND is used on the Asic Board, comment this out
-//#define CONFIG_NAND_TYPE_SLC
-
-#if defined (CONFIG_NAND_TYPE_SLC)
-#define COMCERTO_NAND_FLASH_SIZE        (512UL * 1024UL * 1024UL)
-#else
 #define COMCERTO_NAND_FLASH_SIZE        (2UL * 1024UL * 1024UL * 1024UL)
-#endif
 
 #define CFG_NAND_BASE			COMCERTO_EXP_CS4_BASE_ADDR
 #define CFG_MAX_NAND_DEVICE		1
 #define NAND_MAX_CHIPS			1
 #define CONFIG_JFFS2_NAND		1
+#define CONFIG_JFFS2_CMDLINE		1
 
-#endif
 #if (CONFIG_COMMANDS & CFG_CMD_FLASH)
 //TODO
 #else
 /*
- *EEPORM boot loader does the relocate and lowlevel init work
+ * EEPROM boot loader does the relocate and lowlevel init work
  */
 //#define CONFIG_SKIP_RELOCATE_UBOOT
 //#define CONFIG_SKIP_LOWLEVEL_INIT
@@ -352,35 +339,22 @@
  * JFFS2 Configuration
  */
 /* mtdparts command line support */
-//#define CONFIG_JFFS2_CMDLINE
+/* TODO(apenwarr): nand support depends on this for no good reason.
+#define CONFIG_JFFS2_CMDLINE
 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
 //#define CFG_JFFS2_SORT_FRAGMENTS
 #endif /* CFG_CMD_JFFS2 */
 
-#if (CONFIG_COMMANDS & CFG_CMD_NAND)
-#define MTDIDS_DEFAULT		"nand0=comcertonand"
-#define MTDPARTS_DEFAULT	"mtdparts=comcertonand:256k(u-boot),128k(env),16000k(fs)"
-#define MTDPARTITION_DEFAULT	"nand0,2"
-#define ROOT_MTDBLOCK		"/dev/mtdblock3"
-#else
-#define MTDIDS_DEFAULT		"nor0=comcertoflash.0"
-#define MTDPARTS_DEFAULT	"mtdparts=comcertoflash.0:128k(uloader),256k(u-boot),128k(env),4M(kernel),16M(fs)"
-#define MTDPARTITION_DEFAULT	"nor0,3"
-#define ROOT_MTDBLOCK		"/dev/mtdblock3"
-#endif
+// TODO(apenwarr): once hnvram is fixed/replaced, drop out NOR altogether
+#define MTDIDS_DEFAULT		"nor0=comcertoflash.0,nand0=comcertonand"
+#define MTDPARTS_DEFAULT \
+  "mtdparts=" \
+  "comcertoflash.0:128k(uloader),256k(u-boot),128k(env),4M(norkernel),50M(norfs),2M(hnvram),2M(nvram);" \
+  "comcertonand:256k(reserved-u-boot),768k(reserved-env),32M(kernel0),32M(kernel1),288M(rootfs0),288M(rootfs1),32M(emergency),350M(data+ubi);"
+
 
 #define CFG_HZ                  1000
 
-#if 0
-#define CFG_REFCLKFREQ		24000000	/* 24 MHz */
-
-#define CFG_HZ			2000
-//#define CFG_CLK			CFG_CLK_650_187_375
-//#define CFG_PHY_CLOCK		125000000	/* 125 MHz*/
-//#define CFG_GEM0_CLOCK		 25000000	/*  25 MHz*/
-//#define CFG_GEM1_CLOCK		 25000000	/*  25 MHz*/
-#endif
-
 /*
  * Initial stack configuration
  */
@@ -390,8 +364,6 @@
 
 #define CFG_INIT_SP_OFFSET	CFG_GBL_DATA_OFFSET - CFG_ARAM_CODE_SIZE
 
-
-
 /*
  * Malloc/stack configuration
  */