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