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
 
 
        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
                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.
 
   /* 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
   
 
                /* 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
 
 
        /* 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
 
 
        /* 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
 
 
        /* 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
 
 
        /* 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
 
 
 #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
 
 
        /* 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
 
                /* 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
 
 
        /* 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
 
 
 #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
 
 
 #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
 
 
                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
 
     */
    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,
 
            /* 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 ;
 
        /* 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,
 
 #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
 
      */
     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,
 
     {
         (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]);
     }
 
 
     {
         (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]);
     }
 
 
        /* 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;
 
         */
        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,
 
 #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
 
 
            /* 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 ;
            /* 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
 
 
              /* 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 {
 
 
        /* 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]);
 
 
                /* 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 {
 
 
        /* 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]);
 
 
                /* 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 {
 
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
 
 
        /* 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) {
 
                /* 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;
 
 #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
 
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
 
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
 
 
        /* 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) {
 
                /* 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;
 
 
        /* 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) {
 
                /* 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;
 
 
         /* Monitor protection ON by default */
         (void)flash_protect(FLAG_PROTECT_SET,
-                            -CFG_MONITOR_LEN,
+                            -monitor_flash_len,
                             0xffffffff,
                             &flash_info[0]);
 
 
        /* 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
 
                /* 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 {
 
        /* 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
 
                /* 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 {
 
                /* 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
 
 
        /* 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
 
 
         */
        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
 
 
        /* 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
 
 
          /* 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
 
                /* 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
        }
 
 #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
 
 
        /* 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
 
 
 #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
 
 
        /* 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
 
 
      */
     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,
 
        /* 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
 
 
        /* 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
 
 
                /* 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
 
 
        /* 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
 
 
        /* 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
 
 
        /* 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
 
                /* 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
 
 
      */
     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,
 
         */
        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,
 
        /* 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
 
                /* 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
 
 
     /* 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
 
 
        /* 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
 
 
        /* 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
 
 
 #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 ;
 
 
     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,
 
        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
 
                /* 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
 
 
        /* 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) {
                /* 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 */
 
        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;
 
 
        /* 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;
 
     /* 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
 
 
                /* 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
 
 
 # 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 */
 
 
        /* 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
 
 
        /* 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
 
 
 */
 void copy_code (ulong dest_addr)
 {
+       extern long uboot_end_data;
        unsigned long start;
        unsigned long end;
 
         */
        copyLongs((ulong *)CFG_MONITOR_BASE,
                  (ulong *)dest_addr,
-                 (CFG_MONITOR_LEN + 3) / 4);
+                 ((ulong)&uboot_end_data - CFG_MONITOR_BASE + 3) / 4);
 
 
        /* flush caches
 
        /* 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
 
 
 #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
 
 
 #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
 
 
        /* 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
 
                /* 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
 
 
 #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
 
 
 #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
 
 
 #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,
 
        /* 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
 
                /* 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 {
 
 #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)
 
        /* 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
 
        /* 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
 
 
         */
        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,
 
 
     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,
 
        /* 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
 
                /* 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
 
 
 #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)
 
        /* 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
 
                /* 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
 
 
         */
        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,
 
      */
 #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)
 
        /* 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
 
 
 
     /* 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]);
 
 
            /* 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;
 
            /* 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]);
 
 
              /* 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 {
 
 
        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,
 
        /* 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
 
                /* 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
 
 
        GOT_ENTRY(_end_of_vectors)
        GOT_ENTRY(transfer_to_handler)
 
+       GOT_ENTRY(__init_end)
        GOT_ENTRY(_end)
        GOT_ENTRY(__bss_start)
        END_GOT
        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      */
 
        /*
        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
        /* 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
         *
 
        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
 
        /*
 
        GOT_ENTRY(_end_of_vectors)
        GOT_ENTRY(transfer_to_handler)
 
+       GOT_ENTRY(__init_end)
        GOT_ENTRY(_end)
        GOT_ENTRY(__bss_start)
        END_GOT
        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:
        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
         *
 
        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)
        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      */
 
        /*
        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
         *
 
        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)
        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      */
 
        /*
        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
         *
 
        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)
        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      */
 
        /*
        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
         *
 
        GOT_ENTRY(_end_of_vectors)
        GOT_ENTRY(transfer_to_handler)
 
+       GOT_ENTRY(__init_end)
        GOT_ENTRY(_end)
        GOT_ENTRY(__bss_start)
        END_GOT
        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      */
 
        /*
        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
         *
 
 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);
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-#define        CFG_DER 0x2002000F
-/*#define CFG_DER      0*/
+#define CFG_DER        0
 
 /*
  * Init Memory Controller:
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER 0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER        0
 
 /*
 
  *-----------------------------------------------------------------------
  *
  */
-/*#define      CFG_DER 0x2002000F*/
 #define CFG_DER 0
 
 /*
 
 void nand_init (void);
 #endif
 
+ulong monitor_flash_len;
+
 const char version_string[] =
        U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
 
        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 ();
 
 
 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__ ")";
 
        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
 #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);
 
        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
         */
        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
 
 #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"
  */
         *  - 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;
 
        /*
         * 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);
        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
 #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