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