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