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> |
Mike Frysinger | 53ba322 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 15 | #include <serial.h> |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 16 | #include <environment.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 17 | #include <malloc.h> |
Cliff Cai | e463892 | 2009-11-20 08:24:43 +0000 | [diff] [blame] | 18 | #include <mmc.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 19 | #include <net.h> |
Mike Frysinger | c6b978b | 2008-10-06 03:52:24 -0400 | [diff] [blame] | 20 | #include <status_led.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 21 | #include <version.h> |
| 22 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 23 | #include <asm/cplb.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 24 | #include <asm/mach-common/bits/mpu.h> |
Robin Getz | 230d001 | 2009-12-21 16:35:48 -0500 | [diff] [blame] | 25 | #include <kgdb.h> |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 26 | |
| 27 | #ifdef CONFIG_CMD_NAND |
| 28 | #include <nand.h> /* cannot even include nand.h if it isnt configured */ |
| 29 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 30 | |
Luigi 'Comio' Mantellini | 01db155 | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_BITBANGMII |
| 32 | #include <miiphy.h> |
| 33 | #endif |
| 34 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 35 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 36 | #include <post.h> |
| 37 | int post_flag; |
| 38 | #endif |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 39 | |
Wolfgang Denk | d112a2c | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 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 | 5b74f0b | 2011-06-30 18:26:39 -0400 | [diff] [blame] | 53 | display_options(); |
Mike Frysinger | 36e63df | 2010-08-09 17:39:22 -0400 | [diff] [blame] | 54 | printf("CPU: ADSP %s " |
Mike Frysinger | 7e1bbd8 | 2009-01-06 06:16:19 -0500 | [diff] [blame] | 55 | "(Detected Rev: 0.%d) " |
| 56 | "(%s boot)\n", |
Mike Frysinger | 36e63df | 2010-08-09 17:39:22 -0400 | [diff] [blame] | 57 | gd->bd->bi_cpu, |
Mike Frysinger | 7e1bbd8 | 2009-01-06 06:16:19 -0500 | [diff] [blame] | 58 | bfin_revid(), |
| 59 | get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE)); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 60 | return 0; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 63 | static int init_baudrate(void) |
| 64 | { |
Simon Glass | 3d87f6b | 2011-10-13 14:43:08 +0000 | [diff] [blame] | 65 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 66 | return 0; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 69 | static void display_global_data(void) |
| 70 | { |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 71 | bd_t *bd; |
Mike Frysinger | 188cd54 | 2010-01-19 15:39:07 -0500 | [diff] [blame] | 72 | |
| 73 | #ifndef CONFIG_DEBUG_EARLY_SERIAL |
| 74 | return; |
| 75 | #endif |
| 76 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 77 | bd = gd->bd; |
Mike Frysinger | 3429837 | 2009-08-24 19:03:18 -0400 | [diff] [blame] | 78 | printf(" gd: %p\n", gd); |
| 79 | printf(" |-flags: %lx\n", gd->flags); |
Simon Glass | bbeac16 | 2013-03-05 14:39:59 +0000 | [diff] [blame] | 80 | printf(" |-board_type: %lx\n", gd->arch.board_type); |
Simon Glass | 25c2bad | 2012-10-12 14:21:17 +0000 | [diff] [blame] | 81 | printf(" |-baudrate: %u\n", gd->baudrate); |
Mike Frysinger | 3429837 | 2009-08-24 19:03:18 -0400 | [diff] [blame] | 82 | printf(" |-have_console: %lx\n", gd->have_console); |
| 83 | printf(" |-ram_size: %lx\n", gd->ram_size); |
Mike Frysinger | 3429837 | 2009-08-24 19:03:18 -0400 | [diff] [blame] | 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_boot_params: %lx\n", bd->bi_boot_params); |
| 90 | printf(" |-bi_memstart: %lx\n", bd->bi_memstart); |
| 91 | printf(" |-bi_memsize: %lx\n", bd->bi_memsize); |
| 92 | printf(" |-bi_flashstart: %lx\n", bd->bi_flashstart); |
| 93 | printf(" |-bi_flashsize: %lx\n", bd->bi_flashsize); |
| 94 | printf(" \\-bi_flashoffset: %lx\n", bd->bi_flashoffset); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 95 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 96 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 97 | #define CPLB_PAGE_SIZE (4 * 1024 * 1024) |
| 98 | #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1)) |
Bob Liu | 49334b8 | 2011-10-25 18:07:58 +0800 | [diff] [blame] | 99 | #if defined(__ADSPBF60x__) |
| 100 | #define CPLB_EX_PAGE_SIZE (16 * 1024 * 1024) |
| 101 | #define CPLB_EX_PAGE_MASK (~(CPLB_EX_PAGE_SIZE - 1)) |
| 102 | #else |
| 103 | #define CPLB_EX_PAGE_SIZE CPLB_PAGE_SIZE |
| 104 | #define CPLB_EX_PAGE_MASK CPLB_PAGE_MASK |
| 105 | #endif |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 106 | void init_cplbtables(void) |
| 107 | { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 108 | volatile uint32_t *ICPLB_ADDR, *ICPLB_DATA; |
| 109 | volatile uint32_t *DCPLB_ADDR, *DCPLB_DATA; |
| 110 | uint32_t extern_memory; |
| 111 | size_t i; |
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 icplb_add(uint32_t addr, uint32_t data) |
| 114 | { |
| 115 | *(ICPLB_ADDR + i) = addr; |
| 116 | *(ICPLB_DATA + i) = data; |
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 | void dcplb_add(uint32_t addr, uint32_t data) |
| 119 | { |
| 120 | *(DCPLB_ADDR + i) = addr; |
| 121 | *(DCPLB_DATA + i) = data; |
| 122 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 123 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 124 | /* populate a few common entries ... we'll let |
| 125 | * the memory map and cplb exception handler do |
| 126 | * the rest of the work. |
| 127 | */ |
| 128 | i = 0; |
| 129 | ICPLB_ADDR = (uint32_t *)ICPLB_ADDR0; |
| 130 | ICPLB_DATA = (uint32_t *)ICPLB_DATA0; |
| 131 | DCPLB_ADDR = (uint32_t *)DCPLB_ADDR0; |
| 132 | DCPLB_DATA = (uint32_t *)DCPLB_DATA0; |
| 133 | |
| 134 | icplb_add(0xFFA00000, L1_IMEMORY); |
| 135 | dcplb_add(0xFF800000, L1_DMEMORY); |
| 136 | ++i; |
Bob Liu | 49334b8 | 2011-10-25 18:07:58 +0800 | [diff] [blame] | 137 | #if defined(__ADSPBF60x__) |
| 138 | icplb_add(0x0, 0x0); |
| 139 | dcplb_add(CONFIG_SYS_FLASH_BASE, SDRAM_EBIU); |
| 140 | ++i; |
| 141 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 142 | |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 143 | if (CONFIG_MEM_SIZE) { |
| 144 | uint32_t mbase = CONFIG_SYS_MONITOR_BASE; |
| 145 | uint32_t mend = mbase + CONFIG_SYS_MONITOR_LEN; |
| 146 | mbase &= CPLB_PAGE_MASK; |
| 147 | mend &= CPLB_PAGE_MASK; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 148 | |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 149 | icplb_add(mbase, SDRAM_IKERNEL); |
| 150 | dcplb_add(mbase, SDRAM_DKERNEL); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 151 | ++i; |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * If the monitor crosses a 4 meg boundary, we'll need |
| 155 | * to lock two entries for it. We assume it doesn't |
| 156 | * cross two 4 meg boundaries ... |
| 157 | */ |
| 158 | if (mbase != mend) { |
| 159 | icplb_add(mend, SDRAM_IKERNEL); |
| 160 | dcplb_add(mend, SDRAM_DKERNEL); |
| 161 | ++i; |
| 162 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 163 | } |
| 164 | |
Bob Liu | 49334b8 | 2011-10-25 18:07:58 +0800 | [diff] [blame] | 165 | #ifndef __ADSPBF60x__ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 166 | icplb_add(0x20000000, SDRAM_INON_CHBL); |
| 167 | dcplb_add(0x20000000, SDRAM_EBIU); |
| 168 | ++i; |
Bob Liu | 49334b8 | 2011-10-25 18:07:58 +0800 | [diff] [blame] | 169 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 170 | |
| 171 | /* Add entries for the rest of external RAM up to the bootrom */ |
| 172 | extern_memory = 0; |
| 173 | |
| 174 | #ifdef CONFIG_DEBUG_NULL_PTR |
| 175 | icplb_add(extern_memory, (SDRAM_IKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); |
| 176 | dcplb_add(extern_memory, (SDRAM_DKERNEL & ~PAGE_SIZE_MASK) | PAGE_SIZE_1KB); |
| 177 | ++i; |
| 178 | icplb_add(extern_memory, SDRAM_IKERNEL); |
| 179 | dcplb_add(extern_memory, SDRAM_DKERNEL); |
| 180 | extern_memory += CPLB_PAGE_SIZE; |
| 181 | ++i; |
| 182 | #endif |
| 183 | |
Bob Liu | 49334b8 | 2011-10-25 18:07:58 +0800 | [diff] [blame] | 184 | while (i < 16 && extern_memory < |
| 185 | (CONFIG_SYS_MONITOR_BASE & CPLB_EX_PAGE_MASK)) { |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 186 | icplb_add(extern_memory, SDRAM_IGENERIC); |
| 187 | dcplb_add(extern_memory, SDRAM_DGENERIC); |
Bob Liu | 49334b8 | 2011-10-25 18:07:58 +0800 | [diff] [blame] | 188 | extern_memory += CPLB_EX_PAGE_SIZE; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 189 | ++i; |
| 190 | } |
| 191 | while (i < 16) { |
| 192 | icplb_add(0, 0); |
| 193 | dcplb_add(0, 0); |
| 194 | ++i; |
| 195 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 196 | } |
| 197 | |
Mike Frysinger | a067a5e | 2012-02-29 22:48:10 -0500 | [diff] [blame] | 198 | static int global_board_data_init(void) |
| 199 | { |
| 200 | #ifndef CONFIG_SYS_GBL_DATA_ADDR |
| 201 | # define CONFIG_SYS_GBL_DATA_ADDR 0 |
| 202 | #endif |
| 203 | #ifndef CONFIG_SYS_BD_INFO_ADDR |
| 204 | # define CONFIG_SYS_BD_INFO_ADDR 0 |
| 205 | #endif |
| 206 | |
| 207 | bd_t *bd; |
| 208 | |
| 209 | if (CONFIG_SYS_GBL_DATA_ADDR) { |
| 210 | gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR); |
| 211 | memset((void *)gd, 0, GENERATED_GBL_DATA_SIZE); |
| 212 | } else { |
| 213 | static gd_t _bfin_gd; |
| 214 | gd = &_bfin_gd; |
| 215 | } |
| 216 | |
| 217 | if (CONFIG_SYS_BD_INFO_ADDR) { |
| 218 | bd = (bd_t *) (CONFIG_SYS_BD_INFO_ADDR); |
| 219 | memset(bd, 0, GENERATED_BD_INFO_SIZE); |
| 220 | } else { |
| 221 | static bd_t _bfin_bd; |
| 222 | bd = &_bfin_bd; |
| 223 | } |
| 224 | gd->bd = bd; |
| 225 | |
| 226 | bd->bi_r_version = version_string; |
Marek Vasut | 0b3176c | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 227 | bd->bi_cpu = __stringify(CONFIG_BFIN_CPU); |
Mike Frysinger | a067a5e | 2012-02-29 22:48:10 -0500 | [diff] [blame] | 228 | bd->bi_board_name = BFIN_BOARD_NAME; |
| 229 | bd->bi_vco = get_vco(); |
| 230 | bd->bi_cclk = get_cclk(); |
| 231 | bd->bi_sclk = get_sclk(); |
| 232 | bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; |
| 233 | bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 238 | /* |
| 239 | * All attempts to come up with a "common" initialization sequence |
| 240 | * that works for all boards and architectures failed: some of the |
| 241 | * requirements are just _too_ different. To get rid of the resulting |
| 242 | * mess of board dependend #ifdef'ed code we now make the whole |
| 243 | * initialization sequence configurable to the user. |
| 244 | * |
| 245 | * The requirements for any new initalization function is simple: it |
| 246 | * receives a pointer to the "global data" structure as it's only |
| 247 | * argument, and returns an integer return code, where 0 means |
| 248 | * "continue" and != 0 means "fatal error, hang the system". |
| 249 | */ |
| 250 | |
Mike Frysinger | 851b817 | 2010-02-11 20:19:10 -0500 | [diff] [blame] | 251 | extern int watchdog_init(void); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 252 | extern int exception_init(void); |
| 253 | extern int irq_init(void); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 254 | extern int timer_init(void); |
| 255 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 256 | void board_init_f(ulong bootflag) |
| 257 | { |
Mike Frysinger | a267207 | 2008-10-20 16:15:04 -0400 | [diff] [blame] | 258 | char buf[32]; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 259 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 260 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 261 | serial_early_puts("Board early init flash\n"); |
| 262 | board_early_init_f(); |
| 263 | #endif |
| 264 | |
| 265 | serial_early_puts("Init CPLB tables\n"); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 266 | init_cplbtables(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 267 | |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 268 | serial_early_puts("Exceptions setup\n"); |
| 269 | exception_init(); |
| 270 | |
| 271 | #ifndef CONFIG_ICACHE_OFF |
| 272 | serial_early_puts("Turn on ICACHE\n"); |
| 273 | icache_enable(); |
| 274 | #endif |
| 275 | #ifndef CONFIG_DCACHE_OFF |
| 276 | serial_early_puts("Turn on DCACHE\n"); |
| 277 | dcache_enable(); |
| 278 | #endif |
| 279 | |
Mike Frysinger | 851b817 | 2010-02-11 20:19:10 -0500 | [diff] [blame] | 280 | #ifdef CONFIG_WATCHDOG |
| 281 | serial_early_puts("Setting up external watchdog\n"); |
| 282 | watchdog_init(); |
| 283 | #endif |
| 284 | |
Mike Frysinger | f93f030 | 2008-10-06 03:57:39 -0400 | [diff] [blame] | 285 | #ifdef DEBUG |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 286 | if (GENERATED_GBL_DATA_SIZE < sizeof(*gd)) |
Mike Frysinger | f93f030 | 2008-10-06 03:57:39 -0400 | [diff] [blame] | 287 | hang(); |
| 288 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 289 | serial_early_puts("Init global data\n"); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 290 | |
Mike Frysinger | a067a5e | 2012-02-29 22:48:10 -0500 | [diff] [blame] | 291 | global_board_data_init(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 292 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 293 | /* Initialize */ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 294 | serial_early_puts("IRQ init\n"); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 295 | irq_init(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 296 | serial_early_puts("Environment init\n"); |
| 297 | env_init(); |
| 298 | serial_early_puts("Baudrate init\n"); |
| 299 | init_baudrate(); |
| 300 | serial_early_puts("Serial init\n"); |
| 301 | serial_init(); |
Mike Frysinger | 53ba322 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 302 | serial_initialize(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 303 | serial_early_puts("Console init flash\n"); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 304 | console_init_f(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 305 | serial_early_puts("End of early debugging\n"); |
| 306 | display_banner(); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 307 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 308 | checkboard(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 309 | timer_init(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 310 | |
Mike Frysinger | a267207 | 2008-10-20 16:15:04 -0400 | [diff] [blame] | 311 | printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco())); |
| 312 | printf("Core: %s MHz, ", strmhz(buf, get_cclk())); |
Sonic Zhang | a99f03e | 2012-08-16 11:56:14 +0800 | [diff] [blame] | 313 | #if defined(__ADSPBF60x__) |
| 314 | printf("System0: %s MHz, ", strmhz(buf, get_sclk0())); |
| 315 | printf("System1: %s MHz, ", strmhz(buf, get_sclk1())); |
| 316 | printf("Dclk: %s MHz\n", strmhz(buf, get_dclk())); |
| 317 | #else |
Mike Frysinger | a267207 | 2008-10-20 16:15:04 -0400 | [diff] [blame] | 318 | printf("System: %s MHz\n", strmhz(buf, get_sclk())); |
Sonic Zhang | a99f03e | 2012-08-16 11:56:14 +0800 | [diff] [blame] | 319 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 320 | |
Mike Frysinger | 20ea997 | 2010-12-20 05:18:55 -0500 | [diff] [blame] | 321 | if (CONFIG_MEM_SIZE) { |
| 322 | printf("RAM: "); |
Mike Frysinger | a067a5e | 2012-02-29 22:48:10 -0500 | [diff] [blame] | 323 | print_size(gd->bd->bi_memsize, "\n"); |
Mike Frysinger | 20ea997 | 2010-12-20 05:18:55 -0500 | [diff] [blame] | 324 | } |
| 325 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 326 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 327 | post_init_f(); |
| 328 | post_bootmode_init(); |
| 329 | post_run(NULL, POST_ROM | post_bootmode_get(0)); |
| 330 | #endif |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 331 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 332 | board_init_r((gd_t *) gd, 0x20000010); |
| 333 | } |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 334 | |
Mike Frysinger | e434b9f | 2009-02-22 16:02:27 -0500 | [diff] [blame] | 335 | static void board_net_init_r(bd_t *bd) |
| 336 | { |
Luigi 'Comio' Mantellini | 01db155 | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 337 | #ifdef CONFIG_BITBANGMII |
| 338 | bb_miiphy_init(); |
| 339 | #endif |
Mike Frysinger | e434b9f | 2009-02-22 16:02:27 -0500 | [diff] [blame] | 340 | #ifdef CONFIG_CMD_NET |
Mike Frysinger | e434b9f | 2009-02-22 16:02:27 -0500 | [diff] [blame] | 341 | printf("Net: "); |
Mike Frysinger | 36fe7db | 2012-04-04 18:53:41 +0000 | [diff] [blame] | 342 | eth_initialize(bd); |
Mike Frysinger | e434b9f | 2009-02-22 16:02:27 -0500 | [diff] [blame] | 343 | #endif |
| 344 | } |
| 345 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 346 | void board_init_r(gd_t * id, ulong dest_addr) |
| 347 | { |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 348 | bd_t *bd; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 349 | gd = id; |
| 350 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 351 | bd = gd->bd; |
| 352 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 353 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 354 | post_output_backlog(); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 355 | #endif |
| 356 | |
Stefan Roese | b81464e | 2009-05-11 15:50:12 +0200 | [diff] [blame] | 357 | /* initialize malloc() area */ |
Peter Tyser | ed52770 | 2009-08-21 23:05:20 -0500 | [diff] [blame] | 358 | mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN); |
Stefan Roese | b81464e | 2009-05-11 15:50:12 +0200 | [diff] [blame] | 359 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 360 | #if !defined(CONFIG_SYS_NO_FLASH) |
Mike Frysinger | 0dc765f | 2008-10-06 04:00:07 -0400 | [diff] [blame] | 361 | /* Initialize the flash and protect u-boot by default */ |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 362 | extern flash_info_t flash_info[]; |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 363 | puts("Flash: "); |
Mike Frysinger | d1c68c1 | 2008-10-06 04:01:26 -0400 | [diff] [blame] | 364 | ulong size = flash_init(); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 365 | print_size(size, "\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 366 | flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE, |
Mike Frysinger | 0dc765f | 2008-10-06 04:00:07 -0400 | [diff] [blame] | 367 | CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1, |
| 368 | &flash_info[0]); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 369 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 370 | bd->bi_flashsize = size; |
| 371 | bd->bi_flashoffset = 0; |
| 372 | #else |
| 373 | bd->bi_flashstart = 0; |
| 374 | bd->bi_flashsize = 0; |
| 375 | bd->bi_flashoffset = 0; |
| 376 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 377 | |
Mike Frysinger | 392bc55 | 2008-10-06 03:55:25 -0400 | [diff] [blame] | 378 | #ifdef CONFIG_CMD_NAND |
| 379 | puts("NAND: "); |
| 380 | nand_init(); /* go init the NAND */ |
| 381 | #endif |
| 382 | |
Cliff Cai | e463892 | 2009-11-20 08:24:43 +0000 | [diff] [blame] | 383 | #ifdef CONFIG_GENERIC_MMC |
Mike Frysinger | d9548e3 | 2010-09-29 14:46:42 -0400 | [diff] [blame] | 384 | puts("MMC: "); |
Cliff Cai | e463892 | 2009-11-20 08:24:43 +0000 | [diff] [blame] | 385 | mmc_initialize(bd); |
| 386 | #endif |
| 387 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 388 | /* relocate environment function pointers etc. */ |
| 389 | env_relocate(); |
| 390 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 391 | /* Initialize stdio devices */ |
| 392 | stdio_init(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 393 | jumptable_init(); |
| 394 | |
| 395 | /* Initialize the console (after the relocation and devices init) */ |
| 396 | console_init_r(); |
| 397 | |
Robin Getz | 230d001 | 2009-12-21 16:35:48 -0500 | [diff] [blame] | 398 | #ifdef CONFIG_CMD_KGDB |
| 399 | puts("KGDB: "); |
| 400 | kgdb_init(); |
| 401 | #endif |
| 402 | |
Mike Frysinger | c6b978b | 2008-10-06 03:52:24 -0400 | [diff] [blame] | 403 | #ifdef CONFIG_STATUS_LED |
| 404 | status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); |
| 405 | status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF); |
| 406 | #endif |
| 407 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 408 | /* Initialize from environment */ |
Simon Glass | 3d87f6b | 2011-10-13 14:43:08 +0000 | [diff] [blame] | 409 | load_addr = getenv_ulong("loadaddr", 16, load_addr); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 410 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 411 | #if defined(CONFIG_MISC_INIT_R) |
| 412 | /* miscellaneous platform dependent initialisations */ |
| 413 | misc_init_r(); |
| 414 | #endif |
| 415 | |
Mike Frysinger | e434b9f | 2009-02-22 16:02:27 -0500 | [diff] [blame] | 416 | board_net_init_r(bd); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 417 | |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 418 | display_global_data(); |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 419 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 420 | #if defined(CONFIG_POST) |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 421 | if (post_flag) |
| 422 | post_run(NULL, POST_RAM | post_bootmode_get(0)); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 423 | #endif |
| 424 | |
Mike Frysinger | 7edbbfa | 2010-12-24 13:19:25 -0500 | [diff] [blame] | 425 | if (CONFIG_MEM_SIZE && bfin_os_log_check()) { |
Mike Frysinger | 0897589 | 2009-07-09 01:15:05 -0400 | [diff] [blame] | 426 | puts("\nLog buffer from operating system:\n"); |
| 427 | bfin_os_log_dump(); |
| 428 | puts("\n"); |
| 429 | } |
| 430 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 431 | /* 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] | 432 | for (;;) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 433 | main_loop(); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 434 | } |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 435 | |
| 436 | void hang(void) |
| 437 | { |
Mike Frysinger | c6b978b | 2008-10-06 03:52:24 -0400 | [diff] [blame] | 438 | #ifdef CONFIG_STATUS_LED |
| 439 | status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); |
| 440 | status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING); |
| 441 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 442 | puts("### ERROR ### Please RESET the board ###\n"); |
Mike Frysinger | 6a67532 | 2008-02-19 00:54:20 -0500 | [diff] [blame] | 443 | while (1) |
| 444 | /* If a JTAG emulator is hooked up, we'll automatically trigger |
| 445 | * a breakpoint in it. If one isn't, this is just a NOP. |
| 446 | */ |
| 447 | asm("emuexcpt;"); |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 448 | } |