Merge commit '7b2fac7654f7420c2787f74ec3b1540fa3b343e9'
[oweals/u-boot.git] / arch / powerpc / lib / board.c
index 628d067abf1b8ad66c5aabd241b9b21b3602b6d2..22bbc52da55066b0387d9dc09f6c5cf256ca69be 100644 (file)
@@ -107,7 +107,7 @@ void doc_init (void);
 
 static char *failed = "*** failed ***\n";
 
-#if defined(CONFIG_OXC) || defined(CONFIG_PCU_E) || defined(CONFIG_RMU)
+#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
 extern flash_info_t flash_info[];
 #endif
 
@@ -118,22 +118,12 @@ extern int board_start_ide(void);
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if defined(CONFIG_ENV_IS_EMBEDDED)
-#define TOTAL_MALLOC_LEN       CONFIG_SYS_MALLOC_LEN
-#elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
-       (CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
-      defined(CONFIG_ENV_IS_IN_NVRAM)
-#define        TOTAL_MALLOC_LEN        (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
-#else
-#define        TOTAL_MALLOC_LEN        CONFIG_SYS_MALLOC_LEN
-#endif
-
 #if !defined(CONFIG_SYS_MEM_TOP_HIDE)
 #define CONFIG_SYS_MEM_TOP_HIDE        0
 #endif
 
 extern ulong __init_end;
-extern ulong _end;
+extern ulong __bss_end__;
 ulong monitor_flash_len;
 
 #if defined(CONFIG_CMD_BEDBUG)
@@ -185,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)
 {
@@ -403,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
@@ -453,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)
@@ -490,6 +500,7 @@ void board_init_f (ulong bootflag)
         */
        addr_sp -= sizeof (bd_t);
        bd = (bd_t *) addr_sp;
+       memset(bd, 0, sizeof(bd_t));
        gd->bd = bd;
        debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
                        sizeof (bd_t), addr_sp);
@@ -519,15 +530,9 @@ void board_init_f (ulong bootflag)
        bd->bi_memstart  = CONFIG_SYS_SDRAM_BASE;       /* start of  DRAM memory        */
        bd->bi_memsize   = gd->ram_size;        /* size  of  DRAM memory in bytes */
 
-#ifdef CONFIG_IP860
-       bd->bi_sramstart = SRAM_BASE;   /* start of  SRAM memory        */
-       bd->bi_sramsize  = SRAM_SIZE;   /* size  of  SRAM memory        */
-#elif defined CONFIG_MPC8220
+#ifdef CONFIG_SYS_SRAM_BASE
        bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;        /* start of  SRAM memory        */
        bd->bi_sramsize  = CONFIG_SYS_SRAM_SIZE;        /* size  of  SRAM memory        */
-#else
-       bd->bi_sramstart = 0;           /* FIXME */ /* start of  SRAM memory    */
-       bd->bi_sramsize  = 0;           /* FIXME */ /* size  of  SRAM memory    */
 #endif
 
 #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
@@ -561,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 */
@@ -652,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
@@ -694,15 +708,14 @@ void board_init_r (gd_t *id, ulong dest_addr)
        unlock_ram_in_cache();  /* it's time to unlock D-cache in e500 */
 #endif
 
-#if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
+#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT)
        /*
-        * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
-        * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
-        * bridge there.
+        * Do early PCI configuration _before_ the flash gets initialised,
+        * because PCU ressources are crucial for flash access on some boards.
         */
        pci_init ();
 #endif
-#if defined(CONFIG_BAB7xx)
+#if defined(CONFIG_WINBOND_83C553)
        /*
         * Initialise the ISA bridge
         */
@@ -714,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, "");
                /*
@@ -748,19 +765,12 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #endif
 
 
-# if defined(CONFIG_PCU_E) || defined(CONFIG_OXC) || defined(CONFIG_RMU)
+# 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  */
-# else
-       bd->bi_flashoffset = 0;
 # endif
-#else  /* CONFIG_SYS_NO_FLASH */
-
-       bd->bi_flashsize = 0;
-       bd->bi_flashstart = 0;
-       bd->bi_flashoffset = 0;
 #endif /* !CONFIG_SYS_NO_FLASH */
 
        WATCHDOG_RESET ();
@@ -797,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
@@ -817,14 +835,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
                if (s && ((*s == 'y') || (*s == 'Y'))) {
                        bd->bi_iic_fast[0] = 1;
                        bd->bi_iic_fast[1] = 1;
-               } else {
-                       bd->bi_iic_fast[0] = 0;
-                       bd->bi_iic_fast[1] = 0;
                }
        }
-#else
-       bd->bi_iic_fast[0] = 0;
-       bd->bi_iic_fast[1] = 0;
 #endif /* CONFIG_I2CFAST */
 #endif /* CONFIG_405GP, CONFIG_405EP */
 #endif /* CONFIG_SYS_EXTBDINFO */
@@ -869,7 +881,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
        WATCHDOG_RESET ();
 
-#if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx) && !defined(CONFIG_CPC45)
+#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT)
        /*
         * Do pci configuration
         */
@@ -914,21 +926,12 @@ void board_init_r (gd_t *id, ulong dest_addr)
         */
        interrupt_init ();
 
-       /* Must happen after interrupts are initialized since
-        * an irq handler gets installed
-        */
-#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
-       serial_buffered_init();
-#endif
-
 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
        status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
 #endif
 
        udelay (20);
 
-       set_timer (0);
-
        /* Initialize from environment */
        if ((s = getenv ("loadaddr")) != NULL) {
                load_addr = simple_strtoul (s, NULL, 16);