Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - board.c First C file to be called contains init routines |
| 3 | * |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 4 | * Copyright (c) 2005-2008 Analog Devices Inc. |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 5 | * |
| 6 | * (C) Copyright 2000-2004 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 9 | * Licensed under the GPL-2 or later. |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <command.h> |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 14 | #include <devices.h> |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 15 | #include <environment.h> |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 16 | #include <i2c.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 17 | #include <malloc.h> |
| 18 | #include <net.h> |
| 19 | #include <version.h> |
| 20 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 21 | #include <asm/cplb.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 22 | #include <asm/mach-common/bits/mpu.h> |
| 23 | |
| 24 | #ifdef CONFIG_CMD_NAND |
| 25 | #include <nand.h> /* cannot even include nand.h if it isnt configured */ |
| 26 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 27 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 28 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 29 | #include <post.h> |
| 30 | int post_flag; |
| 31 | #endif |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 32 | |
Wolfgang Denk | d112a2c | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 35 | const char version_string[] = U_BOOT_VERSION " (" __DATE__ " - " __TIME__ ")"; |
| 36 | |
| 37 | __attribute__((always_inline)) |
| 38 | static inline void serial_early_puts(const char *s) |
| 39 | { |
| 40 | #ifdef CONFIG_DEBUG_EARLY_SERIAL |
| 41 | serial_puts("Early: "); |
| 42 | serial_puts(s); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 43 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 44 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 45 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 46 | /* Get the input voltage */ |
| 47 | static u_long get_vco(void) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 48 | { |
| 49 | u_long msel; |
| 50 | u_long vco; |
| 51 | |
| 52 | msel = (*pPLL_CTL >> 9) & 0x3F; |
| 53 | if (0 == msel) |
| 54 | msel = 64; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 55 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 56 | vco = CONFIG_CLKIN_HZ; |
| 57 | vco >>= (1 & *pPLL_CTL); /* DF bit */ |
| 58 | vco = msel * vco; |
| 59 | return vco; |
| 60 | } |
| 61 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 62 | /* Get the Core clock */ |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 63 | u_long get_cclk(void) |
| 64 | { |
| 65 | u_long csel, ssel; |
| 66 | if (*pPLL_STAT & 0x1) |
| 67 | return CONFIG_CLKIN_HZ; |
| 68 | |
| 69 | ssel = *pPLL_DIV; |
| 70 | csel = ((ssel >> 4) & 0x03); |
| 71 | ssel &= 0xf; |
| 72 | if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */ |
| 73 | return get_vco() / ssel; |
| 74 | return get_vco() >> csel; |
| 75 | } |
| 76 | |
| 77 | /* Get the System clock */ |
| 78 | u_long get_sclk(void) |
| 79 | { |
| 80 | u_long ssel; |
| 81 | |
| 82 | if (*pPLL_STAT & 0x1) |
| 83 | return CONFIG_CLKIN_HZ; |
| 84 | |
| 85 | ssel = (*pPLL_DIV & 0xf); |
| 86 | |
| 87 | return get_vco() / ssel; |
| 88 | } |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 89 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 90 | static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk; |
| 91 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 92 | static void mem_malloc_init(void) |
| 93 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE; |
| 95 | mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 96 | mem_malloc_brk = mem_malloc_start; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 97 | memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void *sbrk(ptrdiff_t increment) |
| 101 | { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 102 | void *old = mem_malloc_brk; |
| 103 | void *new = old + increment; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 104 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 105 | if (new < mem_malloc_start || new > mem_malloc_end) |
| 106 | return NULL; |
| 107 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 108 | mem_malloc_brk = new; |
| 109 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 110 | return old; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static int display_banner(void) |
| 114 | { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 115 | printf("\n\n%s\n\n", version_string); |
Mike Frysinger | f0dd792 | 2008-02-18 05:26:48 -0500 | [diff] [blame] | 116 | printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid()); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 117 | return 0; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 120 | static int init_baudrate(void) |
| 121 | { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 122 | char baudrate[15]; |
| 123 | int i = getenv_r("baudrate", baudrate, sizeof(baudrate)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 124 | gd->bd->bi_baudrate = gd->baudrate = (i > 0) |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 125 | ? simple_strtoul(baudrate, NULL, 10) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 126 | : CONFIG_BAUDRATE; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 127 | return 0; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 130 | static void display_global_data(void) |
| 131 | { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 132 | #ifdef CONFIG_DEBUG_EARLY_SERIAL |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 133 | bd_t *bd; |
| 134 | bd = gd->bd; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 135 | printf(" gd: %x\n", gd); |
| 136 | printf(" |-flags: %x\n", gd->flags); |
| 137 | printf(" |-board_type: %x\n", gd->board_type); |
| 138 | printf(" |-baudrate: %i\n", gd->baudrate); |
| 139 | printf(" |-have_console: %x\n", gd->have_console); |
| 140 | printf(" |-ram_size: %x\n", gd->ram_size); |
| 141 | printf(" |-reloc_off: %x\n", gd->reloc_off); |
| 142 | printf(" |-env_addr: %x\n", gd->env_addr); |
| 143 | printf(" |-env_valid: %x\n", gd->env_valid); |
| 144 | printf(" |-jt(%x): %x\n", gd->jt, *(gd->jt)); |
| 145 | printf(" \\-bd: %x\n", gd->bd); |
| 146 | printf(" |-bi_baudrate: %x\n", bd->bi_baudrate); |
| 147 | printf(" |-bi_ip_addr: %x\n", bd->bi_ip_addr); |
| 148 | printf(" |-bi_enetaddr: %x %x %x %x %x %x\n", |
| 149 | bd->bi_enetaddr[0], bd->bi_enetaddr[1], |
| 150 | bd->bi_enetaddr[2], bd->bi_enetaddr[3], |
| 151 | bd->bi_enetaddr[4], bd->bi_enetaddr[5]); |
| 152 | printf(" |-bi_boot_params: %x\n", bd->bi_boot_params); |
| 153 | printf(" |-bi_memstart: %x\n", bd->bi_memstart); |
| 154 | printf(" |-bi_memsize: %x\n", bd->bi_memsize); |
| 155 | printf(" |-bi_flashstart: %x\n", bd->bi_flashstart); |
| 156 | printf(" |-bi_flashsize: %x\n", bd->bi_flashsize); |
| 157 | printf(" \\-bi_flashoffset: %x\n", bd->bi_flashoffset); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 158 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 159 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 160 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 161 | #define CPLB_PAGE_SIZE (4 * 1024 * 1024) |
| 162 | #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1)) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 163 | void init_cplbtables(void) |
| 164 | { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 165 | volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA; |
| 166 | volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA; |
| 167 | uint32_t extern_memory; |
| 168 | size_t i; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 169 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 170 | void icplb_add(uint32_t addr, uint32_t data) |
| 171 | { |
| 172 | *(ICPLB_ADDR + i) = addr; |
| 173 | *(ICPLB_DATA + i) = data; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 174 | } |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 175 | void dcplb_add(uint32_t addr, uint32_t data) |
| 176 | { |
| 177 | *(DCPLB_ADDR + i) = addr; |
| 178 | *(DCPLB_DATA + i) = data; |
| 179 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 180 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 181 | /* populate a few common entries ... we'll let |
| 182 | * the memory map and cplb exception handler do |
| 183 | * the rest of the work. |
| 184 | */ |
| 185 | i = 0; |
| 186 | ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0; |
| 187 | ICPLB_DATA = (uint32_t *)ICPLB_DATA0; |
| 188 | DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0; |
| 189 | DCPLB_DATA = (uint32_t *)DCPLB_DATA0; |
| 190 | |
| 191 | icplb_add(0xFFA00000, L1_IMEMORY); |
| 192 | dcplb_add(0xFF800000, L1_DMEMORY); |
| 193 | ++i; |
| 194 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 195 | icplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_IKERNEL); |
| 196 | dcplb_add(CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK, SDRAM_DKERNEL); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 197 | ++i; |
| 198 | |
| 199 | /* If the monitor crosses a 4 meg boundary, we'll need |
| 200 | * to lock two entries for it. |
| 201 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 202 | if ((CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK) != ((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK)) { |
| 203 | icplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_IKERNEL); |
| 204 | dcplb_add((CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN) & CPLB_PAGE_MASK, SDRAM_DKERNEL); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 205 | ++i; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 206 | } |
| 207 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 208 | icplb_add(0x20000000, SDRAM_INON_CHBL); |
| 209 | dcplb_add(0x20000000, SDRAM_EBIU); |
| 210 | ++i; |
| 211 | |
| 212 | /* Add entries for the rest of external RAM up to the bootrom */ |
| 213 | extern_memory = 0; |
| 214 | |
| 215 | #ifdef CONFIG_DEBUG_NULL_PTR |
| 216 | icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); |
| 217 | dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); |
| 218 | ++i; |
| 219 | icplb_add(extern_memory, SDRAM_IKERNEL); |
| 220 | dcplb_add(extern_memory, SDRAM_DKERNEL); |
| 221 | extern_memory += CPLB_PAGE_SIZE; |
| 222 | ++i; |
| 223 | #endif |
| 224 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | while (i < 16 && extern_memory < (CONFIG_SYS_MONITOR_BASE & CPLB_PAGE_MASK)) { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 226 | icplb_add(extern_memory, SDRAM_IGENERIC); |
| 227 | dcplb_add(extern_memory, SDRAM_DGENERIC); |
| 228 | extern_memory += CPLB_PAGE_SIZE; |
| 229 | ++i; |
| 230 | } |
| 231 | while (i < 16) { |
| 232 | icplb_add(0, 0); |
| 233 | dcplb_add(0, 0); |
| 234 | ++i; |
| 235 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 236 | } |
| 237 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 238 | /* |
| 239 | * All attempts to come up with a "common" initialization sequence |
| 240 | * that works for all boards and architectures failed: some of the |
| 241 | * requirements are just _too_ different. To get rid of the resulting |
| 242 | * mess of board dependend #ifdef'ed code we now make the whole |
| 243 | * initialization sequence configurable to the user. |
| 244 | * |
| 245 | * The requirements for any new initalization function is simple: it |
| 246 | * receives a pointer to the "global data" structure as it's only |
| 247 | * argument, and returns an integer return code, where 0 means |
| 248 | * "continue" and != 0 means "fatal error, hang the system". |
| 249 | */ |
| 250 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 251 | extern int exception_init(void); |
| 252 | extern int irq_init(void); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 253 | extern int timer_init(void); |
| 254 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 255 | void board_init_f(ulong bootflag) |
| 256 | { |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 257 | ulong addr; |
| 258 | bd_t *bd; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 259 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 260 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 261 | serial_early_puts("Board early init flash\n"); |
| 262 | board_early_init_f(); |
| 263 | #endif |
| 264 | |
| 265 | serial_early_puts("Init CPLB tables\n"); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 266 | init_cplbtables(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 267 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 268 | serial_early_puts("Exceptions setup\n"); |
| 269 | exception_init(); |
| 270 | |
| 271 | #ifndef CONFIG_ICACHE_OFF |
| 272 | serial_early_puts("Turn on ICACHE\n"); |
| 273 | icache_enable(); |
| 274 | #endif |
| 275 | #ifndef CONFIG_DCACHE_OFF |
| 276 | serial_early_puts("Turn on DCACHE\n"); |
| 277 | dcache_enable(); |
| 278 | #endif |
| 279 | |
| 280 | serial_early_puts("Init global data\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 281 | gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 282 | memset((void *)gd, 0, sizeof(gd_t)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 283 | |
| 284 | /* Board data initialization */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 285 | addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 286 | |
| 287 | /* Align to 4 byte boundary */ |
Wolfgang Denk | 2bad868 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 288 | addr &= ~(4 - 1); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 289 | bd = (bd_t *) addr; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 290 | gd->bd = bd; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 291 | memset((void *)bd, 0, sizeof(bd_t)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 292 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 293 | bd->bi_r_version = version_string; |
| 294 | bd->bi_cpu = MK_STR(CONFIG_BFIN_CPU); |
| 295 | bd->bi_board_name = BFIN_BOARD_NAME; |
| 296 | bd->bi_vco = get_vco(); |
| 297 | bd->bi_cclk = get_cclk(); |
| 298 | bd->bi_sclk = get_sclk(); |
| 299 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 300 | /* Initialize */ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 301 | serial_early_puts("IRQ init\n"); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 302 | irq_init(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 303 | serial_early_puts("Environment init\n"); |
| 304 | env_init(); |
| 305 | serial_early_puts("Baudrate init\n"); |
| 306 | init_baudrate(); |
| 307 | serial_early_puts("Serial init\n"); |
| 308 | serial_init(); |
| 309 | serial_early_puts("Console init flash\n"); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 310 | console_init_f(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 311 | serial_early_puts("End of early debugging\n"); |
| 312 | display_banner(); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 313 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 314 | checkboard(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 315 | timer_init(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 316 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 317 | printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", |
| 318 | get_vco() / 1000000, get_cclk() / 1000000, get_sclk() / 1000000); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 319 | |
| 320 | printf("RAM: "); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 321 | print_size(initdram(0), "\n"); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 322 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 323 | post_init_f(); |
| 324 | post_bootmode_init(); |
| 325 | post_run(NULL, POST_ROM | post_bootmode_get(0)); |
| 326 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 327 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 328 | board_init_r((gd_t *) gd, 0x20000010); |
| 329 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 330 | |
| 331 | #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) |
| 332 | static int init_func_i2c(void) |
| 333 | { |
| 334 | puts("I2C: "); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 335 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 336 | puts("ready\n"); |
| 337 | return (0); |
| 338 | } |
| 339 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 340 | |
| 341 | void board_init_r(gd_t * id, ulong dest_addr) |
| 342 | { |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 343 | extern void malloc_bin_reloc(void); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 344 | char *s; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 345 | bd_t *bd; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 346 | gd = id; |
| 347 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 348 | bd = gd->bd; |
| 349 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 350 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 351 | post_output_backlog(); |
| 352 | post_reloc(); |
| 353 | #endif |
| 354 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 355 | #if !defined(CONFIG_SYS_NO_FLASH) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 356 | /* There are some other pointer constants we must deal with */ |
| 357 | /* configure available FLASH banks */ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 358 | extern flash_info_t flash_info[]; |
| 359 | ulong size = flash_init(); |
| 360 | puts("Flash: "); |
| 361 | print_size(size, "\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 362 | flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE, |
| 363 | CONFIG_SYS_FLASH_BASE + 0x1ffff, &flash_info[0]); |
| 364 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 365 | bd->bi_flashsize = size; |
| 366 | bd->bi_flashoffset = 0; |
| 367 | #else |
| 368 | bd->bi_flashstart = 0; |
| 369 | bd->bi_flashsize = 0; |
| 370 | bd->bi_flashoffset = 0; |
| 371 | #endif |
| 372 | /* initialize malloc() area */ |
| 373 | mem_malloc_init(); |
| 374 | malloc_bin_reloc(); |
| 375 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 376 | #ifdef CONFIG_SPI |
Jean-Christophe PLAGNIOL-VILLARD | e46af64 | 2008-09-05 09:19:30 +0200 | [diff] [blame] | 377 | # if ! defined(CONFIG_ENV_IS_IN_EEPROM) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 378 | spi_init_f(); |
| 379 | # endif |
| 380 | spi_init_r(); |
| 381 | #endif |
| 382 | |
Mike Frysinger | 392bc55 | 2008-10-06 03:55:25 -0400 | [diff] [blame] | 383 | #ifdef CONFIG_CMD_NAND |
| 384 | puts("NAND: "); |
| 385 | nand_init(); /* go init the NAND */ |
| 386 | #endif |
| 387 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 388 | /* relocate environment function pointers etc. */ |
| 389 | env_relocate(); |
| 390 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 391 | #ifdef CONFIG_CMD_NET |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 392 | /* board MAC address */ |
| 393 | s = getenv("ethaddr"); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 394 | if (s == NULL) { |
| 395 | # ifndef CONFIG_ETHADDR |
| 396 | # if 0 |
| 397 | if (!board_get_enetaddr(bd->bi_enetaddr)) { |
| 398 | char nid[20]; |
| 399 | sprintf(nid, "%02X:%02X:%02X:%02X:%02X:%02X", |
| 400 | bd->bi_enetaddr[0], bd->bi_enetaddr[1], |
| 401 | bd->bi_enetaddr[2], bd->bi_enetaddr[3], |
| 402 | bd->bi_enetaddr[4], bd->bi_enetaddr[5]); |
| 403 | setenv("ethaddr", nid); |
| 404 | } |
| 405 | # endif |
| 406 | # endif |
| 407 | } else { |
| 408 | int i; |
| 409 | char *e; |
| 410 | for (i = 0; i < 6; ++i) { |
| 411 | bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 412 | s = (*e) ? e + 1 : e; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 413 | } |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* IP Address */ |
| 417 | bd->bi_ip_addr = getenv_IPaddr("ipaddr"); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 418 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 419 | |
| 420 | /* Initialize devices */ |
| 421 | devices_init(); |
| 422 | jumptable_init(); |
| 423 | |
| 424 | /* Initialize the console (after the relocation and devices init) */ |
| 425 | console_init_r(); |
| 426 | |
| 427 | /* Initialize from environment */ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 428 | if ((s = getenv("loadaddr")) != NULL) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 429 | load_addr = simple_strtoul(s, NULL, 16); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 430 | #ifdef CONFIG_CMD_NET |
| 431 | if ((s = getenv("bootfile")) != NULL) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 432 | copy_filename(BootFile, s, sizeof(BootFile)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 433 | #endif |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 434 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 435 | #if defined(CONFIG_MISC_INIT_R) |
| 436 | /* miscellaneous platform dependent initialisations */ |
| 437 | misc_init_r(); |
| 438 | #endif |
| 439 | |
Mike Frysinger | f0dd792 | 2008-02-18 05:26:48 -0500 | [diff] [blame] | 440 | #ifdef CONFIG_CMD_NET |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 441 | printf("Net: "); |
| 442 | eth_initialize(gd->bd); |
| 443 | if (getenv("ethaddr")) |
| 444 | printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 445 | bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2], |
| 446 | bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 447 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 448 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 449 | #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 450 | init_func_i2c(); |
| 451 | #endif |
| 452 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 453 | display_global_data(); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 454 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 455 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 456 | if (post_flag) |
| 457 | post_run(NULL, POST_RAM | post_bootmode_get(0)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 458 | #endif |
| 459 | |
| 460 | /* main_loop() can return to retry autoboot, if so just run it again. */ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 461 | for (;;) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 462 | main_loop(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 463 | } |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 464 | |
| 465 | void hang(void) |
| 466 | { |
| 467 | puts("### ERROR ### Please RESET the board ###\n"); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 468 | while (1) |
| 469 | /* If a JTAG emulator is hooked up, we'll automatically trigger |
| 470 | * a breakpoint in it. If one isn't, this is just a NOP. |
| 471 | */ |
| 472 | asm("emuexcpt;"); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 473 | } |