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