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