From 6b31b0e7d881b741e020d799f4d5bc1165241797 Mon Sep 17 00:00:00 2001
From: Jason Kridner <jkridner@beagleboard.org>
Date: Tue, 3 Feb 2009 19:34:34 -0600
Subject: [PATCH 3/4] OMAP3: BeagleBoard: Additional build to ignore environment variables

Builds now performed as 'make beagle' and they will generate
two versions of u-boot.  u-boot.bin is meant to be placed on
SD cards and will always ignore the environment variables that
are stored on flash and execute the default environment.  The
u-boot-f.bin is meant to be stored on the flash and will work
normally, reading the environment off of the flash.

Signed-off-by: Jason Kridner <jkridner@beagleboard.org>
---
 Makefile            |   12 +++++++++++
 common/env_common.c |    6 ++++-
 doc/README.omap3    |    3 +-
 mkbootscr           |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+), 3 deletions(-)
 create mode 100755 mkbootscr

diff --git a/Makefile b/Makefile
index 787c5f2..d65079e 100644
--- a/Makefile
+++ b/Makefile
@@ -151,8 +151,12 @@ ifeq ($(ARCH),ppc)
 CROSS_COMPILE = ppc_8xx-
 endif
 ifeq ($(ARCH),arm)
+ifeq ($(CPU),arm_cortexa8)
+CROSS_COMPILE = arm-none-linux-gnueabi-
+else
 CROSS_COMPILE = arm-linux-
 endif
+endif
 ifeq ($(ARCH),i386)
 CROSS_COMPILE = i386-linux-
 endif
@@ -2935,6 +2939,14 @@ omap3_pandora_config :	unconfig
 omap3_zoom1_config :	unconfig
 	@$(MKCONFIG) $(@:_config=) arm arm_cortexa8 zoom1 omap3 omap3
 
+beagle :	unconfig
+		@$(MKCONFIG) omap3_beagle arm arm_cortexa8 beagle omap3 omap3
+		$(MAKE) || exit 1
+		mv u-boot.bin u-boot-f.bin
+		echo "#define CONFIG_OVERRIDE_BOOTENV 1" >>$(obj)include/config.h
+		$(MAKE) || exit 1
+		./mkbootscr
+
 #########################################################################
 ## XScale Systems
 #########################################################################
diff --git a/common/env_common.c b/common/env_common.c
index 6be3bb0..6f39f10 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -251,8 +251,12 @@ void env_relocate (void)
 	DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
 #endif
 
+#ifdef CONFIG_OVERRIDE_BOOTENV
+	gd->env_valid = 0;
+#endif
 	if (gd->env_valid == 0) {
-#if defined(CONFIG_GTH)	|| defined(CONFIG_ENV_IS_NOWHERE)	/* Environment not changable */
+#if defined(CONFIG_GTH)	|| defined(CONFIG_ENV_IS_NOWHERE) \
+	|| defined(CONFIG_OVERRIDE_BOOTENV)			/* Environment not changable */
 		puts ("Using default environment\n\n");
 #else
 		puts ("*** Warning - bad CRC, using default environment\n\n");
diff --git a/doc/README.omap3 b/doc/README.omap3
index 1ba307f..03fc53e 100644
--- a/doc/README.omap3
+++ b/doc/README.omap3
@@ -31,8 +31,7 @@ Build
 
 * BeagleBoard:
 
-make omap3_beagle_config
-make
+make beagle
 
 * Gumstix Overo:
 
diff --git a/mkbootscr b/mkbootscr
new file mode 100755
index 0000000..d175c25
--- /dev/null
+++ b/mkbootscr
@@ -0,0 +1,53 @@
+#!/bin/sh
+cat <<EOF > normal.cmd
+if fatload mmc 0 80200000 uImage.bin
+then
+ echo ***** Kernel: /dev/mmcblk0p1/uImage.bin *****
+else
+ echo ***** Kernel: /dev/mtd3 *****
+ nand read 80200000 280000 400000
+fi
+if fatload mmc 0 81600000 ramdisk.gz
+then
+ echo ***** RootFS: /dev/mmcblk0p1/ramdisk.gz *****
+ setenv bootargs 'console=ttyS2,115200n8 console=tty0 root=/dev/ram0 rw ramdisk_size=32768 initrd=0x81600000,32M'
+else
+ echo ***** RootFS: /dev/mmcblk0p2 *****
+ setenv bootargs 'console=ttyS2,115200n8 console=tty0 root=/dev/mmcblk0p2 rw rootwait'
+fi
+bootm 80200000
+EOF
+
+mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Execute uImage.bin' -d normal.cmd normal.scr
+
+cat <<EOF_FLASH > reset.cmd
+if fatload mmc 0 80200000 x-load.bin.ift
+then
+ echo ***** Replacing x-load *****
+ nand unlock
+ nandecc hw
+ nand erase 0 80000
+ nand write 80200000 0 20000
+ nand write 80200000 20000 20000
+ nand write 80200000 40000 20000
+ nand write 80200000 60000 20000
+fi
+if fatload mmc 0 80200000 u-boot-f.bin
+then
+ echo ***** Replacing u-boot *****
+ nand unlock
+ nandecc sw
+ nand erase 80000 160000
+ nand write 80200000 80000 160000
+fi
+echo ***** Erasing environment settings *****
+nand unlock
+nand erase 160000 20000
+if fatload mmc 0 80200000 normal.scr
+then
+ echo ***** Executing normal.scr *****
+ autoscr 80200000
+fi
+EOF_FLASH
+
+mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Reset flash' -d reset.cmd reset.scr
-- 
1.6.0.4.790.gaa14a

