Merge commit '7b2fac7654f7420c2787f74ec3b1540fa3b343e9'
[oweals/u-boot.git] / arch / powerpc / lib / board.c
index 529f71960d7ce62dfbfbc897ebe86443d23f8fda..22bbc52da55066b0387d9dc09f6c5cf256ca69be 100644 (file)
@@ -123,7 +123,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif
 
 extern ulong __init_end;
-extern ulong _end;
+extern ulong __bss_end__;
 ulong monitor_flash_len;
 
 #if defined(CONFIG_CMD_BEDBUG)
@@ -175,6 +175,22 @@ void __board_add_ram_info(int use_default)
 }
 void board_add_ram_info(int) __attribute__((weak, alias("__board_add_ram_info")));
 
+int __board_flash_wp_on(void)
+{
+       /*
+        * Most flashes can't be detected when write protection is enabled,
+        * so provide a way to let U-Boot gracefully ignore write protected
+        * devices.
+        */
+       return 0;
+}
+int board_flash_wp_on(void) __attribute__((weak, alias("__board_flash_wp_on")));
+
+void __cpu_secondary_init_r(void)
+{
+}
+void cpu_secondary_init_r(void)
+__attribute__((weak, alias("__cpu_secondary_init_r")));
 
 static int init_func_ram (void)
 {
@@ -393,7 +409,7 @@ void board_init_f (ulong bootflag)
         *  - monitor code
         *  - board info struct
         */
-       len = (ulong)&_end - CONFIG_SYS_MONITOR_BASE;
+       len = (ulong)&__bss_end__ - CONFIG_SYS_MONITOR_BASE;
 
        /*
         * Subtract specified amount of memory to hide so that it won't
@@ -443,9 +459,13 @@ void board_init_f (ulong bootflag)
        debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
 
 #ifdef CONFIG_LCD
+#ifdef CONFIG_FB_ADDR
+       gd->fb_base = CONFIG_FB_ADDR;
+#else
        /* reserve memory for LCD display (always full pages) */
        addr = lcd_setmem (addr);
        gd->fb_base = addr;
+#endif /* CONFIG_FB_ADDR */
 #endif /* CONFIG_LCD */
 
 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
@@ -546,8 +566,6 @@ void board_init_f (ulong bootflag)
        }
 #endif
 
-       bd->bi_bootflags = bootflag;    /* boot / reboot flag (for LynxOS)    */
-
        WATCHDOG_RESET ();
        bd->bi_intfreq = gd->cpu_clk;   /* Internal Freq, in Hz */
        bd->bi_busfreq = gd->bus_clk;   /* Bus Freq,      in Hz */
@@ -637,6 +655,17 @@ void board_init_r (gd_t *id, ulong dest_addr)
        gd->cpu += dest_addr - CONFIG_SYS_MONITOR_BASE;
 #endif
 
+#ifdef CONFIG_SYS_EXTRA_ENV_RELOC
+       /*
+        * Some systems need to relocate the env_addr pointer early because the
+        * location it points to will get invalidated before env_relocate is
+        * called.  One example is on systems that might use a L2 or L3 cache
+        * in SRAM mode and initialize that cache from SRAM mode back to being
+        * a cache in cpu_init_r.
+        */
+       gd->env_addr += dest_addr - CONFIG_SYS_MONITOR_BASE;
+#endif
+
 #ifdef CONFIG_SERIAL_MULTI
        serial_initialize();
 #endif
@@ -686,7 +715,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
         */
        pci_init ();
 #endif
-#if defined(CONFIG_BAB7xx)
+#if defined(CONFIG_WINBOND_83C553)
        /*
         * Initialise the ISA bridge
         */
@@ -698,9 +727,13 @@ void board_init_r (gd_t *id, ulong dest_addr)
        mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
 
 #if !defined(CONFIG_SYS_NO_FLASH)
-       puts ("FLASH: ");
+       puts ("Flash: ");
 
-       if ((flash_size = flash_init ()) > 0) {
+       if (board_flash_wp_on()) {
+               printf("Uninitialized - Write Protect On\n");
+               /* Since WP is on, we can't find real size.  Set to 0 */
+               flash_size = 0;
+       } else if ((flash_size = flash_init ()) > 0) {
 # ifdef CONFIG_SYS_FLASH_CHECKSUM
                print_size (flash_size, "");
                /*
@@ -734,7 +767,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 # if defined(CONFIG_OXC) || defined(CONFIG_RMU)
        /* flash mapped at end of memory map */
-       bd->bi_flashoffset = TEXT_BASE + flash_size;
+       bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
 # elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
        bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor  */
 # endif
@@ -774,6 +807,14 @@ void board_init_r (gd_t *id, ulong dest_addr)
        /* relocate environment function pointers etc. */
        env_relocate ();
 
+       /*
+        * after non-volatile devices & environment is setup and cpu code have
+        * another round to deal with any initialization that might require
+        * full access to the environment or loading of some image (firmware)
+        * from a non-volatile device
+        */
+       cpu_secondary_init_r();
+
        /*
         * Fill in missing fields of bd_info.
         * We do this here, where we have "normal" access to the
@@ -891,8 +932,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
        udelay (20);
 
-       set_timer (0);
-
        /* Initialize from environment */
        if ((s = getenv ("loadaddr")) != NULL) {
                load_addr = simple_strtoul (s, NULL, 16);