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