From 3b57fe0a70b903f4db66c558bb9828bc58acf06b Mon Sep 17 00:00:00 2001
From: wdenk <wdenk>
Date: Fri, 30 May 2003 12:48:29 +0000
Subject: [PATCH] * Get (mostly) rid of CFG_MONITOR_LEN definition; compute
 real length   instead CFG_MONITOR_LEN is now only used to determine 
 _at_compile_   _time_  (!) if the environment is embedded within the U-Boot
 image,   or in a separate flash sector.

* Cleanup CFG_DER #defines in config files (wd maintained only)
---
 CHANGELOG                          |  7 +++++++
 README                             | 19 +++++++++++--------
 board/LEOX/elpt860/flash.c         |  2 +-
 board/MAI/AmigaOneG3SE/flash_new.c |  2 +-
 board/RPXClassic/flash.c           |  2 +-
 board/RPXlite/flash.c              |  2 +-
 board/RRvision/flash.c             |  2 +-
 board/atc/flash.c                  |  2 +-
 board/bmw/flash.c                  |  2 +-
 board/c2mon/flash.c                |  4 ++--
 board/cmi/flash.c                  |  2 +-
 board/cogent/flash.c               |  2 +-
 board/cpc45/flash.c                |  4 ++--
 board/cpu86/flash.c                |  4 ++--
 board/cradle/flash.c               |  2 +-
 board/cray/L1/flash.c              |  2 +-
 board/csb226/flash.c               |  2 +-
 board/cu824/flash.c                |  4 ++--
 board/dnp1110/flash.c              |  2 +-
 board/eltec/bab7xx/flash.c         |  6 +++---
 board/eltec/elppc/flash.c          |  6 +++---
 board/eltec/mhpc/flash.c           |  2 +-
 board/ep7312/flash.c               |  2 +-
 board/ep8260/flash.c               |  2 +-
 board/eric/flash.c                 | 12 ++++++------
 board/esd/adciop/flash.c           |  6 +++---
 board/esd/ar405/flash.c            |  6 +++---
 board/esd/canbt/flash.c            |  2 +-
 board/esd/cpci405/flash.c          |  6 +++---
 board/esd/cpci440/strataflash.c    |  2 +-
 board/esd/cpciiser4/flash.c        |  2 +-
 board/esd/dasa_sim/flash.c         |  2 +-
 board/esd/du405/flash.c            |  6 +++---
 board/esd/ocrtc/flash.c            |  6 +++---
 board/esd/pci405/flash.c           |  2 +-
 board/esteem192e/flash.c           |  4 ++--
 board/etx094/flash.c               |  4 ++--
 board/fads/flash.c                 |  2 +-
 board/flagadm/flash.c              |  2 +-
 board/gen860t/flash.c              |  2 +-
 board/genietv/flash.c              |  2 +-
 board/gth/flash.c                  |  4 ++--
 board/gw8260/flash.c               |  2 +-
 board/hermes/flash.c               |  2 +-
 board/hymod/flash.c                |  2 +-
 board/icu862/flash.c               |  2 +-
 board/impa7/flash.c                |  2 +-
 board/incaip/flash.c               |  2 +-
 board/ip860/flash.c                |  2 +-
 board/iphase4539/flash.c           |  2 +-
 board/ivm/flash.c                  |  2 +-
 board/kup4k/flash.c                |  2 +-
 board/lantec/flash.c               |  4 ++--
 board/lart/flash.c                 |  2 +-
 board/lubbock/flash.c              |  2 +-
 board/lwmon/flash.c                |  4 ++--
 board/mbx8xx/flash.c               |  2 +-
 board/mpc8260ads/flash.c           |  2 +-
 board/mpc8266ads/flash.c           |  2 +-
 board/mpl/common/flash.c           |  2 +-
 board/mpl/vcma9/flash.c            |  2 +-
 board/musenki/flash.c              |  6 +++---
 board/mvs1/flash.c                 |  4 ++--
 board/netvia/flash.c               |  2 +-
 board/nx823/flash.c                |  2 +-
 board/oxc/flash.c                  |  2 +-
 board/pcippc2/flash.c              |  2 +-
 board/pm826/flash.c                |  2 +-
 board/ppmc8260/strataflash.c       |  2 +-
 board/purple/flash.c               |  2 +-
 board/purple/purple.c              |  3 ++-
 board/r360mpi/flash.c              |  2 +-
 board/rpxsuper/flash.c             |  2 +-
 board/rsdproto/flash.c             |  4 ++--
 board/sacsng/flash.c               |  4 ++--
 board/sandpoint/flash.c            |  2 +-
 board/sbc8260/flash.c              |  2 +-
 board/shannon/flash.c              |  2 +-
 board/siemens/CCM/flash.c          |  4 ++--
 board/siemens/SCM/flash.c          |  2 +-
 board/siemens/pcu_e/flash.c        |  2 +-
 board/sixnet/flash.c               |  2 +-
 board/smdk2400/flash.c             |  2 +-
 board/smdk2410/flash.c             |  2 +-
 board/svm_sc8xx/flash.c            |  4 ++--
 board/tqm8260/flash.c              |  2 +-
 board/tqm8xx/flash.c               |  4 ++--
 board/trab/flash.c                 |  2 +-
 board/utx8245/flash.c              |  2 +-
 board/v37/flash.c                  |  2 +-
 board/w7o/flash.c                  |  2 +-
 board/walnut405/flash.c            |  8 ++++----
 board/wepep250/flash.c             |  2 +-
 board/westel/amx860/flash.c        |  4 ++--
 cpu/74xx_7xx/start.S               | 15 +++++----------
 cpu/mips/start.S                   |  3 ++-
 cpu/mpc5xx/start.S                 | 11 +++--------
 cpu/mpc824x/start.S                | 11 +++--------
 cpu/mpc8260/start.S                | 11 +++--------
 cpu/mpc8xx/start.S                 | 11 +++--------
 cpu/ppc4xx/start.S                 | 11 +++--------
 include/common.h                   |  1 +
 include/configs/ETX094.h           |  1 -
 include/configs/FPS850L.h          |  1 -
 include/configs/FPS860L.h          |  1 -
 include/configs/IP860.h            |  1 -
 include/configs/IVML24.h           |  1 -
 include/configs/IVMS8.h            |  1 -
 include/configs/KUP4K.h            |  1 -
 include/configs/LANTEC.h           |  1 -
 include/configs/R360MPI.h          |  3 +--
 include/configs/RRvision.h         |  1 -
 include/configs/SM850.h            |  1 -
 include/configs/SPD823TS.h         |  1 -
 include/configs/TQM823L.h          |  1 -
 include/configs/TQM850L.h          |  1 -
 include/configs/TQM855L.h          |  1 -
 include/configs/TQM860L.h          |  1 -
 include/configs/TQM862L.h          |  1 -
 include/configs/c2mon.h            |  1 -
 include/configs/hermes.h           |  1 -
 include/configs/lwmon.h            |  1 -
 lib_arm/board.c                    |  4 ++++
 lib_mips/board.c                   | 15 +++++++++++----
 lib_ppc/board.c                    | 24 +++++++++++-------------
 125 files changed, 201 insertions(+), 229 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index f28631a6878..3a97de7e1d0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,13 @@
 Changes since U-Boot 0.3.1:
 ======================================================================
 
+* Get (mostly) rid of CFG_MONITOR_LEN definition; compute real length
+  instead CFG_MONITOR_LEN is now only used to determine  _at_compile_
+  _time_  (!) if the environment is embedded within the U-Boot image,
+  or in a separate flash sector.
+
+* Cleanup CFG_DER #defines in config files (wd maintained only)
+
 * Fix data abort exception handling for arm920t CPU
 
 * Fix alignment problems with flash driver for TRAB board
diff --git a/README b/README
index e9b714567f9..06fade67fab 100644
--- a/README
+++ b/README
@@ -1183,13 +1183,13 @@ The following options need to be configured:
 
 	Note:
 
-		In the current implementation, the local variables
-		space and global environment variables space are
-		separated. Local variables are those you define by
-		simply typing like `name=value'. To access a local
-		variable later on, you have write `$name' or
-		`${name}'; variable directly by typing say `$name' at
-		the command prompt.
+                In the current implementation, the local variables
+                space and global environment variables space are
+                separated. Local variables are those you define by
+                simply typing `name=value'. To access a local
+                variable later on, you have write `$name' or
+                `${name}'; to execute the contents of a variable
+                directly type `$name' at the command prompt.
 
 		Global environment variables are those you use
 		setenv/printenv to work with. To run a command stored
@@ -1389,7 +1389,10 @@ Configuration Settings:
 		CFG_FLASH_BASE when booting from flash.
 
 - CFG_MONITOR_LEN:
-		Size of memory reserved for monitor code
+                Size of memory reserved for monitor code, used to
+                determine _at_compile_time_ (!) if the environment is
+                embedded within the U-Boot image, or in a separate
+                flash sector.
 
 - CFG_MALLOC_LEN:
 		Size of DRAM reserved for malloc() use.
diff --git a/board/LEOX/elpt860/flash.c b/board/LEOX/elpt860/flash.c
index a9238e16cfe..7107aaa6c26 100644
--- a/board/LEOX/elpt860/flash.c
+++ b/board/LEOX/elpt860/flash.c
@@ -118,7 +118,7 @@ flash_init (void)
   /* monitor protection ON by default */
   flash_protect (FLAG_PROTECT_SET,
 		 CFG_MONITOR_BASE,
-		 CFG_MONITOR_BASE + CFG_MONITOR_LEN-1,
+		 CFG_MONITOR_BASE + monitor_flash_len-1,
 		 &flash_info[0]);
 #endif
   
diff --git a/board/MAI/AmigaOneG3SE/flash_new.c b/board/MAI/AmigaOneG3SE/flash_new.c
index 6eebeba0f21..3fb9f1246b4 100644
--- a/board/MAI/AmigaOneG3SE/flash_new.c
+++ b/board/MAI/AmigaOneG3SE/flash_new.c
@@ -120,7 +120,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+			      CFG_MONITOR_BASE + monitor_flash_len - 1,
 			      &flash_info[0]);
 #endif
 
diff --git a/board/RPXClassic/flash.c b/board/RPXClassic/flash.c
index 62934975fef..fdf90cfa94e 100644
--- a/board/RPXClassic/flash.c
+++ b/board/RPXClassic/flash.c
@@ -64,7 +64,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/RPXlite/flash.c b/board/RPXlite/flash.c
index 78c1838b792..846794df3f7 100644
--- a/board/RPXlite/flash.c
+++ b/board/RPXlite/flash.c
@@ -85,7 +85,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/RRvision/flash.c b/board/RRvision/flash.c
index 06f7c4b7ac2..d8e07e6450f 100644
--- a/board/RRvision/flash.c
+++ b/board/RRvision/flash.c
@@ -73,7 +73,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/atc/flash.c b/board/atc/flash.c
index 7e971822e07..6d7b38bde84 100644
--- a/board/atc/flash.c
+++ b/board/atc/flash.c
@@ -91,7 +91,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      flash_get_info(CFG_MONITOR_BASE));
 #endif
 
diff --git a/board/bmw/flash.c b/board/bmw/flash.c
index 6a7649ffe5a..be622743f09 100644
--- a/board/bmw/flash.c
+++ b/board/bmw/flash.c
@@ -219,7 +219,7 @@ flash_init(void)
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
     flash_protect(FLAG_PROTECT_SET,
 		CFG_MONITOR_BASE,
-		CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+		CFG_MONITOR_BASE + monitor_flash_len - 1,
 		&flash_info[0]);
 #endif
 
diff --git a/board/c2mon/flash.c b/board/c2mon/flash.c
index 181f82af2f4..b2be21c6845 100644
--- a/board/c2mon/flash.c
+++ b/board/c2mon/flash.c
@@ -91,7 +91,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -118,7 +118,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/cmi/flash.c b/board/cmi/flash.c
index b41ff12520e..9c802b9131d 100644
--- a/board/cmi/flash.c
+++ b/board/cmi/flash.c
@@ -106,7 +106,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/cogent/flash.c b/board/cogent/flash.c
index 86da80edb81..969520d277b 100644
--- a/board/cogent/flash.c
+++ b/board/cogent/flash.c
@@ -323,7 +323,7 @@ flash_init(void)
 #if CFG_MONITOR_BASE == CFG_FLASH_BASE
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/cpc45/flash.c b/board/cpc45/flash.c
index 6e81b9c335b..a289d089420 100644
--- a/board/cpc45/flash.c
+++ b/board/cpc45/flash.c
@@ -132,12 +132,12 @@ unsigned long flash_init(void)
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE + FLASH_BANK_SIZE
     flash_protect(FLAG_PROTECT_SET,
               CFG_MONITOR_BASE,
-              CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+              CFG_MONITOR_BASE + monitor_flash_len - 1,
               &flash_info[1]);
 #else
     flash_protect(FLAG_PROTECT_SET,
               CFG_MONITOR_BASE,
-              CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+              CFG_MONITOR_BASE + monitor_flash_len - 1,
               &flash_info[0]);
 #endif
 #endif
diff --git a/board/cpu86/flash.c b/board/cpu86/flash.c
index 8cf761f1e65..0769dc5c626 100644
--- a/board/cpu86/flash.c
+++ b/board/cpu86/flash.c
@@ -218,14 +218,14 @@ unsigned long flash_init (void)
 
 		flash_protect  (FLAG_PROTECT_SET,
 				CFG_MONITOR_BASE,
-				CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[1]
+				CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[1]
 		);
 	}
 #else
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
 	flash_protect (FLAG_PROTECT_SET,
 		       CFG_MONITOR_BASE,
-		       CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[0]
+		       CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]
 	);
 #endif
 #endif
diff --git a/board/cradle/flash.c b/board/cradle/flash.c
index 265b609648b..463026d0ea8 100644
--- a/board/cradle/flash.c
+++ b/board/cradle/flash.c
@@ -73,7 +73,7 @@ ulong flash_init(void)
     */
    flash_protect(FLAG_PROTECT_SET,
                   CFG_FLASH_BASE,
-                  CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+                  CFG_FLASH_BASE + monitor_flash_len - 1,
                   &flash_info[0]);
 
    flash_protect(FLAG_PROTECT_SET,
diff --git a/board/cray/L1/flash.c b/board/cray/L1/flash.c
index 6d66905d9a0..829dbaecbe3 100644
--- a/board/cray/L1/flash.c
+++ b/board/cray/L1/flash.c
@@ -88,7 +88,7 @@ unsigned long flash_init (void)
 	    /* Monitor protection ON by default */
 	    (void)flash_protect(FLAG_PROTECT_SET,
 				FLASH_BASE0_PRELIM,
-				FLASH_BASE0_PRELIM+CFG_MONITOR_LEN-1,
+				FLASH_BASE0_PRELIM+monitor_flash_len-1,
 				&flash_info[0]);
 #endif
 	    size_b1 = 0 ;
diff --git a/board/csb226/flash.c b/board/csb226/flash.c
index c6cb95e2f34..0ee78e6f2fc 100644
--- a/board/csb226/flash.c
+++ b/board/csb226/flash.c
@@ -74,7 +74,7 @@ ulong flash_init(void)
 	/* Protect monitor and environment sectors */
 	flash_protect(FLAG_PROTECT_SET,
 			CFG_FLASH_BASE,
-			CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+			CFG_FLASH_BASE + monitor_flash_len - 1,
 			&flash_info[0]);
 
 	flash_protect(FLAG_PROTECT_SET,
diff --git a/board/cu824/flash.c b/board/cu824/flash.c
index 0cec41ebdbd..61b759ec575 100644
--- a/board/cu824/flash.c
+++ b/board/cu824/flash.c
@@ -125,12 +125,12 @@ unsigned long flash_init(void)
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE + FLASH_BANK_SIZE
     flash_protect(FLAG_PROTECT_SET,
               CFG_MONITOR_BASE,
-              CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+              CFG_MONITOR_BASE + monitor_flash_len - 1,
               &flash_info[1]);
 #else
     flash_protect(FLAG_PROTECT_SET,
               CFG_MONITOR_BASE,
-              CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+              CFG_MONITOR_BASE + monitor_flash_len - 1,
               &flash_info[0]);
 #endif
 #endif
diff --git a/board/dnp1110/flash.c b/board/dnp1110/flash.c
index bb6d2e79959..f4a8b999c61 100644
--- a/board/dnp1110/flash.c
+++ b/board/dnp1110/flash.c
@@ -84,7 +84,7 @@ unsigned long flash_init (void)
      */
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_FLASH_BASE,
-		  CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+		  CFG_FLASH_BASE + monitor_flash_len  - 1,
 		  &flash_info[0]);
 
     flash_protect(FLAG_PROTECT_SET,
diff --git a/board/eltec/bab7xx/flash.c b/board/eltec/bab7xx/flash.c
index 5834c999990..73496a13ded 100644
--- a/board/eltec/bab7xx/flash.c
+++ b/board/eltec/bab7xx/flash.c
@@ -83,21 +83,21 @@ unsigned long flash_init (void)
     {
         (void)flash_protect(FLAG_PROTECT_SET,
                 FLASH_BASE0_PRELIM,
-                FLASH_BASE0_PRELIM+CFG_MONITOR_LEN-1,
+                FLASH_BASE0_PRELIM+monitor_flash_len-1,
                 &flash_info[0]);
     }
     if (size2 == 512*1024)
     {
         (void)flash_protect(FLAG_PROTECT_SET,
                 FLASH_BASE1_PRELIM,
-                FLASH_BASE1_PRELIM+CFG_MONITOR_LEN-1,
+                FLASH_BASE1_PRELIM+monitor_flash_len-1,
                 &flash_info[1]);
     }
     if (size2 == 4*1024*1024)
     {
         (void)flash_protect(FLAG_PROTECT_SET,
                 CFG_FLASH_BASE,
-                CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
+                CFG_FLASH_BASE+monitor_flash_len-1,
                 &flash_info[1]);
     }
 
diff --git a/board/eltec/elppc/flash.c b/board/eltec/elppc/flash.c
index 5834c999990..73496a13ded 100644
--- a/board/eltec/elppc/flash.c
+++ b/board/eltec/elppc/flash.c
@@ -83,21 +83,21 @@ unsigned long flash_init (void)
     {
         (void)flash_protect(FLAG_PROTECT_SET,
                 FLASH_BASE0_PRELIM,
-                FLASH_BASE0_PRELIM+CFG_MONITOR_LEN-1,
+                FLASH_BASE0_PRELIM+monitor_flash_len-1,
                 &flash_info[0]);
     }
     if (size2 == 512*1024)
     {
         (void)flash_protect(FLAG_PROTECT_SET,
                 FLASH_BASE1_PRELIM,
-                FLASH_BASE1_PRELIM+CFG_MONITOR_LEN-1,
+                FLASH_BASE1_PRELIM+monitor_flash_len-1,
                 &flash_info[1]);
     }
     if (size2 == 4*1024*1024)
     {
         (void)flash_protect(FLAG_PROTECT_SET,
                 CFG_FLASH_BASE,
-                CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
+                CFG_FLASH_BASE+monitor_flash_len-1,
                 &flash_info[1]);
     }
 
diff --git a/board/eltec/mhpc/flash.c b/board/eltec/mhpc/flash.c
index 58cfd7047fd..e9c8f9862d4 100644
--- a/board/eltec/mhpc/flash.c
+++ b/board/eltec/mhpc/flash.c
@@ -92,7 +92,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	(void)flash_protect(FLAG_PROTECT_SET,
 			    CFG_FLASH_BASE,
-			    CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
+			    CFG_FLASH_BASE+monitor_flash_len-1,
 			    &flash_info[0]);
 
 	flash_info[0].size = size_b0;
diff --git a/board/ep7312/flash.c b/board/ep7312/flash.c
index 373d238ccf1..1ee0a37a00d 100644
--- a/board/ep7312/flash.c
+++ b/board/ep7312/flash.c
@@ -61,7 +61,7 @@ ulong flash_init (void)
 	 */
 	flash_protect ( FLAG_PROTECT_SET,
 			CFG_FLASH_BASE,
-			CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+			CFG_FLASH_BASE + monitor_flash_len - 1,
 			&flash_info[0]);
 
 	flash_protect ( FLAG_PROTECT_SET,
diff --git a/board/ep8260/flash.c b/board/ep8260/flash.c
index cae8a13dde0..d9dbdbee921 100644
--- a/board/ep8260/flash.c
+++ b/board/ep8260/flash.c
@@ -140,7 +140,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_MONITOR_BASE,
-		  CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		  CFG_MONITOR_BASE+monitor_flash_len-1,
 		  &flash_info[0]);
 #endif
 
diff --git a/board/eric/flash.c b/board/eric/flash.c
index c3f6e15bc54..5dfb620c6cb 100644
--- a/board/eric/flash.c
+++ b/board/eric/flash.c
@@ -83,13 +83,13 @@ unsigned long flash_init (void)
 	    /* Monitor protection ON by default */
 #if 0	    /* sand: */
 	    (void)flash_protect(FLAG_PROTECT_SET,
-				FLASH_BASE0_PRELIM-CFG_MONITOR_LEN+size_b0,
+				FLASH_BASE0_PRELIM-monitor_flash_len+size_b0,
 				FLASH_BASE0_PRELIM-1+size_b0,
 				&flash_info[0]);
 #else
 	    (void)flash_protect(FLAG_PROTECT_SET,
 		      		CFG_MONITOR_BASE,
-		      		CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      		CFG_MONITOR_BASE+monitor_flash_len-1,
 		      		&flash_info[0]);
 #endif
 	    size_b1 = 0 ;
@@ -132,13 +132,13 @@ unsigned long flash_init (void)
 	    /* monitor protection ON by default */
 #if 0	    /* sand: */
 	    (void)flash_protect(FLAG_PROTECT_SET,
-				FLASH_BASE0_PRELIM-CFG_MONITOR_LEN+size_b0,
+				FLASH_BASE0_PRELIM-monitor_flash_len+size_b0,
 				FLASH_BASE0_PRELIM-1+size_b0,
 				&flash_info[0]);
 #else
 	    (void)flash_protect(FLAG_PROTECT_SET,
 		      		CFG_MONITOR_BASE,
-		      		CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      		CFG_MONITOR_BASE+monitor_flash_len-1,
 		      		&flash_info[0]);
 #endif
 
@@ -150,12 +150,12 @@ unsigned long flash_init (void)
 
 	      /* monitor protection ON by default */
 	      (void)flash_protect(FLAG_PROTECT_SET,
-				  base_b1+size_b1-CFG_MONITOR_LEN,
+				  base_b1+size_b1-monitor_flash_len,
 				  base_b1+size_b1-1,
 				  &flash_info[1]);
 	      /* monitor protection OFF by default (one is enough) */
 	      (void)flash_protect(FLAG_PROTECT_CLEAR,
-				  base_b0+size_b0-CFG_MONITOR_LEN,
+				  base_b0+size_b0-monitor_flash_len,
 				  base_b0+size_b0-1,
 				  &flash_info[0]);
 	    } else {
diff --git a/board/esd/adciop/flash.c b/board/esd/adciop/flash.c
index 46ae03b3c06..69618de1fce 100644
--- a/board/esd/adciop/flash.c
+++ b/board/esd/adciop/flash.c
@@ -80,7 +80,7 @@ unsigned long flash_init (void)
 
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
-		      FLASH_BASE0_PRELIM+size_b0-CFG_MONITOR_LEN,
+		      FLASH_BASE0_PRELIM+size_b0-monitor_flash_len,
 		      FLASH_BASE0_PRELIM+size_b0-1,
 		      &flash_info[0]);
 
@@ -93,12 +93,12 @@ unsigned long flash_init (void)
 
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
-			      FLASH_BASE0_PRELIM+size_b0+size_b1-CFG_MONITOR_LEN,
+			      FLASH_BASE0_PRELIM+size_b0+size_b1-monitor_flash_len,
 			      FLASH_BASE0_PRELIM+size_b0+size_b1-1,
 			      &flash_info[1]);
                 /* monitor protection OFF by default (one is enough) */
                 flash_protect(FLAG_PROTECT_CLEAR,
-			      FLASH_BASE0_PRELIM+size_b0-CFG_MONITOR_LEN,
+			      FLASH_BASE0_PRELIM+size_b0-monitor_flash_len,
 			      FLASH_BASE0_PRELIM+size_b0-1,
 			      &flash_info[0]);
 	} else {
diff --git a/board/esd/ar405/flash.c b/board/esd/ar405/flash.c
index 4fa6b2733fd..3a644f9cc56 100644
--- a/board/esd/ar405/flash.c
+++ b/board/esd/ar405/flash.c
@@ -94,7 +94,7 @@ unsigned long flash_init (void)
 
 	/* monitor protection ON by default */
 	(void)flash_protect(FLAG_PROTECT_SET,
-			    base_b0+size_b0-CFG_MONITOR_LEN,
+			    base_b0+size_b0-monitor_flash_len,
 			    base_b0+size_b0-1,
 			    &flash_info[0]);
 
@@ -106,12 +106,12 @@ unsigned long flash_init (void)
 
 		/* monitor protection ON by default */
 		(void)flash_protect(FLAG_PROTECT_SET,
-				    base_b1+size_b1-CFG_MONITOR_LEN,
+				    base_b1+size_b1-monitor_flash_len,
 				    base_b1+size_b1-1,
 				    &flash_info[1]);
                 /* monitor protection OFF by default (one is enough) */
                 (void)flash_protect(FLAG_PROTECT_CLEAR,
-                                    base_b0+size_b0-CFG_MONITOR_LEN,
+                                    base_b0+size_b0-monitor_flash_len,
                                     base_b0+size_b0-1,
                                     &flash_info[0]);
 	} else {
diff --git a/board/esd/canbt/flash.c b/board/esd/canbt/flash.c
index 214948f6d85..685850e84fd 100644
--- a/board/esd/canbt/flash.c
+++ b/board/esd/canbt/flash.c
@@ -74,7 +74,7 @@ unsigned long flash_init (void)
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
diff --git a/board/esd/cpci405/flash.c b/board/esd/cpci405/flash.c
index 02de050b742..e766895bb06 100644
--- a/board/esd/cpci405/flash.c
+++ b/board/esd/cpci405/flash.c
@@ -125,7 +125,7 @@ unsigned long flash_init (void)
 
 	/* monitor protection ON by default */
 	flash_protect (FLAG_PROTECT_SET,
-			base_b0 + size_b0 - CFG_MONITOR_LEN,
+			base_b0 + size_b0 - monitor_flash_len,
 			base_b0 + size_b0 - 1, &flash_info[0]);
 
 	if (size_b1) {
@@ -136,11 +136,11 @@ unsigned long flash_init (void)
 
 		/* monitor protection ON by default */
 		flash_protect (FLAG_PROTECT_SET,
-				base_b1 + size_b1 - CFG_MONITOR_LEN,
+				base_b1 + size_b1 - monitor_flash_len,
 				base_b1 + size_b1 - 1, &flash_info[1]);
 		/* monitor protection OFF by default (one is enough) */
 		flash_protect (FLAG_PROTECT_CLEAR,
-				base_b0 + size_b0 - CFG_MONITOR_LEN,
+				base_b0 + size_b0 - monitor_flash_len,
 				base_b0 + size_b0 - 1, &flash_info[0]);
 	} else {
 		flash_info[1].flash_id = FLASH_UNKNOWN;
diff --git a/board/esd/cpci440/strataflash.c b/board/esd/cpci440/strataflash.c
index 6f6286694bd..de57318e26c 100644
--- a/board/esd/cpci440/strataflash.c
+++ b/board/esd/cpci440/strataflash.c
@@ -200,7 +200,7 @@ unsigned long flash_init (void)
 #if 0 /* test-only */
 	/* Monitor protection ON by default */
 #if (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
-	for(i=0; flash_info[0].start[i] < CFG_MONITOR_BASE+CFG_MONITOR_LEN-1; i++)
+	for(i=0; flash_info[0].start[i] < CFG_MONITOR_BASE+monitor_flash_len-1; i++)
 		(void)flash_real_protect(&flash_info[0], i, 1);
 #endif
 #endif
diff --git a/board/esd/cpciiser4/flash.c b/board/esd/cpciiser4/flash.c
index 214948f6d85..685850e84fd 100644
--- a/board/esd/cpciiser4/flash.c
+++ b/board/esd/cpciiser4/flash.c
@@ -74,7 +74,7 @@ unsigned long flash_init (void)
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
diff --git a/board/esd/dasa_sim/flash.c b/board/esd/dasa_sim/flash.c
index 2574eac7fdc..32cd64cf088 100644
--- a/board/esd/dasa_sim/flash.c
+++ b/board/esd/dasa_sim/flash.c
@@ -67,7 +67,7 @@ unsigned long flash_init (void)
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
diff --git a/board/esd/du405/flash.c b/board/esd/du405/flash.c
index 97d832228ea..14549c0147e 100644
--- a/board/esd/du405/flash.c
+++ b/board/esd/du405/flash.c
@@ -94,7 +94,7 @@ unsigned long flash_init (void)
 
 	/* monitor protection ON by default */
 	flash_protect (FLAG_PROTECT_SET,
-			base_b0 + size_b0 - CFG_MONITOR_LEN,
+			base_b0 + size_b0 - monitor_flash_len,
 			base_b0 + size_b0 - 1, &flash_info[0]);
 
 	if (size_b1) {
@@ -105,11 +105,11 @@ unsigned long flash_init (void)
 
 		/* monitor protection ON by default */
 		flash_protect (FLAG_PROTECT_SET,
-				base_b1 + size_b1 - CFG_MONITOR_LEN,
+				base_b1 + size_b1 - monitor_flash_len,
 				base_b1 + size_b1 - 1, &flash_info[1]);
 		/* monitor protection OFF by default (one is enough) */
 		flash_protect (FLAG_PROTECT_CLEAR,
-				base_b0 + size_b0 - CFG_MONITOR_LEN,
+				base_b0 + size_b0 - monitor_flash_len,
 				base_b0 + size_b0 - 1, &flash_info[0]);
 	} else {
 		flash_info[1].flash_id = FLASH_UNKNOWN;
diff --git a/board/esd/ocrtc/flash.c b/board/esd/ocrtc/flash.c
index 90965eadf5f..c3d8bec9137 100644
--- a/board/esd/ocrtc/flash.c
+++ b/board/esd/ocrtc/flash.c
@@ -127,7 +127,7 @@ unsigned long flash_init (void)
 
 	/* monitor protection ON by default */
 	flash_protect (FLAG_PROTECT_SET,
-			base_b0 + size_b0 - CFG_MONITOR_LEN,
+			base_b0 + size_b0 - monitor_flash_len,
 			base_b0 + size_b0 - 1, &flash_info[0]);
 
 	if (size_b1) {
@@ -138,11 +138,11 @@ unsigned long flash_init (void)
 
 		/* monitor protection ON by default */
 		flash_protect (FLAG_PROTECT_SET,
-				base_b1 + size_b1 - CFG_MONITOR_LEN,
+				base_b1 + size_b1 - monitor_flash_len,
 				base_b1 + size_b1 - 1, &flash_info[1]);
 		/* monitor protection OFF by default (one is enough) */
 		flash_protect (FLAG_PROTECT_CLEAR,
-				base_b0 + size_b0 - CFG_MONITOR_LEN,
+				base_b0 + size_b0 - monitor_flash_len,
 				base_b0 + size_b0 - 1, &flash_info[0]);
 	} else {
 		flash_info[1].flash_id = FLASH_UNKNOWN;
diff --git a/board/esd/pci405/flash.c b/board/esd/pci405/flash.c
index f904affc4f6..1707dcf6e19 100644
--- a/board/esd/pci405/flash.c
+++ b/board/esd/pci405/flash.c
@@ -91,7 +91,7 @@ unsigned long flash_init (void)
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
diff --git a/board/esteem192e/flash.c b/board/esteem192e/flash.c
index 55845fac111..5322430de38 100644
--- a/board/esteem192e/flash.c
+++ b/board/esteem192e/flash.c
@@ -104,7 +104,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	(void)flash_protect(FLAG_PROTECT_SET,
 			    CFG_MONITOR_BASE,
-			    CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			    CFG_MONITOR_BASE+monitor_flash_len-1,
 			    &flash_info[0]);
 #endif
 
@@ -124,7 +124,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		(void)flash_protect(FLAG_PROTECT_SET,
 				    CFG_MONITOR_BASE,
-				    CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+				    CFG_MONITOR_BASE+monitor_flash_len-1,
 				    &flash_info[1]);
 #endif
 	} else {
diff --git a/board/etx094/flash.c b/board/etx094/flash.c
index b3c620e868c..98a7c0c8d77 100644
--- a/board/etx094/flash.c
+++ b/board/etx094/flash.c
@@ -91,7 +91,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -115,7 +115,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 	} else {
diff --git a/board/fads/flash.c b/board/fads/flash.c
index 22a7c410ce4..680a2dc93cc 100644
--- a/board/fads/flash.c
+++ b/board/fads/flash.c
@@ -112,7 +112,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[i]);
 #endif
 
diff --git a/board/flagadm/flash.c b/board/flagadm/flash.c
index fc5d963a91f..fd0082c135b 100644
--- a/board/flagadm/flash.c
+++ b/board/flagadm/flash.c
@@ -77,7 +77,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/gen860t/flash.c b/board/gen860t/flash.c
index 902b1b0afe6..ec32d07dbf2 100644
--- a/board/gen860t/flash.c
+++ b/board/gen860t/flash.c
@@ -157,7 +157,7 @@ flash_init (void)
 	 */
 	flash_protect(FLAG_PROTECT_SET,
 		      	  CFG_MONITOR_BASE,
-		      	  CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+		      	  CFG_MONITOR_BASE + monitor_flash_len - 1,
 		      	  &flash_info[0]);
 #endif
 
diff --git a/board/genietv/flash.c b/board/genietv/flash.c
index 2314a53e736..f12d0be5525 100644
--- a/board/genietv/flash.c
+++ b/board/genietv/flash.c
@@ -55,7 +55,7 @@ unsigned long flash_init (void)
 	/* Monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/gth/flash.c b/board/gth/flash.c
index 562a3499246..c8b56fb96b2 100644
--- a/board/gth/flash.c
+++ b/board/gth/flash.c
@@ -102,7 +102,7 @@ unsigned long flash_init (void)
 	  /* monitor protection ON by default */
 	  (void)flash_protect(FLAG_PROTECT_SET,
 			    CFG_MONITOR_BASE,
-			    CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			    CFG_MONITOR_BASE+monitor_flash_len-1,
 			    &flash_info[0]);
 #endif
 
@@ -121,7 +121,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		(void)flash_protect(FLAG_PROTECT_SET,
 				    CFG_MONITOR_BASE,
-				    CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+				    CFG_MONITOR_BASE+monitor_flash_len-1,
 				    &flash_info[1]);
 #endif
 	}
diff --git a/board/gw8260/flash.c b/board/gw8260/flash.c
index 532dd194d7b..5620a1d8b7d 100644
--- a/board/gw8260/flash.c
+++ b/board/gw8260/flash.c
@@ -96,7 +96,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_MONITOR_BASE,
-		  CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		  CFG_MONITOR_BASE+monitor_flash_len-1,
 		  &flash_info[0]);
 #endif
 
diff --git a/board/hermes/flash.c b/board/hermes/flash.c
index bb7635ecfe9..799fe83f3e6 100644
--- a/board/hermes/flash.c
+++ b/board/hermes/flash.c
@@ -71,7 +71,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/hymod/flash.c b/board/hymod/flash.c
index ee052e39593..0a09b4a70e5 100644
--- a/board/hymod/flash.c
+++ b/board/hymod/flash.c
@@ -321,7 +321,7 @@ flash_init(void)
 #if CFG_MONITOR_BASE == CFG_FLASH_BASE
 	(void)flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/icu862/flash.c b/board/icu862/flash.c
index 79e7cc28aec..6315bd95b11 100644
--- a/board/icu862/flash.c
+++ b/board/icu862/flash.c
@@ -104,7 +104,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/impa7/flash.c b/board/impa7/flash.c
index c59ffb86584..7db0b3289dc 100644
--- a/board/impa7/flash.c
+++ b/board/impa7/flash.c
@@ -72,7 +72,7 @@ ulong flash_init(void)
      */
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_FLASH_BASE,
-		  CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+		  CFG_FLASH_BASE + monitor_flash_len - 1,
 		  &flash_info[0]);
 
     flash_protect(FLAG_PROTECT_SET,
diff --git a/board/incaip/flash.c b/board/incaip/flash.c
index 427f14a6168..e7fd54063b4 100644
--- a/board/incaip/flash.c
+++ b/board/incaip/flash.c
@@ -100,7 +100,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      flash_get_info(CFG_MONITOR_BASE));
 #endif
 
diff --git a/board/ip860/flash.c b/board/ip860/flash.c
index 4b0ea9bb019..2cf23b3e8c5 100644
--- a/board/ip860/flash.c
+++ b/board/ip860/flash.c
@@ -90,7 +90,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/iphase4539/flash.c b/board/iphase4539/flash.c
index 401ffbe415f..4eca46720cc 100644
--- a/board/iphase4539/flash.c
+++ b/board/iphase4539/flash.c
@@ -71,7 +71,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+			      CFG_MONITOR_BASE + monitor_flash_len - 1,
 			      flash_info + bank);
 #endif
 
diff --git a/board/ivm/flash.c b/board/ivm/flash.c
index b5453dff1e4..140ba2d530f 100644
--- a/board/ivm/flash.c
+++ b/board/ivm/flash.c
@@ -87,7 +87,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/kup4k/flash.c b/board/kup4k/flash.c
index 38374576871..7297c159e0e 100644
--- a/board/kup4k/flash.c
+++ b/board/kup4k/flash.c
@@ -74,7 +74,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/lantec/flash.c b/board/lantec/flash.c
index df585103334..0faa82cba4d 100644
--- a/board/lantec/flash.c
+++ b/board/lantec/flash.c
@@ -134,7 +134,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -166,7 +166,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/lart/flash.c b/board/lart/flash.c
index 7b195241393..89ab62c5365 100644
--- a/board/lart/flash.c
+++ b/board/lart/flash.c
@@ -105,7 +105,7 @@ ulong flash_init(void)
      */
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_FLASH_BASE,
-		  CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+		  CFG_FLASH_BASE + monitor_flash_len - 1,
 		  &flash_info[0]);
 
     flash_protect(FLAG_PROTECT_SET,
diff --git a/board/lubbock/flash.c b/board/lubbock/flash.c
index dcf829b2c55..9e07b1140d4 100644
--- a/board/lubbock/flash.c
+++ b/board/lubbock/flash.c
@@ -86,7 +86,7 @@ unsigned long flash_init (void)
 	 */
 	flash_protect ( FLAG_PROTECT_SET,
 			CFG_FLASH_BASE,
-			CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+			CFG_FLASH_BASE + monitor_flash_len - 1,
 			&flash_info[0] );
 
 	flash_protect ( FLAG_PROTECT_SET,
diff --git a/board/lwmon/flash.c b/board/lwmon/flash.c
index 3d2a00fd3e0..127738a4bb5 100644
--- a/board/lwmon/flash.c
+++ b/board/lwmon/flash.c
@@ -123,7 +123,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -156,7 +156,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/mbx8xx/flash.c b/board/mbx8xx/flash.c
index e1aa47bbaa9..a491f7bf0b7 100644
--- a/board/mbx8xx/flash.c
+++ b/board/mbx8xx/flash.c
@@ -79,7 +79,7 @@ unsigned long flash_init (void)
     /* monitor protection ON by default */
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_MONITOR_BASE,
-		  CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		  CFG_MONITOR_BASE+monitor_flash_len-1,
 		  &flash_info[0]);
 #endif
 
diff --git a/board/mpc8260ads/flash.c b/board/mpc8260ads/flash.c
index ec6a3b3fedf..d61bfc6462f 100644
--- a/board/mpc8260ads/flash.c
+++ b/board/mpc8260ads/flash.c
@@ -100,7 +100,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/mpc8266ads/flash.c b/board/mpc8266ads/flash.c
index b876d1cddd1..9512c72a0b9 100644
--- a/board/mpc8266ads/flash.c
+++ b/board/mpc8266ads/flash.c
@@ -101,7 +101,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/mpl/common/flash.c b/board/mpl/common/flash.c
index 483d0fff34a..563039b9cd0 100644
--- a/board/mpl/common/flash.c
+++ b/board/mpl/common/flash.c
@@ -102,7 +102,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
 	flash_protect(FLAG_PROTECT_SET,
 			CFG_MONITOR_BASE,
-			CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			CFG_MONITOR_BASE+monitor_flash_len-1,
 			&flash_info[0]);
 #endif
 	size_b1 = 0 ;
diff --git a/board/mpl/vcma9/flash.c b/board/mpl/vcma9/flash.c
index c2075da2a54..b442c9d2874 100644
--- a/board/mpl/vcma9/flash.c
+++ b/board/mpl/vcma9/flash.c
@@ -113,7 +113,7 @@ ulong flash_init(void)
 
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_FLASH_BASE,
-		  CFG_FLASH_BASE + _armboot_end - _armboot_start,
+		  CFG_FLASH_BASE + monitor_flash_len - 1,
 		  &flash_info[0]);
 
     flash_protect(FLAG_PROTECT_SET,
diff --git a/board/musenki/flash.c b/board/musenki/flash.c
index a0a038f753a..1e8bfff8c65 100644
--- a/board/musenki/flash.c
+++ b/board/musenki/flash.c
@@ -146,11 +146,11 @@ unsigned long flash_init (void)
 	flash_info[0].size = size_b0;
 
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
-	DEBUGF("protect monitor %x @ %x\n", CFG_MONITOR_BASE, CFG_MONITOR_LEN);
+	DEBUGF("protect monitor %x @ %x\n", CFG_MONITOR_BASE, monitor_flash_len);
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -171,7 +171,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/mvs1/flash.c b/board/mvs1/flash.c
index 75d9048bac0..08459435874 100644
--- a/board/mvs1/flash.c
+++ b/board/mvs1/flash.c
@@ -115,7 +115,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_FLASH_BASE,
-		      CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
+		      CFG_FLASH_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 
 	if (size_b1) {
@@ -136,7 +136,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_FLASH_BASE,
-			      CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
+			      CFG_FLASH_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 	} else {
 		memctl->memc_br1 = 0;		/* invalidate bank */
diff --git a/board/netvia/flash.c b/board/netvia/flash.c
index 4204c341933..669031f7358 100644
--- a/board/netvia/flash.c
+++ b/board/netvia/flash.c
@@ -66,7 +66,7 @@ unsigned long flash_init(void)
 	flash_get_offsets(CFG_FLASH_BASE, &flash_info[0]);
 
 	/* monitor protection ON by default */
-	flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + CFG_MONITOR_LEN - 1, &flash_info[0]);
+	flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + monitor_flash_len - 1, &flash_info[0]);
 
 	flash_info[0].size = size;
 
diff --git a/board/nx823/flash.c b/board/nx823/flash.c
index 616a13f2c6f..05ec687929f 100644
--- a/board/nx823/flash.c
+++ b/board/nx823/flash.c
@@ -93,7 +93,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	(void)flash_protect(FLAG_PROTECT_SET,
 			    CFG_FLASH_BASE,
-			    CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
+			    CFG_FLASH_BASE+monitor_flash_len-1,
 			    &flash_info[0]);
 
 	flash_info[0].size = size_b0;
diff --git a/board/oxc/flash.c b/board/oxc/flash.c
index 4f0220eab6b..795b7ccff9a 100644
--- a/board/oxc/flash.c
+++ b/board/oxc/flash.c
@@ -69,7 +69,7 @@ unsigned long flash_init (void)
     /* monitor protection ON by default */
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_MONITOR_BASE,
-		  CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		  CFG_MONITOR_BASE+monitor_flash_len-1,
 		  &flash_info[0]);
 #endif
 
diff --git a/board/pcippc2/flash.c b/board/pcippc2/flash.c
index 20f4d0343b8..6e9e3395c1b 100644
--- a/board/pcippc2/flash.c
+++ b/board/pcippc2/flash.c
@@ -70,7 +70,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+			      CFG_MONITOR_BASE + monitor_flash_len - 1,
 			      &flash_info[0]);
 #endif
 
diff --git a/board/pm826/flash.c b/board/pm826/flash.c
index 4d5147bf78c..770a46db737 100644
--- a/board/pm826/flash.c
+++ b/board/pm826/flash.c
@@ -133,7 +133,7 @@ unsigned long flash_init (void)
 # if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
 	flash_protect (FLAG_PROTECT_SET,
 		       CFG_MONITOR_BASE,
-		       CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[0]
+		       CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]
 	);
 # endif
 #endif	/* CONFIG_BOOT_ROM */
diff --git a/board/ppmc8260/strataflash.c b/board/ppmc8260/strataflash.c
index bb2184895bd..6d5a853829a 100644
--- a/board/ppmc8260/strataflash.c
+++ b/board/ppmc8260/strataflash.c
@@ -201,7 +201,7 @@ unsigned long flash_init (void)
 
 	/* Monitor protection ON by default */
 #if (CFG_MONITOR_BASE >= CFG_FLASH_BASE)
-	for(i=0; flash_info[0].start[i] < CFG_MONITOR_BASE+CFG_MONITOR_LEN-1; i++)
+	for(i=0; flash_info[0].start[i] < CFG_MONITOR_BASE+monitor_flash_len-1; i++)
 		(void)flash_real_protect(&flash_info[0], i, 1);
 #endif
 
diff --git a/board/purple/flash.c b/board/purple/flash.c
index 56d3acd160e..34f1b91c400 100644
--- a/board/purple/flash.c
+++ b/board/purple/flash.c
@@ -233,7 +233,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      flash_get_info(CFG_MONITOR_BASE));
 #endif
 
diff --git a/board/purple/purple.c b/board/purple/purple.c
index dfd014b53b5..b1eb78f0e60 100644
--- a/board/purple/purple.c
+++ b/board/purple/purple.c
@@ -232,6 +232,7 @@ static void programLoad(void)
 */
 void copy_code (ulong dest_addr)
 {
+	extern long uboot_end_data;
 	unsigned long start;
 	unsigned long end;
 
@@ -243,7 +244,7 @@ void copy_code (ulong dest_addr)
 	 */
 	copyLongs((ulong *)CFG_MONITOR_BASE,
 		  (ulong *)dest_addr,
-		  (CFG_MONITOR_LEN + 3) / 4);
+		  ((ulong)&uboot_end_data - CFG_MONITOR_BASE + 3) / 4);
 
 
 	/* flush caches
diff --git a/board/r360mpi/flash.c b/board/r360mpi/flash.c
index fef483c3f82..9b42960c7d3 100644
--- a/board/r360mpi/flash.c
+++ b/board/r360mpi/flash.c
@@ -107,7 +107,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	(void) flash_protect (FLAG_PROTECT_SET,
 				CFG_FLASH_BASE,
-				CFG_FLASH_BASE + CFG_MONITOR_LEN - 1,
+				CFG_FLASH_BASE + monitor_flash_len - 1,
 				&flash_info[0]);
 #endif
 
diff --git a/board/rpxsuper/flash.c b/board/rpxsuper/flash.c
index 0c298ba858f..73281bd4e20 100644
--- a/board/rpxsuper/flash.c
+++ b/board/rpxsuper/flash.c
@@ -67,7 +67,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_MONITOR_BASE,
-		  CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		  CFG_MONITOR_BASE+monitor_flash_len-1,
 		  &flash_info[0]);
 #endif
 
diff --git a/board/rsdproto/flash.c b/board/rsdproto/flash.c
index 654012f607c..d90e7db5473 100644
--- a/board/rsdproto/flash.c
+++ b/board/rsdproto/flash.c
@@ -123,11 +123,11 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= PHYS_FLASH
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[1]);
 #endif
 
diff --git a/board/sacsng/flash.c b/board/sacsng/flash.c
index 4fd04dfc067..52e01def5b1 100644
--- a/board/sacsng/flash.c
+++ b/board/sacsng/flash.c
@@ -69,7 +69,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -86,7 +86,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/sandpoint/flash.c b/board/sandpoint/flash.c
index 572199dd0af..4b6f2d06786 100644
--- a/board/sandpoint/flash.c
+++ b/board/sandpoint/flash.c
@@ -228,7 +228,7 @@ flash_init(void)
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
     flash_protect(FLAG_PROTECT_SET,
 		CFG_MONITOR_BASE,
-		CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
+		CFG_MONITOR_BASE + monitor_flash_len - 1,
 		&flash_info[0]);
 #endif
 
diff --git a/board/sbc8260/flash.c b/board/sbc8260/flash.c
index ab2bf354c3a..9a8b95225f9 100644
--- a/board/sbc8260/flash.c
+++ b/board/sbc8260/flash.c
@@ -63,7 +63,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_MONITOR_BASE,
-		  CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		  CFG_MONITOR_BASE+monitor_flash_len-1,
 		  &flash_info[0]);
 #endif
 
diff --git a/board/shannon/flash.c b/board/shannon/flash.c
index 8e0f7521939..c340fea52ca 100644
--- a/board/shannon/flash.c
+++ b/board/shannon/flash.c
@@ -124,7 +124,7 @@ ulong flash_init(void)
 #else
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_FLASH_BASE,
-		  CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+		  CFG_FLASH_BASE + monitor_flash_len - 1,
 		  &flash_info[0]);
 
     flash_protect(FLAG_PROTECT_SET,
diff --git a/board/siemens/CCM/flash.c b/board/siemens/CCM/flash.c
index e56114f80cc..9c32785b482 100644
--- a/board/siemens/CCM/flash.c
+++ b/board/siemens/CCM/flash.c
@@ -87,7 +87,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -106,7 +106,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 	} else {
diff --git a/board/siemens/SCM/flash.c b/board/siemens/SCM/flash.c
index dd7a4cc838e..056fe810b38 100644
--- a/board/siemens/SCM/flash.c
+++ b/board/siemens/SCM/flash.c
@@ -204,7 +204,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
 	flash_protect (FLAG_PROTECT_SET,
 		       CFG_MONITOR_BASE,
-		       CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[0]);
+		       CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);
 #endif
 
 #if (CFG_ENV_IS_IN_FLASH == 1) && defined(CFG_ENV_ADDR)
diff --git a/board/siemens/pcu_e/flash.c b/board/siemens/pcu_e/flash.c
index b8c0df77432..05c364bb23f 100644
--- a/board/siemens/pcu_e/flash.c
+++ b/board/siemens/pcu_e/flash.c
@@ -148,7 +148,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      PCU_MONITOR_BASE,
-		      PCU_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      PCU_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 
 #ifdef	CFG_ENV_IS_IN_FLASH
diff --git a/board/sixnet/flash.c b/board/sixnet/flash.c
index c201875ba0e..3bf2ff85db4 100644
--- a/board/sixnet/flash.c
+++ b/board/sixnet/flash.c
@@ -100,7 +100,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/smdk2400/flash.c b/board/smdk2400/flash.c
index 6882b884513..eb9eaa0deb0 100644
--- a/board/smdk2400/flash.c
+++ b/board/smdk2400/flash.c
@@ -93,7 +93,7 @@ ulong flash_init (void)
 	 */
 	flash_protect ( FLAG_PROTECT_SET,
 			CFG_FLASH_BASE,
-			CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+			CFG_FLASH_BASE + monitor_flash_len - 1,
 			&flash_info[0]);
 
 	flash_protect ( FLAG_PROTECT_SET,
diff --git a/board/smdk2410/flash.c b/board/smdk2410/flash.c
index c2ec2354b6d..5d04ed43d74 100644
--- a/board/smdk2410/flash.c
+++ b/board/smdk2410/flash.c
@@ -113,7 +113,7 @@ ulong flash_init(void)
 
     flash_protect(FLAG_PROTECT_SET,
 		  CFG_FLASH_BASE,
-		  CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+		  CFG_FLASH_BASE + monitor_flash_len - 1,
 		  &flash_info[0]);
 
     flash_protect(FLAG_PROTECT_SET,
diff --git a/board/svm_sc8xx/flash.c b/board/svm_sc8xx/flash.c
index 8c0e229130a..b50f77b6317 100644
--- a/board/svm_sc8xx/flash.c
+++ b/board/svm_sc8xx/flash.c
@@ -149,7 +149,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -176,7 +176,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/tqm8260/flash.c b/board/tqm8260/flash.c
index dd7a4cc838e..056fe810b38 100644
--- a/board/tqm8260/flash.c
+++ b/board/tqm8260/flash.c
@@ -204,7 +204,7 @@ unsigned long flash_init (void)
 #if CFG_MONITOR_BASE >= CFG_FLASH0_BASE
 	flash_protect (FLAG_PROTECT_SET,
 		       CFG_MONITOR_BASE,
-		       CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[0]);
+		       CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);
 #endif
 
 #if (CFG_ENV_IS_IN_FLASH == 1) && defined(CFG_ENV_ADDR)
diff --git a/board/tqm8xx/flash.c b/board/tqm8xx/flash.c
index 2f74ccccf24..6b4ea7d2273 100644
--- a/board/tqm8xx/flash.c
+++ b/board/tqm8xx/flash.c
@@ -88,7 +88,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -113,7 +113,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 #endif
 
diff --git a/board/trab/flash.c b/board/trab/flash.c
index 1550e175a4f..a2a21c6d25e 100644
--- a/board/trab/flash.c
+++ b/board/trab/flash.c
@@ -99,7 +99,7 @@ ulong flash_init (void)
 	 */
 	flash_protect ( FLAG_PROTECT_SET,
 			CFG_FLASH_BASE,
-			CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+			CFG_FLASH_BASE + monitor_flash_len - 1,
 			&flash_info[0]);
 
 	flash_protect ( FLAG_PROTECT_SET,
diff --git a/board/utx8245/flash.c b/board/utx8245/flash.c
index 947fbc3aa5e..73bb04d98ee 100644
--- a/board/utx8245/flash.c
+++ b/board/utx8245/flash.c
@@ -145,7 +145,7 @@ unsigned long flash_init(void)
      */
 #if CFG_MONITOR_BASE >= CFG_FLASH_BASE
      flash_protect(FLAG_PROTECT_SET, CFG_MONITOR_BASE,
-              CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1, &flash_info[0]);
+              CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);
 #endif
 
 #if (CFG_ENV_IS_IN_FLASH == 1) && defined(CFG_ENV_ADDR)
diff --git a/board/v37/flash.c b/board/v37/flash.c
index cb0e676a138..b42f3350100 100644
--- a/board/v37/flash.c
+++ b/board/v37/flash.c
@@ -79,7 +79,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
diff --git a/board/w7o/flash.c b/board/w7o/flash.c
index 00484762361..5651e1cfdd7 100644
--- a/board/w7o/flash.c
+++ b/board/w7o/flash.c
@@ -83,7 +83,7 @@ unsigned long flash_init (void)
 
     /* Monitor protection ON by default */
     (void)flash_protect(FLAG_PROTECT_SET,
-                        base_b0 + size_b0 - CFG_MONITOR_LEN,
+                        base_b0 + size_b0 - monitor_flash_len,
                         base_b0 + size_b0 - 1,
                         &flash_info[0]);
 
diff --git a/board/walnut405/flash.c b/board/walnut405/flash.c
index 81f950ba8cb..c9c7cbfdc2d 100644
--- a/board/walnut405/flash.c
+++ b/board/walnut405/flash.c
@@ -92,7 +92,7 @@ unsigned long flash_init (void)
 	    /* Monitor protection ON by default */
 	    (void)flash_protect(FLAG_PROTECT_SET,
 				FLASH_BASE0_PRELIM,
-				FLASH_BASE0_PRELIM+CFG_MONITOR_LEN-1,
+				FLASH_BASE0_PRELIM+monitor_flash_len-1,
 				&flash_info[0]);
 	    size_b1 = 0 ;
 	    flash_info[0].size = size_b0;
@@ -133,7 +133,7 @@ unsigned long flash_init (void)
 
 	    /* monitor protection ON by default */
 	    (void)flash_protect(FLAG_PROTECT_SET,
-				base_b0+size_b0-CFG_MONITOR_LEN,
+				base_b0+size_b0-monitor_flash_len,
 				base_b0+size_b0-1,
 				&flash_info[0]);
 
@@ -145,12 +145,12 @@ unsigned long flash_init (void)
 
 	      /* monitor protection ON by default */
 	      (void)flash_protect(FLAG_PROTECT_SET,
-				  base_b1+size_b1-CFG_MONITOR_LEN,
+				  base_b1+size_b1-monitor_flash_len,
 				  base_b1+size_b1-1,
 				  &flash_info[1]);
 	      /* monitor protection OFF by default (one is enough) */
 	      (void)flash_protect(FLAG_PROTECT_CLEAR,
-				  base_b0+size_b0-CFG_MONITOR_LEN,
+				  base_b0+size_b0-monitor_flash_len,
 				  base_b0+size_b0-1,
 				  &flash_info[0]);
 	    } else {
diff --git a/board/wepep250/flash.c b/board/wepep250/flash.c
index 319dddc4b26..5c9d346da03 100644
--- a/board/wepep250/flash.c
+++ b/board/wepep250/flash.c
@@ -135,7 +135,7 @@ ulong flash_init (void)
 
 	flash_protect (FLAG_PROTECT_SET,
 				   CFG_FLASH_BASE,
-				   CFG_FLASH_BASE + _armboot_end_data - _armboot_start,
+				   CFG_FLASH_BASE + monitor_flash_len - 1,
 				   &flash_info[0]);
 
 	flash_protect (FLAG_PROTECT_SET,
diff --git a/board/westel/amx860/flash.c b/board/westel/amx860/flash.c
index 28238c1ca00..12a1335b757 100644
--- a/board/westel/amx860/flash.c
+++ b/board/westel/amx860/flash.c
@@ -130,7 +130,7 @@ unsigned long flash_init (void)
 	/* monitor protection ON by default */
 	flash_protect(FLAG_PROTECT_SET,
 		      CFG_MONITOR_BASE,
-		      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+		      CFG_MONITOR_BASE+monitor_flash_len-1,
 		      &flash_info[0]);
 #endif
 
@@ -162,7 +162,7 @@ unsigned long flash_init (void)
 		/* monitor protection ON by default */
 		flash_protect(FLAG_PROTECT_SET,
 			      CFG_MONITOR_BASE,
-			      CFG_MONITOR_BASE+CFG_MONITOR_LEN-1,
+			      CFG_MONITOR_BASE+monitor_flash_len-1,
 			      &flash_info[1]);
 # endif
 
diff --git a/cpu/74xx_7xx/start.S b/cpu/74xx_7xx/start.S
index 96559c2e318..4a0e7a11191 100644
--- a/cpu/74xx_7xx/start.S
+++ b/cpu/74xx_7xx/start.S
@@ -68,6 +68,7 @@
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
 
+	GOT_ENTRY(__init_end)
 	GOT_ENTRY(_end)
 	GOT_ENTRY(__bss_start)
 	END_GOT
@@ -590,8 +591,8 @@ relocate_code:
 	mr	r3,  r5				/* Destination Address	*/
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 	li	r6, CFG_CACHELINE_SIZE		/* Cache Line Size	*/
 
 	/*
@@ -617,8 +618,8 @@ relocate_code:
 	mr	r3, r10				/* Destination Address	*/
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 	li	r6, CFG_CACHELINE_SIZE		/* Cache Line Size	*/
 #else
 	cmplw	cr1,r3,r4
@@ -738,12 +739,6 @@ in_ram:
 	/* not reached - end relocate_code */
 /*-----------------------------------------------------------------------*/
 
-	/* Problems accessing "end" in C, so do it here */
-	.globl	get_endaddr
-get_endaddr:
-	lwz	r3,GOT(_end)
-	blr
-
 	/*
 	 * Copy exception vector code to low memory
 	 *
diff --git a/cpu/mips/start.S b/cpu/mips/start.S
index 86a8407f61a..b5043937293 100644
--- a/cpu/mips/start.S
+++ b/cpu/mips/start.S
@@ -302,7 +302,8 @@ relocate_code:
 	sub	t6, gp, t6		/* t6 <-- relocation offset	*/
 	
 	li	t0, CFG_MONITOR_BASE
-	add	t2, t0, CFG_MONITOR_LEN
+	la	t3, in_ram
+	lw	t2, -12(t3)	/* t2 <-- uboot_end_data	*/
 	move	t1, a2
 
 	/*
diff --git a/cpu/mpc5xx/start.S b/cpu/mpc5xx/start.S
index d8a8bec1e55..4d7c71644f0 100644
--- a/cpu/mpc5xx/start.S
+++ b/cpu/mpc5xx/start.S
@@ -66,6 +66,7 @@
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
 
+	GOT_ENTRY(__init_end)
 	GOT_ENTRY(_end)
 	GOT_ENTRY(__bss_start)
 	END_GOT
@@ -432,8 +433,8 @@ relocate_code:
 	mr	r3,  r5				/* Destination Address	*/
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 
 	/*
 	 * Fix GOT pointer:
@@ -544,12 +545,6 @@ clear_bss:
 	mr	r4, r10		/* Destination Address		*/
 	bl	board_init_r
 
-	/* Problems accessing "end" in C, so do it here */
-	.globl	get_endaddr
-get_endaddr:
-	lwz	r3,GOT(_end)
-	blr
-
 	/*
 	 * Copy exception vector code to low memory
 	 *
diff --git a/cpu/mpc824x/start.S b/cpu/mpc824x/start.S
index 855b81f7bb2..d45bb364805 100644
--- a/cpu/mpc824x/start.S
+++ b/cpu/mpc824x/start.S
@@ -73,6 +73,7 @@
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
 
+	GOT_ENTRY(__init_end)
 	GOT_ENTRY(_end)
 	GOT_ENTRY(__bss_start)
 #if defined(CONFIG_FADS)
@@ -549,8 +550,8 @@ relocate_code:
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
 #endif
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 	li	r6, CFG_CACHELINE_SIZE		/* Cache Line Size	*/
 
 	/*
@@ -683,12 +684,6 @@ clear_bss:
 	mr	r4, r10		/* Destination Address		*/
 	bl	board_init_r
 
-	/* Problems accessing "end" in C, so do it here */
-	.globl	get_endaddr
-get_endaddr:
-	lwz	r3,GOT(_end)
-	blr
-
 	/*
 	 * Copy exception vector code to low memory
 	 *
diff --git a/cpu/mpc8260/start.S b/cpu/mpc8260/start.S
index 9ceb7049555..a5b8b5f0f08 100644
--- a/cpu/mpc8260/start.S
+++ b/cpu/mpc8260/start.S
@@ -66,6 +66,7 @@
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
 
+	GOT_ENTRY(__init_end)
 	GOT_ENTRY(_end)
 	GOT_ENTRY(__bss_start)
 #if defined(CONFIG_HYMOD)
@@ -863,8 +864,8 @@ relocate_code:
 	mr	r3,  r5				/* Destination Address	*/
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 	li	r6, CFG_CACHELINE_SIZE		/* Cache Line Size	*/
 
 	/*
@@ -1016,12 +1017,6 @@ clear_bss:
 	mr	r4, r10		/* Destination Address		*/
 	bl	board_init_r
 
-	/* Problems accessing "end" in C, so do it here */
-	.globl	get_endaddr
-get_endaddr:
-	lwz	r3,GOT(_end)
-	blr
-
 	/*
 	 * Copy exception vector code to low memory
 	 *
diff --git a/cpu/mpc8xx/start.S b/cpu/mpc8xx/start.S
index 3cd0d9ae748..c5dc5a973af 100644
--- a/cpu/mpc8xx/start.S
+++ b/cpu/mpc8xx/start.S
@@ -73,6 +73,7 @@
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
 
+	GOT_ENTRY(__init_end)
 	GOT_ENTRY(_end)
 	GOT_ENTRY(__bss_start)
 #if defined(CONFIG_FADS) || defined(CONFIG_ICU862)
@@ -568,8 +569,8 @@ relocate_code:
 	mr	r3,  r5				/* Destination Address	*/
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 	li	r6, CFG_CACHELINE_SIZE		/* Cache Line Size	*/
 
 	/*
@@ -711,12 +712,6 @@ clear_bss:
 	mr	r4, r10		/* Destination Address		*/
 	bl	board_init_r
 
-	/* Problems accessing "end" in C, so do it here */
-	.globl	get_endaddr
-get_endaddr:
-	lwz	r3,GOT(_end)
-	blr
-
 	/*
 	 * Copy exception vector code to low memory
 	 *
diff --git a/cpu/ppc4xx/start.S b/cpu/ppc4xx/start.S
index afe8635585c..cc29548eba7 100644
--- a/cpu/ppc4xx/start.S
+++ b/cpu/ppc4xx/start.S
@@ -132,6 +132,7 @@
 	GOT_ENTRY(_end_of_vectors)
 	GOT_ENTRY(transfer_to_handler)
 
+	GOT_ENTRY(__init_end)
 	GOT_ENTRY(_end)
 	GOT_ENTRY(__bss_start)
 	END_GOT
@@ -1235,8 +1236,8 @@ relocate_code:
 	mr	r3,  r5				/* Destination Address	*/
 	lis	r4, CFG_MONITOR_BASE@h		/* Source      Address	*/
 	ori	r4, r4, CFG_MONITOR_BASE@l
-	lis	r5, CFG_MONITOR_LEN@h		/* Length in Bytes	*/
-	ori	r5, r5, CFG_MONITOR_LEN@l
+	lwz	r5, GOT(__init_end)
+	sub	r5, r5, r4
 	li	r6, CFG_CACHELINE_SIZE		/* Cache Line Size	*/
 
 	/*
@@ -1369,12 +1370,6 @@ clear_bss:
 	mr	r4, r10		/* Destination Address		*/
 	bl	board_init_r
 
-	/* Problems accessing "end" in C, so do it here */
-	.globl	get_endaddr
-get_endaddr:
-	lwz	r3,GOT(_end)
-	blr
-
 	/*
 	 * Copy exception vector code to low memory
 	 *
diff --git a/include/common.h b/include/common.h
index 2ff1c8c35a8..0a252c53fc3 100644
--- a/include/common.h
+++ b/include/common.h
@@ -128,6 +128,7 @@ int	checkflash    (void);
 int	checkdram     (void);
 char *	strmhz(char *buf, long hz);
 int	last_stage_init(void);
+extern ulong monitor_flash_len;
 
 /* common/flash.c */
 void flash_perror (int);
diff --git a/include/configs/ETX094.h b/include/configs/ETX094.h
index 9d7c8689c81..b6e19419dfd 100644
--- a/include/configs/ETX094.h
+++ b/include/configs/ETX094.h
@@ -262,7 +262,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/FPS850L.h b/include/configs/FPS850L.h
index d04616dc995..89a4d437b4d 100644
--- a/include/configs/FPS850L.h
+++ b/include/configs/FPS850L.h
@@ -242,7 +242,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/FPS860L.h b/include/configs/FPS860L.h
index d2ac9d22058..14546f0a2db 100644
--- a/include/configs/FPS860L.h
+++ b/include/configs/FPS860L.h
@@ -243,7 +243,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/IP860.h b/include/configs/IP860.h
index d7dce71e314..fddf0ca3d50 100644
--- a/include/configs/IP860.h
+++ b/include/configs/IP860.h
@@ -304,7 +304,6 @@ extern  unsigned long           ip860_get_clk_freq (void);
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/IVML24.h b/include/configs/IVML24.h
index 85900b5e0f0..77746e87f47 100644
--- a/include/configs/IVML24.h
+++ b/include/configs/IVML24.h
@@ -327,7 +327,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/IVMS8.h b/include/configs/IVMS8.h
index 2725e77c83a..19063fa4dca 100644
--- a/include/configs/IVMS8.h
+++ b/include/configs/IVMS8.h
@@ -322,7 +322,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/KUP4K.h b/include/configs/KUP4K.h
index d02ec0d6376..f68f1e10db2 100644
--- a/include/configs/KUP4K.h
+++ b/include/configs/KUP4K.h
@@ -319,7 +319,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/LANTEC.h b/include/configs/LANTEC.h
index 7f4869fee10..81e20791138 100644
--- a/include/configs/LANTEC.h
+++ b/include/configs/LANTEC.h
@@ -276,7 +276,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/R360MPI.h b/include/configs/R360MPI.h
index 8aba25e06eb..8fa328e0cbe 100644
--- a/include/configs/R360MPI.h
+++ b/include/configs/R360MPI.h
@@ -332,8 +332,7 @@
  *-----------------------------------------------------------------------
  *
  */
-#define	CFG_DER	0x2002000F
-/*#define CFG_DER	0*/
+#define CFG_DER	0
 
 /*
  * Init Memory Controller:
diff --git a/include/configs/RRvision.h b/include/configs/RRvision.h
index acfe747ceca..a1327e75aac 100644
--- a/include/configs/RRvision.h
+++ b/include/configs/RRvision.h
@@ -345,7 +345,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/SM850.h b/include/configs/SM850.h
index 5dfa8f3b0c9..c23b3860a84 100644
--- a/include/configs/SM850.h
+++ b/include/configs/SM850.h
@@ -268,7 +268,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/SPD823TS.h b/include/configs/SPD823TS.h
index 9ad1839154b..51f2c253c21 100644
--- a/include/configs/SPD823TS.h
+++ b/include/configs/SPD823TS.h
@@ -307,7 +307,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER 0x2002000F*/
 #define CFG_DER 0
 
 /*
diff --git a/include/configs/TQM823L.h b/include/configs/TQM823L.h
index cc51ce66748..66e3c91f481 100644
--- a/include/configs/TQM823L.h
+++ b/include/configs/TQM823L.h
@@ -330,7 +330,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/TQM850L.h b/include/configs/TQM850L.h
index 60aacfb7626..07e6faa113a 100644
--- a/include/configs/TQM850L.h
+++ b/include/configs/TQM850L.h
@@ -322,7 +322,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/TQM855L.h b/include/configs/TQM855L.h
index 37363a25ff9..7f1f153c899 100644
--- a/include/configs/TQM855L.h
+++ b/include/configs/TQM855L.h
@@ -322,7 +322,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/TQM860L.h b/include/configs/TQM860L.h
index a9d1afffcd8..c386d3c325f 100644
--- a/include/configs/TQM860L.h
+++ b/include/configs/TQM860L.h
@@ -323,7 +323,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/TQM862L.h b/include/configs/TQM862L.h
index 608c4e16dd7..653d0c79aeb 100644
--- a/include/configs/TQM862L.h
+++ b/include/configs/TQM862L.h
@@ -325,7 +325,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/c2mon.h b/include/configs/c2mon.h
index b38150f4bca..a4859b54646 100644
--- a/include/configs/c2mon.h
+++ b/include/configs/c2mon.h
@@ -321,7 +321,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/hermes.h b/include/configs/hermes.h
index 2d275f331a3..1486377caa9 100644
--- a/include/configs/hermes.h
+++ b/include/configs/hermes.h
@@ -253,7 +253,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER	0x2002000F*/
 #define CFG_DER	0
 
 /*
diff --git a/include/configs/lwmon.h b/include/configs/lwmon.h
index 8ab650e24b3..2989d42a9ae 100644
--- a/include/configs/lwmon.h
+++ b/include/configs/lwmon.h
@@ -484,7 +484,6 @@
  *-----------------------------------------------------------------------
  *
  */
-/*#define	CFG_DER 0x2002000F*/
 #define CFG_DER 0
 
 /*
diff --git a/lib_arm/board.c b/lib_arm/board.c
index 54f554b6d4d..af6af14db76 100644
--- a/lib_arm/board.c
+++ b/lib_arm/board.c
@@ -35,6 +35,8 @@
 void nand_init (void);
 #endif
 
+ulong monitor_flash_len;
+
 const char version_string[] =
 	U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
 
@@ -204,6 +206,8 @@ void start_armboot (void)
 	gd->bd = &bd_data;
 	memset (gd->bd, 0, sizeof (bd_t));
 
+	monitor_flash_len = _armboot_end_data - _armboot_start;
+
 	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
 		if ((*init_fnc_ptr)() != 0) {
 			hang ();
diff --git a/lib_mips/board.c b/lib_mips/board.c
index 4bab3c5855c..2bbf029d2ee 100644
--- a/lib_mips/board.c
+++ b/lib_mips/board.c
@@ -42,6 +42,11 @@
 
 extern int timer_init(void);
 
+extern ulong uboot_end_data;
+extern ulong uboot_end;
+
+ulong monitor_flash_len;
+
 const char version_string[] =
 	U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
 
@@ -176,7 +181,7 @@ void board_init_f(ulong bootflag)
 	gd_t gd_data, *id;
 	bd_t *bd;
 	init_fnc_t **init_fnc_ptr;
-	ulong addr, addr_sp, len   = CFG_MONITOR_LEN;
+	ulong addr, addr_sp, len = (ulong)&uboot_end - CFG_MONITOR_BASE;
 #ifdef CONFIG_PURPLE
 	void copy_code (ulong);
 #endif
@@ -209,10 +214,10 @@ void board_init_f(ulong bootflag)
 #endif
 	 
 		/* Reserve memory for U-Boot code, data & bss
-		 * round down to next 4 kB limit
+		 * round down to next 16 kB limit
 		 */
 	addr -= len;
-	addr &= ~(4096 - 1);
+	addr &= ~(16 * 1024 - 1);
 
 #ifdef DEBUG
 	printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
@@ -319,6 +324,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 	gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
 
+	monitor_flash_len = (ulong)&uboot_end_data - dest_addr;
+
 	/*
 	 * We have to relocate the command table manually
 	 */
@@ -360,7 +367,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	bd->bi_flashstart = CFG_FLASH_BASE;
 	bd->bi_flashsize = size;
 #if CFG_MONITOR_BASE == CFG_FLASH_BASE
-	bd->bi_flashoffset = CFG_MONITOR_LEN;	/* reserved area for U-Boot */
+	bd->bi_flashoffset = monitor_flash_len;	/* reserved area for U-Boot */
 #else
 	bd->bi_flashoffset = 0;
 #endif
diff --git a/lib_ppc/board.c b/lib_ppc/board.c
index bba62d820d2..333d2d25c10 100644
--- a/lib_ppc/board.c
+++ b/lib_ppc/board.c
@@ -93,6 +93,11 @@ extern flash_info_t flash_info[];
 #define	TOTAL_MALLOC_LEN	CFG_MALLOC_LEN
 #endif
 
+extern ulong __init_end;
+extern ulong _end;
+
+ulong monitor_flash_len;
+
 /*
  * Begin and End of memory area for malloc(), and current "brk"
  */
@@ -383,16 +388,7 @@ void board_init_f (ulong bootflag)
 	 *  - monitor code
 	 *  - board info struct
 	 */
-	len = get_endaddr () - CFG_MONITOR_BASE;
-
-	if (len > CFG_MONITOR_LEN) {
-		printf ("*** U-Boot size %ld > reserved memory (%d)\n",
-				len, CFG_MONITOR_LEN);
-		hang ();
-	}
-
-	if (CFG_MONITOR_LEN > len)
-		len = CFG_MONITOR_LEN;
+	len = (ulong)&_end - CFG_MONITOR_BASE;
 
 #ifndef	CONFIG_VERY_BIG_RAM
 	addr = CFG_SDRAM_BASE + gd->ram_size;
@@ -442,10 +438,10 @@ void board_init_f (ulong bootflag)
 
 	/*
 	 * reserve memory for U-Boot code, data & bss
-	 * round down to next 4 kB limit
+	 * round down to next 16 kB limit
 	 */
 	addr -= len;
-	addr &= ~(4096 - 1);
+	addr &= ~(16 * 1024 - 1);
 
 #ifdef DEBUG
 	printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
@@ -600,6 +596,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	WATCHDOG_RESET ();
 
 	gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
+	
+	monitor_flash_len = (ulong)&__init_end - dest_addr;
 
 	/*
 	 * We have to relocate the command table manually
@@ -705,7 +703,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #if defined(CONFIG_PCU_E) || defined(CONFIG_OXC)
 	bd->bi_flashoffset = 0;
 #elif CFG_MONITOR_BASE == CFG_FLASH_BASE
-	bd->bi_flashoffset = CFG_MONITOR_LEN;	/* reserved area for startup monitor  */
+	bd->bi_flashoffset = monitor_flash_len;	/* reserved area for startup monitor  */
 #else
 	bd->bi_flashoffset = 0;
 #endif
-- 
GitLab