]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - arch/arm/lib/board.c
armv7: integrate cache maintenance support
[karo-tx-uboot.git] / arch / arm / lib / board.c
index 54519b0e1d87fb0b3c4cebfac70c6f5a158b74ee..fc52a26b797a47c2945e9846c4d877efb58b091b 100644 (file)
@@ -126,7 +126,8 @@ static int init_baudrate (void)
 {
        char tmp[64];   /* long enough for environment variables */
        int i = getenv_f("baudrate", tmp, sizeof (tmp));
-       gd->bd->bi_baudrate = gd->baudrate = (i > 0)
+
+       gd->baudrate = (i > 0)
                        ? (int) simple_strtoul (tmp, NULL, 10)
                        : CONFIG_BAUDRATE;
 
@@ -137,7 +138,8 @@ static int display_banner (void)
 {
        printf ("\n\n%s\n\n", version_string);
        debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
-              _armboot_start, _bss_start, _bss_end);
+              _TEXT_BASE,
+              _bss_start_ofs+_TEXT_BASE, _bss_end_ofs+_TEXT_BASE);
 #ifdef CONFIG_MODEM_SUPPORT
        debug ("Modem Support enabled\n");
 #endif
@@ -180,14 +182,6 @@ static int display_dram_config (void)
        return (0);
 }
 
-#ifndef CONFIG_SYS_NO_FLASH
-static void display_flash_config (ulong size)
-{
-       puts ("Flash: ");
-       print_size (size, "\n");
-}
-#endif /* CONFIG_SYS_NO_FLASH */
-
 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 static int init_func_i2c (void)
 {
@@ -234,13 +228,20 @@ typedef int (init_fnc_t) (void);
 
 int print_cpuinfo (void);
 
+void __dram_init_banksize(void)
+{
+       gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
+       gd->bd->bi_dram[0].size =  gd->ram_size;
+}
+void dram_init_banksize(void)
+       __attribute__((weak, alias("__dram_init_banksize")));
+
 init_fnc_t *init_sequence[] = {
 #if defined(CONFIG_ARCH_CPU_INIT)
        arch_cpu_init,          /* basic arch cpu dependent setup */
 #endif
-       board_init,             /* basic board dependent setup */
-#if defined(CONFIG_USE_IRQ)
-       interrupt_init,         /* set up exceptions */
+#if defined(CONFIG_BOARD_EARLY_INIT_F)
+       board_early_init_f,
 #endif
        timer_init,             /* initialize timer */
 #ifdef CONFIG_FSL_ESDHC
@@ -261,33 +262,24 @@ init_fnc_t *init_sequence[] = {
        init_func_i2c,
 #endif
        dram_init,              /* configure available RAM banks */
-#if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
-       arm_pci_init,
-#endif
-       display_dram_config,
        NULL,
 };
 
-void start_armboot (void)
+void board_init_f (ulong bootflag)
 {
+       bd_t *bd;
        init_fnc_t **init_fnc_ptr;
-       char *s;
-#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
-       unsigned long addr;
-#endif
+       gd_t *id;
+       ulong addr, addr_sp;
 
        /* Pointer is writable since we allocated a register for it */
-       gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
+       gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
        /* compiler optimization barrier needed for GCC >= 3.4 */
        __asm__ __volatile__("": : :"memory");
 
        memset ((void*)gd, 0, sizeof (gd_t));
-       gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
-       memset (gd->bd, 0, sizeof (bd_t));
 
-       gd->flags |= GD_FLG_RELOC;
-
-       monitor_flash_len = _bss_start - _armboot_start;
+       gd->mon_len = _bss_end_ofs;
 
        for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
                if ((*init_fnc_ptr)() != 0) {
@@ -295,43 +287,221 @@ void start_armboot (void)
                }
        }
 
-       /* armboot_start is defined in the board-specific linker script */
-       mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
-                       CONFIG_SYS_MALLOC_LEN);
+       debug ("monitor len: %08lX\n", gd->mon_len);
+       /*
+        * Ram is setup, size stored in gd !!
+        */
+       debug ("ramsize: %08lX\n", gd->ram_size);
+#if defined(CONFIG_SYS_MEM_TOP_HIDE)
+       /*
+        * Subtract specified amount of memory to hide so that it won't
+        * get "touched" at all by U-Boot. By fixing up gd->ram_size
+        * the Linux kernel should now get passed the now "corrected"
+        * memory size and won't touch it either. This should work
+        * for arch/ppc and arch/powerpc. Only Linux board ports in
+        * arch/powerpc with bootwrapper support, that recalculate the
+        * memory size from the SDRAM controller setup will have to
+        * get fixed.
+        */
+       gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
+#endif
 
-#ifndef CONFIG_SYS_NO_FLASH
-       /* configure available FLASH banks */
-       display_flash_config (flash_init ());
-#endif /* CONFIG_SYS_NO_FLASH */
+       addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
 
-#ifdef CONFIG_VFD
-#      ifndef PAGE_SIZE
-#        define PAGE_SIZE 4096
-#      endif
+#ifdef CONFIG_LOGBUFFER
+#ifndef CONFIG_ALT_LB_ADDR
+       /* reserve kernel log buffer */
+       addr -= (LOGBUFF_RESERVE);
+       debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
+#endif
+#endif
+
+#ifdef CONFIG_PRAM
        /*
-        * reserve memory for VFD display (always full pages)
+        * reserve protected RAM
         */
-       /* bss_end is defined in the board-specific linker script */
-       addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
-       vfd_setmem (addr);
-       gd->fb_base = addr;
-#endif /* CONFIG_VFD */
+       i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
+       reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
+       addr -= (reg << 10);            /* size is in kB */
+       debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
+#endif /* CONFIG_PRAM */
+
+#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
+       /* reserve TLB table */
+       addr -= (4096 * 4);
+
+       /* round down to next 64 kB limit */
+       addr &= ~(0x10000 - 1);
+
+       gd->tlb_addr = addr;
+       debug ("TLB table at: %08lx\n", addr);
+#endif
+
+       /* round down to next 4 kB limit */
+       addr &= ~(4096 - 1);
+       debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
 
 #ifdef CONFIG_LCD
-       /* board init may have inited fb_base */
-       if (!gd->fb_base) {
-#              ifndef PAGE_SIZE
-#                define PAGE_SIZE 4096
-#              endif
+#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 */
+
+       /*
+        * reserve memory for U-Boot code, data & bss
+        * round down to next 4 kB limit
+        */
+       addr -= gd->mon_len;
+       addr &= ~(4096 - 1);
+
+       debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
+
+#ifndef CONFIG_PRELOADER
+       /*
+        * reserve memory for malloc() arena
+        */
+       addr_sp = addr - TOTAL_MALLOC_LEN;
+       debug ("Reserving %dk for malloc() at: %08lx\n",
+                       TOTAL_MALLOC_LEN >> 10, addr_sp);
+       /*
+        * (permanently) allocate a Board Info struct
+        * and a permanent copy of the "global" data
+        */
+       addr_sp -= sizeof (bd_t);
+       bd = (bd_t *) addr_sp;
+       gd->bd = bd;
+       debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
+                       sizeof (bd_t), addr_sp);
+       addr_sp -= sizeof (gd_t);
+       id = (gd_t *) addr_sp;
+       debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
+                       sizeof (gd_t), addr_sp);
+
+       /* setup stackpointer for exeptions */
+       gd->irq_sp = addr_sp;
+#ifdef CONFIG_USE_IRQ
+       addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
+       debug ("Reserving %zu Bytes for IRQ stack at: %08lx\n",
+               CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
+#endif
+       /* leave 3 words for abort-stack    */
+       addr_sp -= 12;
+
+       /* 8-byte alignment for ABI compliance */
+       addr_sp &= ~0x07;
+#else
+       addr_sp += 128; /* leave 32 words for abort-stack   */
+       gd->irq_sp = addr_sp;
+#endif
+
+       debug ("New Stack Pointer is: %08lx\n", addr_sp);
+
+#ifdef CONFIG_POST
+       post_bootmode_init();
+       post_run (NULL, POST_ROM | post_bootmode_get(0));
+#endif
+
+       gd->bd->bi_baudrate = gd->baudrate;
+       /* Ram ist board specific, so move it to board code ... */
+       dram_init_banksize();
+       display_dram_config();  /* and display it */
+
+       gd->relocaddr = addr;
+       gd->start_addr_sp = addr_sp;
+       gd->reloc_off = addr - _TEXT_BASE;
+       debug ("relocation Offset is: %08lx\n", gd->reloc_off);
+       memcpy (id, (void *)gd, sizeof (gd_t));
+
+       relocate_code (addr_sp, id, addr);
+
+       /* NOTREACHED - relocate_code() does not return */
+}
+
+#if !defined(CONFIG_SYS_NO_FLASH)
+static char *failed = "*** failed ***\n";
+#endif
+
+/************************************************************************
+ *
+ * This is the next part if the initialization sequence: we are now
+ * running from RAM and have a "normal" C environment, i. e. global
+ * data can be written, BSS has been cleared, the stack size in not
+ * that critical any more, etc.
+ *
+ ************************************************************************
+ */
+
+void board_init_r (gd_t *id, ulong dest_addr)
+{
+       char *s;
+       bd_t *bd;
+       ulong malloc_start;
+#if !defined(CONFIG_SYS_NO_FLASH)
+       ulong flash_size;
+#endif
+
+       gd = id;
+       bd = gd->bd;
+
+       gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
+
+       monitor_flash_len = _end_ofs;
+       /*
+        * Enable D$:
+        * I$, if needed, must be already enabled in start.S
+        */
+       dcache_enable();
+
+       debug ("monitor flash len: %08lX\n", monitor_flash_len);
+       board_init();   /* Setup chipselects */
+
+#ifdef CONFIG_SERIAL_MULTI
+       serial_initialize();
+#endif
+
+       debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
+
+#ifdef CONFIG_LOGBUFFER
+       logbuff_init_ptrs ();
+#endif
+#ifdef CONFIG_POST
+       post_output_backlog ();
+#endif
+
+       /* The Malloc area is immediately below the monitor copy in DRAM */
+       malloc_start = dest_addr - TOTAL_MALLOC_LEN;
+       mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
+
+#if !defined(CONFIG_SYS_NO_FLASH)
+       puts ("Flash: ");
+
+       if ((flash_size = flash_init ()) > 0) {
+# ifdef CONFIG_SYS_FLASH_CHECKSUM
+               print_size (flash_size, "");
                /*
-                * reserve memory for LCD display (always full pages)
+                * Compute and print flash CRC if flashchecksum is set to 'y'
+                *
+                * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
                 */
-               /* bss_end is defined in the board-specific linker script */
-               addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
-               lcd_setmem (addr);
-               gd->fb_base = addr;
+               s = getenv ("flashchecksum");
+               if (s && (*s == 'y')) {
+                       printf ("  CRC: %08X",
+                               crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)
+                       );
+               }
+               putc ('\n');
+# else /* !CONFIG_SYS_FLASH_CHECKSUM */
+               print_size (flash_size, "\n");
+# endif /* CONFIG_SYS_FLASH_CHECKSUM */
+       } else {
+               puts (failed);
+               hang ();
        }
-#endif /* CONFIG_LCD */
+#endif
 
 #if defined(CONFIG_CMD_NAND)
        puts ("NAND:  ");
@@ -342,6 +512,11 @@ void start_armboot (void)
        onenand_init();
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts("MMC:   ");
+       mmc_initialize(bd);
+#endif
+
 #ifdef CONFIG_HAS_DATAFLASH
        AT91F_DataflashInit();
        dataflash_print_info();
@@ -350,13 +525,8 @@ void start_armboot (void)
        /* initialize environment */
        env_relocate ();
 
-#ifdef CONFIG_VFD
-       /* must do this after the framebuffer is allocated */
-       drv_vfd_init();
-#endif /* CONFIG_VFD */
-
-#ifdef CONFIG_SERIAL_MULTI
-       serial_initialize();
+#if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
+       arm_pci_init();
 #endif
 
        /* IP Address */
@@ -382,20 +552,12 @@ void start_armboot (void)
        misc_init_r ();
 #endif
 
+        /* set up exceptions */
+       interrupt_init ();
        /* enable exceptions */
        enable_interrupts ();
 
        /* Perform network card initialisation if necessary */
-#ifdef CONFIG_DRIVER_TI_EMAC
-       /* XXX: this needs to be moved to board init */
-extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
-       if (getenv ("ethaddr")) {
-               uchar enetaddr[6];
-               eth_getenv_enetaddr("ethaddr", enetaddr);
-               davinci_eth_set_mac_addr(enetaddr);
-       }
-#endif
-
 #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
        /* XXX: this needs to be moved to board init */
        if (getenv ("ethaddr")) {
@@ -419,11 +581,6 @@ extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
        board_late_init ();
 #endif
 
-#ifdef CONFIG_GENERIC_MMC
-       puts ("MMC:   ");
-       mmc_initialize (gd->bd);
-#endif
-
 #ifdef CONFIG_BITBANGMII
        bb_miiphy_init();
 #endif
@@ -437,6 +594,41 @@ extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
        reset_phy();
 #endif
 #endif
+
+#ifdef CONFIG_POST
+       post_run (NULL, POST_RAM | post_bootmode_get(0));
+#endif
+
+#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
+       /*
+        * Export available size of memory for Linux,
+        * taking into account the protected RAM at top of memory
+        */
+       {
+               ulong pram;
+               uchar memsz[32];
+#ifdef CONFIG_PRAM
+               char *s;
+
+               if ((s = getenv ("pram")) != NULL) {
+                       pram = simple_strtoul (s, NULL, 10);
+               } else {
+                       pram = CONFIG_PRAM;
+               }
+#else
+               pram=0;
+#endif
+#ifdef CONFIG_LOGBUFFER
+#ifndef CONFIG_ALT_LB_ADDR
+               /* Also take the logbuffer into account (pram is in kB) */
+               pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
+#endif
+#endif
+               sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
+               setenv ("mem", (char *)memsz);
+       }
+#endif
+
        /* main_loop() can return to retry autoboot, if so just run it again. */
        for (;;) {
                main_loop ();