]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib_blackfin/board.c
Blackfin: drop reference to gd->reloc_off
[karo-tx-uboot.git] / lib_blackfin / board.c
index fef1934d6faa2bace750177a551849b95e4d34ba..b0b52b2ba87c6d6d78bc06ed8622e9092ca95cd0 100644 (file)
 
 #include <common.h>
 #include <command.h>
-#include <devices.h>
+#include <stdio_dev.h>
 #include <environment.h>
 #include <malloc.h>
+#include <mmc.h>
 #include <net.h>
 #include <timestamp.h>
 #include <status_led.h>
 
 #include <asm/cplb.h>
 #include <asm/mach-common/bits/mpu.h>
+#include <kgdb.h>
 
 #ifdef CONFIG_CMD_NAND
 #include <nand.h>      /* cannot even include nand.h if it isnt configured */
 #endif
 
+#ifdef CONFIG_BITBANGMII
+#include <miiphy.h>
+#endif
+
 #if defined(CONFIG_POST)
 #include <post.h>
 int post_flag;
@@ -44,77 +50,14 @@ static inline void serial_early_puts(const char *s)
 #endif
 }
 
-/* Get the input voltage */
-static u_long get_vco(void)
-{
-       u_long msel;
-       u_long vco;
-
-       msel = (*pPLL_CTL >> 9) & 0x3F;
-       if (0 == msel)
-               msel = 64;
-
-       vco = CONFIG_CLKIN_HZ;
-       vco >>= (1 & *pPLL_CTL);        /* DF bit */
-       vco = msel * vco;
-       return vco;
-}
-
-/* Get the Core clock */
-u_long get_cclk(void)
-{
-       u_long csel, ssel;
-       if (*pPLL_STAT & 0x1)
-               return CONFIG_CLKIN_HZ;
-
-       ssel = *pPLL_DIV;
-       csel = ((ssel >> 4) & 0x03);
-       ssel &= 0xf;
-       if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
-               return get_vco() / ssel;
-       return get_vco() >> csel;
-}
-
-/* Get the System clock */
-u_long get_sclk(void)
-{
-       u_long ssel;
-
-       if (*pPLL_STAT & 0x1)
-               return CONFIG_CLKIN_HZ;
-
-       ssel = (*pPLL_DIV & 0xf);
-
-       return get_vco() / ssel;
-}
-
-static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk;
-
-static void mem_malloc_init(void)
-{
-       mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE;
-       mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
-       mem_malloc_brk = mem_malloc_start;
-       memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
-}
-
-void *sbrk(ptrdiff_t increment)
-{
-       void *old = mem_malloc_brk;
-       void *new = old + increment;
-
-       if (new < mem_malloc_start || new > mem_malloc_end)
-               return NULL;
-
-       mem_malloc_brk = new;
-
-       return old;
-}
-
 static int display_banner(void)
 {
        printf("\n\n%s\n\n", version_string);
-       printf("CPU:   ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid());
+       printf("CPU:   ADSP " MK_STR(CONFIG_BFIN_CPU) " "
+               "(Detected Rev: 0.%d) "
+               "(%s boot)\n",
+               bfin_revid(),
+               get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE));
        return 0;
 }
 
@@ -130,33 +73,31 @@ static int init_baudrate(void)
 
 static void display_global_data(void)
 {
-#ifdef CONFIG_DEBUG_EARLY_SERIAL
        bd_t *bd;
+
+#ifndef CONFIG_DEBUG_EARLY_SERIAL
+       return;
+#endif
+
        bd = gd->bd;
-       printf(" gd: %x\n", gd);
-       printf(" |-flags: %x\n", gd->flags);
-       printf(" |-board_type: %x\n", gd->board_type);
-       printf(" |-baudrate: %i\n", gd->baudrate);
-       printf(" |-have_console: %x\n", gd->have_console);
-       printf(" |-ram_size: %x\n", gd->ram_size);
-       printf(" |-reloc_off: %x\n", gd->reloc_off);
-       printf(" |-env_addr: %x\n", gd->env_addr);
-       printf(" |-env_valid: %x\n", gd->env_valid);
-       printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt));
-       printf(" \\-bd: %x\n", gd->bd);
+       printf(" gd: %p\n", gd);
+       printf(" |-flags: %lx\n", gd->flags);
+       printf(" |-board_type: %lx\n", gd->board_type);
+       printf(" |-baudrate: %lu\n", gd->baudrate);
+       printf(" |-have_console: %lx\n", gd->have_console);
+       printf(" |-ram_size: %lx\n", gd->ram_size);
+       printf(" |-env_addr: %lx\n", gd->env_addr);
+       printf(" |-env_valid: %lx\n", gd->env_valid);
+       printf(" |-jt(%p): %p\n", gd->jt, *(gd->jt));
+       printf(" \\-bd: %p\n", gd->bd);
        printf("   |-bi_baudrate: %x\n", bd->bi_baudrate);
-       printf("   |-bi_ip_addr: %x\n", bd->bi_ip_addr);
-       printf("   |-bi_enetaddr: %x %x %x %x %x %x\n",
-              bd->bi_enetaddr[0], bd->bi_enetaddr[1],
-              bd->bi_enetaddr[2], bd->bi_enetaddr[3],
-              bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
-       printf("   |-bi_boot_params: %x\n", bd->bi_boot_params);
-       printf("   |-bi_memstart: %x\n", bd->bi_memstart);
-       printf("   |-bi_memsize: %x\n", bd->bi_memsize);
-       printf("   |-bi_flashstart: %x\n", bd->bi_flashstart);
-       printf("   |-bi_flashsize: %x\n", bd->bi_flashsize);
-       printf("   \\-bi_flashoffset: %x\n", bd->bi_flashoffset);
-#endif
+       printf("   |-bi_ip_addr: %lx\n", bd->bi_ip_addr);
+       printf("   |-bi_boot_params: %lx\n", bd->bi_boot_params);
+       printf("   |-bi_memstart: %lx\n", bd->bi_memstart);
+       printf("   |-bi_memsize: %lx\n", bd->bi_memsize);
+       printf("   |-bi_flashstart: %lx\n", bd->bi_flashstart);
+       printf("   |-bi_flashsize: %lx\n", bd->bi_flashsize);
+       printf("   \\-bi_flashoffset: %lx\n", bd->bi_flashoffset);
 }
 
 #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
@@ -193,17 +134,26 @@ void init_cplbtables(void)
        dcplb_add(0xFF800000, L1_DMEMORY);
        ++i;
 
-       icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL);
-       dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL);
-       ++i;
+       if (CONFIG_MEM_SIZE) {
+               uint32_t mbase = CONFIG_SYS_MONITOR_BASE;
+               uint32_t mend  = mbase + CONFIG_SYS_MONITOR_LEN;
+               mbase &= CPLB_PAGE_MASK;
+               mend &= CPLB_PAGE_MASK;
 
-       /* If the monitor crosses a 4 meg boundary, we'll need
-        * to lock two entries for it.
-        */
-       if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) {
-               icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL);
-               dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL);
+               icplb_add(mbase, SDRAM_IKERNEL);
+               dcplb_add(mbase, SDRAM_DKERNEL);
                ++i;
+
+               /*
+                * If the monitor crosses a 4 meg boundary, we'll need
+                * to lock two entries for it.  We assume it doesn't
+                * cross two 4 meg boundaries ...
+                */
+               if (mbase != mend) {
+                       icplb_add(mend, SDRAM_IKERNEL);
+                       dcplb_add(mend, SDRAM_DKERNEL);
+                       ++i;
+               }
        }
 
        icplb_add(0x20000000, SDRAM_INON_CHBL);
@@ -302,6 +252,8 @@ void board_init_f(ulong bootflag)
        bd->bi_vco = get_vco();
        bd->bi_cclk = get_cclk();
        bd->bi_sclk = get_sclk();
+       bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
+       bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
 
        /* Initialize */
        serial_early_puts("IRQ init\n");
@@ -325,7 +277,7 @@ void board_init_f(ulong bootflag)
        printf("System: %s MHz\n", strmhz(buf, get_sclk()));
 
        printf("RAM:   ");
-       print_size(initdram(0), "\n");
+       print_size(bd->bi_memsize, "\n");
 #if defined(CONFIG_POST)
        post_init_f();
        post_bootmode_init();
@@ -335,9 +287,26 @@ void board_init_f(ulong bootflag)
        board_init_r((gd_t *) gd, 0x20000010);
 }
 
+static void board_net_init_r(bd_t *bd)
+{
+#ifdef CONFIG_BITBANGMII
+       bb_miiphy_init();
+#endif
+#ifdef CONFIG_CMD_NET
+       char *s;
+
+       if ((s = getenv("bootfile")) != NULL)
+               copy_filename(BootFile, s, sizeof(BootFile));
+
+       bd->bi_ip_addr = getenv_IPaddr("ipaddr");
+
+       printf("Net:   ");
+       eth_initialize(gd->bd);
+#endif
+}
+
 void board_init_r(gd_t * id, ulong dest_addr)
 {
-       extern void malloc_bin_reloc(void);
        char *s;
        bd_t *bd;
        gd = id;
@@ -349,15 +318,18 @@ void board_init_r(gd_t * id, ulong dest_addr)
        post_reloc();
 #endif
 
+       /* initialize malloc() area */
+       mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
+
 #if    !defined(CONFIG_SYS_NO_FLASH)
-       /* There are some other pointer constants we must deal with */
-       /* configure available FLASH banks */
+       /* Initialize the flash and protect u-boot by default */
        extern flash_info_t flash_info[];
-       ulong size = flash_init();
        puts("Flash: ");
+       ulong size = flash_init();
        print_size(size, "\n");
        flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE,
-                     CONFIG_SYS_FLASH_BASE + 0x1ffff, &flash_info[0]);
+               CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1,
+               &flash_info[0]);
        bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
        bd->bi_flashsize = size;
        bd->bi_flashoffset = 0;
@@ -366,54 +338,32 @@ void board_init_r(gd_t * id, ulong dest_addr)
        bd->bi_flashsize = 0;
        bd->bi_flashoffset = 0;
 #endif
-       /* initialize malloc() area */
-       mem_malloc_init();
-       malloc_bin_reloc();
 
 #ifdef CONFIG_CMD_NAND
        puts("NAND:  ");
        nand_init();            /* go init the NAND */
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts("MMC:  ");
+       mmc_initialize(bd);
+#endif
+
        /* relocate environment function pointers etc. */
        env_relocate();
 
-#ifdef CONFIG_CMD_NET
-       /* board MAC address */
-       s = getenv("ethaddr");
-       if (s == NULL) {
-# ifndef CONFIG_ETHADDR
-#  if 0
-               if (!board_get_enetaddr(bd->bi_enetaddr)) {
-                       char nid[20];
-                       sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X",
-                               bd->bi_enetaddr[0], bd->bi_enetaddr[1],
-                               bd->bi_enetaddr[2], bd->bi_enetaddr[3],
-                               bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
-                       setenv("ethaddr", nid);
-               }
-#  endif
-# endif
-       } else {
-               int i;
-               char *e;
-               for (i = 0; i < 6; ++i) {
-                       bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16);
-                       s = (*e) ? e + 1 : e;
-               }
-       }
-
-       /* IP Address */
-       bd->bi_ip_addr = getenv_IPaddr("ipaddr");
-#endif
-
-       /* Initialize devices */
-       devices_init();
+       /* Initialize stdio devices */
+       stdio_init();
        jumptable_init();
 
        /* Initialize the console (after the relocation and devices init) */
        console_init_r();
 
+#ifdef CONFIG_CMD_KGDB
+       puts("KGDB:  ");
+       kgdb_init();
+#endif
+
 #ifdef CONFIG_STATUS_LED
        status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
        status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF);
@@ -422,24 +372,13 @@ void board_init_r(gd_t * id, ulong dest_addr)
        /* Initialize from environment */
        if ((s = getenv("loadaddr")) != NULL)
                load_addr = simple_strtoul(s, NULL, 16);
-#ifdef CONFIG_CMD_NET
-       if ((s = getenv("bootfile")) != NULL)
-               copy_filename(BootFile, s, sizeof(BootFile));
-#endif
 
 #if defined(CONFIG_MISC_INIT_R)
        /* miscellaneous platform dependent initialisations */
        misc_init_r();
 #endif
 
-#ifdef CONFIG_CMD_NET
-       printf("Net:   ");
-       eth_initialize(gd->bd);
-       if (getenv("ethaddr"))
-               printf("MAC:   %02X:%02X:%02X:%02X:%02X:%02X\n",
-                       bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2],
-                       bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
-#endif
+       board_net_init_r(bd);
 
        display_global_data();
 
@@ -448,6 +387,12 @@ void board_init_r(gd_t * id, ulong dest_addr)
                post_run(NULL, POST_RAM | post_bootmode_get(0));
 #endif
 
+       if (bfin_os_log_check()) {
+               puts("\nLog buffer from operating system:\n");
+               bfin_os_log_dump();
+               puts("\n");
+       }
+
        /* main_loop() can return to retry autoboot, if so just run it again. */
        for (;;)
                main_loop();