From 8ea84aa414e204c3259861da80d11ff7cc9fded7 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Fri, 24 Jul 2009 15:40:52 -0400
Subject: [PATCH] unify {CONFIG_,}ENV_IS_EMBEDDED

Some boards have fallen out of sync by defining CONFIG_ENV_IS_EMBEDDED
manually.  While it is useful to have this available to the build system,
let's do it automatically rather than forcing people to opt into it.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 include/configs/EB+MCF-EV123.h |    1 -
 include/configs/M52277EVB.h    |    1 -
 include/configs/M5235EVB.h     |    1 -
 include/configs/M5272C3.h      |    1 -
 include/configs/M5275EVB.h     |    1 -
 include/configs/M5329EVB.h     |    1 -
 include/configs/M5373EVB.h     |    1 -
 include/configs/M54451EVB.h    |    1 -
 include/configs/M54455EVB.h    |    1 -
 include/configs/M5475EVB.h     |    1 -
 include/configs/M5485EVB.h     |    1 -
 include/configs/OXC.h          |    1 -
 include/configs/cobra5272.h    |    1 -
 include/configs/pcu_e.h        |    1 -
 include/environment.h          |   33 +++++++++++++++++++++++++++------
 15 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/include/configs/EB+MCF-EV123.h b/include/configs/EB+MCF-EV123.h
index a13db7c..dfdb6c1 100644
--- a/include/configs/EB+MCF-EV123.h
+++ b/include/configs/EB+MCF-EV123.h
@@ -55,7 +55,6 @@
 #define CONFIG_ENV_SECT_SIZE	0x4000
 #define CONFIG_ENV_IS_IN_FLASH	1
 /*
-#define CONFIG_ENV_IS_EMBEDDED	1
 #define CONFIG_ENV_ADDR_REDUND		0xF0018000
 #define CONFIG_ENV_SECT_SIZE_REDUND	0x4000
 */
diff --git a/include/configs/M52277EVB.h b/include/configs/M52277EVB.h
index 053a914..530d92c 100644
--- a/include/configs/M52277EVB.h
+++ b/include/configs/M52277EVB.h
@@ -259,7 +259,6 @@
 #	define CONFIG_ENV_IS_IN_FLASH	1
 #endif
 #define CONFIG_ENV_OVERWRITE		1
-#undef CONFIG_ENV_IS_EMBEDDED
 
 /*-----------------------------------------------------------------------
  * FLASH organization
diff --git a/include/configs/M5235EVB.h b/include/configs/M5235EVB.h
index 6b26c0b..2b816ce 100644
--- a/include/configs/M5235EVB.h
+++ b/include/configs/M5235EVB.h
@@ -222,7 +222,6 @@
  * Environment is embedded in u-boot in the second sector of the flash
  */
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 #ifdef NORFLASH_PS32BIT
 #	define CONFIG_ENV_OFFSET		(0x8000)
 #	define CONFIG_ENV_SIZE		0x4000
diff --git a/include/configs/M5272C3.h b/include/configs/M5272C3.h
index fc73d64..f824158 100644
--- a/include/configs/M5272C3.h
+++ b/include/configs/M5272C3.h
@@ -55,7 +55,6 @@
 #define CONFIG_ENV_OFFSET		0x4000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 #else
 #define CONFIG_ENV_ADDR		0xffe04000
 #define CONFIG_ENV_SECT_SIZE	0x2000
diff --git a/include/configs/M5275EVB.h b/include/configs/M5275EVB.h
index 210bb2d..b380159 100644
--- a/include/configs/M5275EVB.h
+++ b/include/configs/M5275EVB.h
@@ -55,7 +55,6 @@
 #define CONFIG_ENV_OFFSET		0x4000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 #else
 #define CONFIG_ENV_ADDR		0xffe04000
 #define CONFIG_ENV_SECT_SIZE	0x2000
diff --git a/include/configs/M5329EVB.h b/include/configs/M5329EVB.h
index a2d17c3..8180c05 100644
--- a/include/configs/M5329EVB.h
+++ b/include/configs/M5329EVB.h
@@ -231,7 +231,6 @@
 #define CONFIG_ENV_OFFSET		0x4000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 
 /*-----------------------------------------------------------------------
  * Cache Configuration
diff --git a/include/configs/M5373EVB.h b/include/configs/M5373EVB.h
index 98d800f..8652a80 100644
--- a/include/configs/M5373EVB.h
+++ b/include/configs/M5373EVB.h
@@ -231,7 +231,6 @@
 #define CONFIG_ENV_OFFSET		0x4000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 
 /*-----------------------------------------------------------------------
  * Cache Configuration
diff --git a/include/configs/M54451EVB.h b/include/configs/M54451EVB.h
index 45f7016..86d3b05 100644
--- a/include/configs/M54451EVB.h
+++ b/include/configs/M54451EVB.h
@@ -277,7 +277,6 @@
 #	define CONFIG_ENV_SECT_SIZE	0x2000
 #endif
 #undef CONFIG_ENV_OVERWRITE
-#undef CONFIG_ENV_IS_EMBEDDED
 
 /*-----------------------------------------------------------------------
  * FLASH organization
diff --git a/include/configs/M54455EVB.h b/include/configs/M54455EVB.h
index 87f3a73..68227cd 100644
--- a/include/configs/M54455EVB.h
+++ b/include/configs/M54455EVB.h
@@ -336,7 +336,6 @@
 #	define CONFIG_ENV_IS_IN_FLASH	1
 #endif
 #undef CONFIG_ENV_OVERWRITE
-#undef CONFIG_ENV_IS_EMBEDDED
 
 /*-----------------------------------------------------------------------
  * FLASH organization
diff --git a/include/configs/M5475EVB.h b/include/configs/M5475EVB.h
index e48de15..4534002 100644
--- a/include/configs/M5475EVB.h
+++ b/include/configs/M5475EVB.h
@@ -280,7 +280,6 @@
 #define CONFIG_ENV_OFFSET		0x2000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 
 /*-----------------------------------------------------------------------
  * Cache Configuration
diff --git a/include/configs/M5485EVB.h b/include/configs/M5485EVB.h
index 28bf0ad..971cb67 100644
--- a/include/configs/M5485EVB.h
+++ b/include/configs/M5485EVB.h
@@ -266,7 +266,6 @@
 #define CONFIG_ENV_OFFSET		0x2000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 
 /*-----------------------------------------------------------------------
  * Cache Configuration
diff --git a/include/configs/OXC.h b/include/configs/OXC.h
index 104c23f..74c51f4 100644
--- a/include/configs/OXC.h
+++ b/include/configs/OXC.h
@@ -196,7 +196,6 @@
 #define CONFIG_ENV_IS_IN_FLASH	1
 #define CONFIG_ENV_ADDR		0xFFF30000	/* Offset of Environment Sector	*/
 #define CONFIG_ENV_SIZE		0x00010000	/* Total Size of Environment Sector */
-#define	CONFIG_ENV_IS_EMBEDDED	1		/* short-cut compile-time test	*/
 #define CONFIG_ENV_OVERWRITE    1		/* Allow modifying the environment */
 
 /*
diff --git a/include/configs/cobra5272.h b/include/configs/cobra5272.h
index fb32f3f..1c3ea23 100644
--- a/include/configs/cobra5272.h
+++ b/include/configs/cobra5272.h
@@ -127,7 +127,6 @@
 #define CONFIG_ENV_OFFSET		0x4000
 #define CONFIG_ENV_SECT_SIZE	0x2000
 #define CONFIG_ENV_IS_IN_FLASH	1
-#define CONFIG_ENV_IS_EMBEDDED	1
 #else
 #define CONFIG_ENV_ADDR		0xffe04000
 #define CONFIG_ENV_SECT_SIZE	0x2000
diff --git a/include/configs/pcu_e.h b/include/configs/pcu_e.h
index 7c2bf1b..6517381 100644
--- a/include/configs/pcu_e.h
+++ b/include/configs/pcu_e.h
@@ -231,7 +231,6 @@
 #define CONFIG_ENV_SIZE		0x2000	/* Total Size of Environment		*/
 #define CONFIG_ENV_ADDR	    0xFFFFE000	/* Address    of Environment Sector	*/
 #define CONFIG_ENV_SECT_SIZE	0x2000	/* use the top-most 8k boot sector	*/
-#define	CONFIG_ENV_IS_EMBEDDED	1	/* short-cut compile-time test		*/
 #else
 /* Final version: environment in EEPROM */
 #define CONFIG_ENV_IS_IN_EEPROM	1
diff --git a/include/environment.h b/include/environment.h
index 5bed32f..6188457 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -67,6 +67,10 @@
 # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
 #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT	1
 # endif
+# ifdef CONFIG_ENV_IS_EMBEDDED
+#  error "do not define CONFIG_ENV_IS_EMBEDDED in your board config"
+#  error "it is calculated automatically for you"
+# endif
 #endif	/* CONFIG_ENV_IS_IN_FLASH */
 
 #if defined(CONFIG_ENV_IS_IN_NAND)
@@ -79,9 +83,6 @@
 # ifdef CONFIG_ENV_OFFSET_REDUND
 #  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
 # endif
-# ifdef CONFIG_ENV_IS_EMBEDDED
-#  define ENV_IS_EMBEDDED	1
-# endif
 #endif /* CONFIG_ENV_IS_IN_NAND */
 
 #if defined(CONFIG_ENV_IS_IN_MG_DISK)
@@ -91,11 +92,31 @@
 # ifndef CONFIG_ENV_SIZE
 #  error "Need to define CONFIG_ENV_SIZE when using CONFIG_ENV_IS_IN_MG_DISK"
 # endif
-# ifdef CONFIG_ENV_IS_EMBEDDED
-#  error "CONFIG_ENV_IS_EMBEDDED not supported when using CONFIG_ENV_IS_IN_MG_DISK"
-# endif
 #endif /* CONFIG_ENV_IS_IN_MG_DISK */
 
+/* Embedded env is only supported for some flash types */
+#ifdef CONFIG_ENV_IS_EMBEDDED
+# if !defined(CONFIG_ENV_IS_IN_FLASH) && \
+     !defined(CONFIG_ENV_IS_IN_NAND) && \
+     !defined(CONFIG_ENV_IS_IN_ONENAND)
+#  error "CONFIG_ENV_IS_EMBEDDED not supported for your flash type"
+#endif
+
+/*
+ * For the flash types where embedded env is supported, but it cannot be
+ * calculated automatically (i.e. NAND), take the board opt-in.
+ */
+#if defined(CONFIG_ENV_IS_EMBEDDED) && !defined(ENV_IS_EMBEDDED)
+# define ENV_IS_EMBEDDED 1
+#endif
+
+/* The build system likes to know if the env is embedded */
+#ifdef DO_DEPS_ONLY
+# ifdef ENV_IS_EMBEDDED
+#  define CONFIG_ENV_IS_EMBEDDED
+# endif
+#endif
+
 #include "compiler.h"
 
 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
-- 
1.6.3.3

