Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
| 3 | * (C) Copyright 2002-2006 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 8 | * Marius Groeger <mgroeger@sysgo.de> |
| 9 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 14 | /* TODO: can we just include all these headers whether needed or not? */ |
| 15 | #if defined(CONFIG_CMD_BEDBUG) |
| 16 | #include <bedbug/type.h> |
| 17 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 18 | #ifdef CONFIG_HAS_DATAFLASH |
| 19 | #include <dataflash.h> |
| 20 | #endif |
| 21 | #include <environment.h> |
| 22 | #include <fdtdec.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 23 | #if defined(CONFIG_CMD_IDE) |
| 24 | #include <ide.h> |
| 25 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 26 | #include <initcall.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 27 | #ifdef CONFIG_PS2KBD |
| 28 | #include <keyboard.h> |
| 29 | #endif |
| 30 | #if defined(CONFIG_CMD_KGDB) |
| 31 | #include <kgdb.h> |
| 32 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 33 | #include <logbuff.h> |
| 34 | #include <malloc.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_BITBANGMII |
| 36 | #include <miiphy.h> |
| 37 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 38 | #include <mmc.h> |
| 39 | #include <nand.h> |
| 40 | #include <onenand_uboot.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 41 | #include <scsi.h> |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 42 | #include <serial.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 43 | #include <spi.h> |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 44 | #include <stdio_dev.h> |
Simon Glass | 209a1a6 | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 45 | #include <trace.h> |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 46 | #include <watchdog.h> |
| 47 | #ifdef CONFIG_ADDR_MAP |
| 48 | #include <asm/mmu.h> |
| 49 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 50 | #include <asm/sections.h> |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 51 | #ifdef CONFIG_X86 |
| 52 | #include <asm/init_helpers.h> |
| 53 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 54 | #include <linux/compiler.h> |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 55 | |
| 56 | DECLARE_GLOBAL_DATA_PTR; |
| 57 | |
| 58 | ulong monitor_flash_len; |
| 59 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 60 | int __board_flash_wp_on(void) |
| 61 | { |
| 62 | /* |
| 63 | * Most flashes can't be detected when write protection is enabled, |
| 64 | * so provide a way to let U-Boot gracefully ignore write protected |
| 65 | * devices. |
| 66 | */ |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int board_flash_wp_on(void) |
| 71 | __attribute__ ((weak, alias("__board_flash_wp_on"))); |
| 72 | |
| 73 | void __cpu_secondary_init_r(void) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void cpu_secondary_init_r(void) |
| 78 | __attribute__ ((weak, alias("__cpu_secondary_init_r"))); |
| 79 | |
| 80 | static int initr_secondary_cpu(void) |
| 81 | { |
| 82 | /* |
| 83 | * after non-volatile devices & environment is setup and cpu code have |
| 84 | * another round to deal with any initialization that might require |
| 85 | * full access to the environment or loading of some image (firmware) |
| 86 | * from a non-volatile device |
| 87 | */ |
| 88 | /* TODO: maybe define this for all archs? */ |
| 89 | cpu_secondary_init_r(); |
| 90 | |
| 91 | return 0; |
| 92 | } |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 93 | |
Simon Glass | 209a1a6 | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 94 | static int initr_trace(void) |
| 95 | { |
| 96 | #ifdef CONFIG_TRACE |
| 97 | trace_init(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE); |
| 98 | #endif |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 103 | static int initr_reloc(void) |
| 104 | { |
| 105 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 106 | bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r"); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | #ifdef CONFIG_ARM |
| 112 | /* |
| 113 | * Some of these functions are needed purely because the functions they |
| 114 | * call return void. If we change them to return 0, these stubs can go away. |
| 115 | */ |
| 116 | static int initr_caches(void) |
| 117 | { |
| 118 | /* Enable caches */ |
| 119 | enable_caches(); |
| 120 | return 0; |
| 121 | } |
| 122 | #endif |
| 123 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 124 | __weak int fixup_cpu(void) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 129 | static int initr_reloc_global_data(void) |
| 130 | { |
| 131 | #ifdef CONFIG_SYS_SYM_OFFSETS |
| 132 | monitor_flash_len = _end_ofs; |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 133 | #elif !defined(CONFIG_SANDBOX) |
Masahiro Yamada | d158924 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 134 | monitor_flash_len = (ulong)&__init_end - gd->relocaddr; |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 135 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 136 | #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) |
| 137 | /* |
| 138 | * The gd->cpu pointer is set to an address in flash before relocation. |
| 139 | * We need to update it to point to the same CPU entry in RAM. |
| 140 | * TODO: why not just add gd->reloc_ofs? |
| 141 | */ |
Masahiro Yamada | d158924 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 142 | gd->arch.cpu += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * If we didn't know the cpu mask & # cores, we can save them of |
| 146 | * now rather than 'computing' them constantly |
| 147 | */ |
| 148 | fixup_cpu(); |
| 149 | #endif |
| 150 | #ifdef CONFIG_SYS_EXTRA_ENV_RELOC |
| 151 | /* |
| 152 | * Some systems need to relocate the env_addr pointer early because the |
| 153 | * location it points to will get invalidated before env_relocate is |
| 154 | * called. One example is on systems that might use a L2 or L3 cache |
| 155 | * in SRAM mode and initialize that cache from SRAM mode back to being |
| 156 | * a cache in cpu_init_r. |
| 157 | */ |
Masahiro Yamada | d158924 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 158 | gd->env_addr += gd->relocaddr - CONFIG_SYS_MONITOR_BASE; |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 159 | #endif |
| 160 | return 0; |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static int initr_serial(void) |
| 164 | { |
| 165 | serial_initialize(); |
| 166 | return 0; |
| 167 | } |
| 168 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 169 | #ifdef CONFIG_PPC |
| 170 | static int initr_trap(void) |
| 171 | { |
| 172 | /* |
| 173 | * Setup trap handlers |
| 174 | */ |
Masahiro Yamada | d158924 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 175 | trap_init(gd->relocaddr); |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | #endif |
| 180 | |
| 181 | #ifdef CONFIG_ADDR_MAP |
| 182 | static int initr_addr_map(void) |
| 183 | { |
| 184 | init_addr_map(); |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | #endif |
| 189 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 190 | #ifdef CONFIG_LOGBUFFER |
| 191 | unsigned long logbuffer_base(void) |
| 192 | { |
| 193 | return gd->ram_top - LOGBUFF_LEN; |
| 194 | } |
| 195 | |
| 196 | static int initr_logbuffer(void) |
| 197 | { |
| 198 | logbuff_init_ptrs(); |
| 199 | return 0; |
| 200 | } |
| 201 | #endif |
| 202 | |
| 203 | #ifdef CONFIG_POST |
| 204 | static int initr_post_backlog(void) |
| 205 | { |
| 206 | post_output_backlog(); |
| 207 | return 0; |
| 208 | } |
| 209 | #endif |
| 210 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 211 | #ifdef CONFIG_SYS_DELAYED_ICACHE |
| 212 | static int initr_icache_enable(void) |
| 213 | { |
| 214 | return 0; |
| 215 | } |
| 216 | #endif |
| 217 | |
| 218 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) |
| 219 | static int initr_unlock_ram_in_cache(void) |
| 220 | { |
| 221 | unlock_ram_in_cache(); /* it's time to unlock D-cache in e500 */ |
| 222 | return 0; |
| 223 | } |
| 224 | #endif |
| 225 | |
| 226 | #ifdef CONFIG_PCI |
| 227 | static int initr_pci(void) |
| 228 | { |
| 229 | pci_init(); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | #endif |
| 234 | |
| 235 | #ifdef CONFIG_WINBOND_83C553 |
| 236 | static int initr_w83c553f(void) |
| 237 | { |
| 238 | /* |
| 239 | * Initialise the ISA bridge |
| 240 | */ |
| 241 | initialise_w83c553f(); |
| 242 | return 0; |
| 243 | } |
| 244 | #endif |
| 245 | |
| 246 | static int initr_barrier(void) |
| 247 | { |
| 248 | #ifdef CONFIG_PPC |
| 249 | /* TODO: Can we not use dmb() macros for this? */ |
| 250 | asm("sync ; isync"); |
| 251 | #endif |
| 252 | return 0; |
| 253 | } |
| 254 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 255 | static int initr_malloc(void) |
| 256 | { |
| 257 | ulong malloc_start; |
| 258 | |
| 259 | /* The malloc area is immediately below the monitor copy in DRAM */ |
Masahiro Yamada | d158924 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 260 | malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN; |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 261 | mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN), |
| 262 | TOTAL_MALLOC_LEN); |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | __weak int power_init_board(void) |
| 267 | { |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int initr_announce(void) |
| 272 | { |
Masahiro Yamada | d158924 | 2013-05-27 00:37:30 +0000 | [diff] [blame] | 273 | debug("Now running in RAM - U-Boot at: %08lx\n", gd->relocaddr); |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | #if !defined(CONFIG_SYS_NO_FLASH) |
| 278 | static int initr_flash(void) |
| 279 | { |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 280 | ulong flash_size = 0; |
| 281 | bd_t *bd = gd->bd; |
| 282 | int ok; |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 283 | |
| 284 | puts("Flash: "); |
| 285 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 286 | if (board_flash_wp_on()) { |
| 287 | printf("Uninitialized - Write Protect On\n"); |
| 288 | /* Since WP is on, we can't find real size. Set to 0 */ |
| 289 | ok = 1; |
| 290 | } else { |
| 291 | flash_size = flash_init(); |
| 292 | ok = flash_size > 0; |
| 293 | } |
| 294 | if (!ok) { |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 295 | puts("*** failed ***\n"); |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 296 | #ifdef CONFIG_PPC |
| 297 | /* Why does PPC do this? */ |
| 298 | hang(); |
| 299 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 300 | return -1; |
| 301 | } |
| 302 | print_size(flash_size, ""); |
| 303 | #ifdef CONFIG_SYS_FLASH_CHECKSUM |
| 304 | /* |
| 305 | * Compute and print flash CRC if flashchecksum is set to 'y' |
| 306 | * |
| 307 | * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX |
| 308 | */ |
| 309 | if (getenv_yesno("flashchecksum") == 1) { |
| 310 | printf(" CRC: %08X", crc32(0, |
| 311 | (const unsigned char *) CONFIG_SYS_FLASH_BASE, |
| 312 | flash_size)); |
| 313 | } |
| 314 | #endif /* CONFIG_SYS_FLASH_CHECKSUM */ |
| 315 | putc('\n'); |
| 316 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 317 | /* update start of FLASH memory */ |
| 318 | #ifdef CONFIG_SYS_FLASH_BASE |
| 319 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
| 320 | #endif |
| 321 | /* size of FLASH memory (final value) */ |
| 322 | bd->bi_flashsize = flash_size; |
| 323 | |
| 324 | #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE) |
| 325 | /* Make a update of the Memctrl. */ |
| 326 | update_flash_size(flash_size); |
| 327 | #endif |
| 328 | |
| 329 | |
| 330 | #if defined(CONFIG_OXC) || defined(CONFIG_RMU) |
| 331 | /* flash mapped at end of memory map */ |
| 332 | bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size; |
| 333 | #elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE |
| 334 | bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */ |
| 335 | #endif |
| 336 | return 0; |
| 337 | } |
| 338 | #endif |
| 339 | |
| 340 | #ifdef CONFIG_PPC |
| 341 | static int initr_spi(void) |
| 342 | { |
| 343 | /* PPC does this here */ |
| 344 | #ifdef CONFIG_SPI |
| 345 | #if !defined(CONFIG_ENV_IS_IN_EEPROM) |
| 346 | spi_init_f(); |
| 347 | #endif |
| 348 | spi_init_r(); |
| 349 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | #endif |
| 353 | |
| 354 | #ifdef CONFIG_CMD_NAND |
| 355 | /* go init the NAND */ |
| 356 | int initr_nand(void) |
| 357 | { |
| 358 | puts("NAND: "); |
| 359 | nand_init(); |
| 360 | return 0; |
| 361 | } |
| 362 | #endif |
| 363 | |
| 364 | #if defined(CONFIG_CMD_ONENAND) |
| 365 | /* go init the NAND */ |
| 366 | int initr_onenand(void) |
| 367 | { |
| 368 | puts("NAND: "); |
| 369 | onenand_init(); |
| 370 | return 0; |
| 371 | } |
| 372 | #endif |
| 373 | |
| 374 | #ifdef CONFIG_GENERIC_MMC |
| 375 | int initr_mmc(void) |
| 376 | { |
| 377 | puts("MMC: "); |
| 378 | mmc_initialize(gd->bd); |
| 379 | return 0; |
| 380 | } |
| 381 | #endif |
| 382 | |
| 383 | #ifdef CONFIG_HAS_DATAFLASH |
| 384 | int initr_dataflash(void) |
| 385 | { |
| 386 | AT91F_DataflashInit(); |
| 387 | dataflash_print_info(); |
| 388 | return 0; |
| 389 | } |
| 390 | #endif |
| 391 | |
| 392 | /* |
| 393 | * Tell if it's OK to load the environment early in boot. |
| 394 | * |
| 395 | * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see |
| 396 | * if this is OK (defaulting to saying it's OK). |
| 397 | * |
| 398 | * NOTE: Loading the environment early can be a bad idea if security is |
| 399 | * important, since no verification is done on the environment. |
| 400 | * |
| 401 | * @return 0 if environment should not be loaded, !=0 if it is ok to load |
| 402 | */ |
| 403 | static int should_load_env(void) |
| 404 | { |
| 405 | #ifdef CONFIG_OF_CONTROL |
| 406 | return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1); |
| 407 | #elif defined CONFIG_DELAY_ENVIRONMENT |
| 408 | return 0; |
| 409 | #else |
| 410 | return 1; |
| 411 | #endif |
| 412 | } |
| 413 | |
| 414 | static int initr_env(void) |
| 415 | { |
| 416 | /* initialize environment */ |
| 417 | if (should_load_env()) |
| 418 | env_relocate(); |
| 419 | else |
| 420 | set_default_env(NULL); |
| 421 | |
| 422 | /* Initialize from environment */ |
| 423 | load_addr = getenv_ulong("loadaddr", 16, load_addr); |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 424 | #if defined(CONFIG_SYS_EXTBDINFO) |
| 425 | #if defined(CONFIG_405GP) || defined(CONFIG_405EP) |
| 426 | #if defined(CONFIG_I2CFAST) |
| 427 | /* |
| 428 | * set bi_iic_fast for linux taking environment variable |
| 429 | * "i2cfast" into account |
| 430 | */ |
| 431 | { |
| 432 | char *s = getenv("i2cfast"); |
| 433 | |
| 434 | if (s && ((*s == 'y') || (*s == 'Y'))) { |
| 435 | gd->bd->bi_iic_fast[0] = 1; |
| 436 | gd->bd->bi_iic_fast[1] = 1; |
| 437 | } |
| 438 | } |
| 439 | #endif /* CONFIG_I2CFAST */ |
| 440 | #endif /* CONFIG_405GP, CONFIG_405EP */ |
| 441 | #endif /* CONFIG_SYS_EXTBDINFO */ |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | #ifdef CONFIG_HERMES |
| 446 | static int initr_hermes(void) |
| 447 | { |
| 448 | if ((gd->board_type >> 16) == 2) |
| 449 | gd->bd->bi_ethspeed = gd->board_type & 0xFFFF; |
| 450 | else |
| 451 | gd->bd->bi_ethspeed = 0xFFFF; |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int initr_hermes_start(void) |
| 456 | { |
| 457 | if (gd->bd->bi_ethspeed != 0xFFFF) |
| 458 | hermes_start_lxt980((int) gd->bd->bi_ethspeed); |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 459 | return 0; |
| 460 | } |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 461 | #endif |
| 462 | |
| 463 | #ifdef CONFIG_SC3 |
| 464 | /* TODO: with new initcalls, move this into the driver */ |
| 465 | extern void sc3_read_eeprom(void); |
| 466 | |
| 467 | static int initr_sc3_read_eeprom(void) |
| 468 | { |
| 469 | sc3_read_eeprom(); |
| 470 | return 0; |
| 471 | } |
| 472 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 473 | |
| 474 | static int initr_jumptable(void) |
| 475 | { |
| 476 | jumptable_init(); |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | #if defined(CONFIG_API) |
| 481 | static int initr_api(void) |
| 482 | { |
| 483 | /* Initialize API */ |
| 484 | api_init(); |
| 485 | return 0; |
| 486 | } |
| 487 | #endif |
| 488 | |
| 489 | #ifdef CONFIG_DISPLAY_BOARDINFO_LATE |
| 490 | static int show_model_r(void) |
| 491 | { |
| 492 | /* Put this here so it appears on the LCD, now it is ready */ |
| 493 | # ifdef CONFIG_OF_CONTROL |
| 494 | const char *model; |
| 495 | |
| 496 | model = (char *)fdt_getprop(gd->fdt_blob, 0, "model", NULL); |
| 497 | printf("Model: %s\n", model ? model : "<unknown>"); |
| 498 | # else |
| 499 | checkboard(); |
| 500 | # endif |
| 501 | } |
| 502 | #endif |
| 503 | |
| 504 | /* enable exceptions */ |
Simon Glass | 2e4622d | 2013-03-11 07:40:13 +0000 | [diff] [blame] | 505 | #ifdef CONFIG_ARM |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 506 | static int initr_enable_interrupts(void) |
| 507 | { |
| 508 | enable_interrupts(); |
| 509 | return 0; |
| 510 | } |
Simon Glass | 2e4622d | 2013-03-11 07:40:13 +0000 | [diff] [blame] | 511 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 512 | |
| 513 | #ifdef CONFIG_CMD_NET |
| 514 | static int initr_ethaddr(void) |
| 515 | { |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 516 | bd_t *bd = gd->bd; |
| 517 | |
| 518 | /* kept around for legacy kernels only ... ignore the next section */ |
| 519 | eth_getenv_enetaddr("ethaddr", bd->bi_enetaddr); |
| 520 | #ifdef CONFIG_HAS_ETH1 |
| 521 | eth_getenv_enetaddr("eth1addr", bd->bi_enet1addr); |
| 522 | #endif |
| 523 | #ifdef CONFIG_HAS_ETH2 |
| 524 | eth_getenv_enetaddr("eth2addr", bd->bi_enet2addr); |
| 525 | #endif |
| 526 | #ifdef CONFIG_HAS_ETH3 |
| 527 | eth_getenv_enetaddr("eth3addr", bd->bi_enet3addr); |
| 528 | #endif |
| 529 | #ifdef CONFIG_HAS_ETH4 |
| 530 | eth_getenv_enetaddr("eth4addr", bd->bi_enet4addr); |
| 531 | #endif |
| 532 | #ifdef CONFIG_HAS_ETH5 |
| 533 | eth_getenv_enetaddr("eth5addr", bd->bi_enet5addr); |
| 534 | #endif |
| 535 | return 0; |
| 536 | } |
| 537 | #endif /* CONFIG_CMD_NET */ |
| 538 | |
| 539 | #ifdef CONFIG_CMD_KGDB |
| 540 | static int initr_kgdb(void) |
| 541 | { |
| 542 | puts("KGDB: "); |
| 543 | kgdb_init(); |
| 544 | return 0; |
| 545 | } |
| 546 | #endif |
| 547 | |
| 548 | #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT) |
| 549 | static int initr_status_led(void) |
| 550 | { |
| 551 | status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); |
| 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | #endif |
| 556 | |
| 557 | #if defined(CONFIG_CMD_SCSI) |
| 558 | static int initr_scsi(void) |
| 559 | { |
| 560 | /* Not supported properly on ARM yet */ |
| 561 | #ifndef CONFIG_ARM |
| 562 | puts("SCSI: "); |
| 563 | scsi_init(); |
| 564 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | #endif /* CONFIG_CMD_NET */ |
| 569 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 570 | #if defined(CONFIG_CMD_DOC) |
| 571 | static int initr_doc(void) |
| 572 | { |
| 573 | puts("DOC: "); |
| 574 | doc_init(); |
| 575 | } |
| 576 | #endif |
| 577 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 578 | #ifdef CONFIG_BITBANGMII |
| 579 | static int initr_bbmii(void) |
| 580 | { |
| 581 | bb_miiphy_init(); |
| 582 | return 0; |
| 583 | } |
| 584 | #endif |
| 585 | |
| 586 | #ifdef CONFIG_CMD_NET |
| 587 | static int initr_net(void) |
| 588 | { |
| 589 | puts("Net: "); |
| 590 | eth_initialize(gd->bd); |
| 591 | #if defined(CONFIG_RESET_PHY_R) |
| 592 | debug("Reset Ethernet PHY\n"); |
| 593 | reset_phy(); |
| 594 | #endif |
| 595 | return 0; |
| 596 | } |
| 597 | #endif |
| 598 | |
| 599 | #ifdef CONFIG_POST |
| 600 | static int initr_post(void) |
| 601 | { |
| 602 | post_run(NULL, POST_RAM | post_bootmode_get(0)); |
| 603 | return 0; |
| 604 | } |
| 605 | #endif |
| 606 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 607 | #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE) |
| 608 | static int initr_pcmcia(void) |
| 609 | { |
| 610 | puts("PCMCIA:"); |
| 611 | pcmcia_init(); |
| 612 | return 0; |
| 613 | } |
| 614 | #endif |
| 615 | |
| 616 | #if defined(CONFIG_CMD_IDE) |
| 617 | static int initr_ide(void) |
| 618 | { |
| 619 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 620 | puts("PCMCIA:"); |
| 621 | #else |
| 622 | puts("IDE: "); |
| 623 | #endif |
| 624 | #if defined(CONFIG_START_IDE) |
| 625 | if (board_start_ide()) |
| 626 | ide_init(); |
| 627 | #else |
| 628 | ide_init(); |
| 629 | #endif |
| 630 | return 0; |
| 631 | } |
| 632 | #endif |
| 633 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 634 | #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) |
| 635 | /* |
| 636 | * Export available size of memory for Linux, taking into account the |
| 637 | * protected RAM at top of memory |
| 638 | */ |
| 639 | int initr_mem(void) |
| 640 | { |
| 641 | ulong pram = 0; |
| 642 | char memsz[32]; |
| 643 | |
| 644 | # ifdef CONFIG_PRAM |
| 645 | pram = getenv_ulong("pram", 10, CONFIG_PRAM); |
| 646 | # endif |
| 647 | # if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR) |
| 648 | /* Also take the logbuffer into account (pram is in kB) */ |
| 649 | pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024; |
| 650 | # endif |
| 651 | sprintf(memsz, "%ldk", (gd->ram_size / 1024) - pram); |
| 652 | setenv("mem", memsz); |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 653 | |
| 654 | return 0; |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 655 | } |
| 656 | #endif |
| 657 | |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 658 | #ifdef CONFIG_CMD_BEDBUG |
| 659 | static int initr_bedbug(void) |
| 660 | { |
| 661 | bedbug_init(); |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | #endif |
| 666 | |
| 667 | #ifdef CONFIG_PS2KBD |
| 668 | static int initr_kbd(void) |
| 669 | { |
| 670 | puts("PS/2: "); |
| 671 | kbd_init(); |
| 672 | return 0; |
| 673 | } |
| 674 | #endif |
| 675 | |
| 676 | #ifdef CONFIG_MODEM_SUPPORT |
| 677 | static int initr_modem(void) |
| 678 | { |
| 679 | /* TODO: with new initcalls, move this into the driver */ |
| 680 | extern int do_mdm_init; |
| 681 | |
| 682 | do_mdm_init = gd->do_mdm_init; |
| 683 | return 0; |
| 684 | } |
| 685 | #endif |
| 686 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 687 | static int run_main_loop(void) |
| 688 | { |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 689 | #ifdef CONFIG_SANDBOX |
| 690 | sandbox_main_loop_init(); |
| 691 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 692 | /* main_loop() can return to retry autoboot, if so just run it again */ |
| 693 | for (;;) |
| 694 | main_loop(); |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * Over time we hope to remove these functions with code fragments and |
| 700 | * stub funtcions, and instead call the relevant function directly. |
| 701 | * |
| 702 | * We also hope to remove most of the driver-related init and do it if/when |
| 703 | * the driver is later used. |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 704 | * |
| 705 | * TODO: perhaps reset the watchdog in the initcall function after each call? |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 706 | */ |
| 707 | init_fnc_t init_sequence_r[] = { |
Simon Glass | 209a1a6 | 2013-06-11 11:14:42 -0700 | [diff] [blame] | 708 | initr_trace, |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 709 | initr_reloc, |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 710 | /* TODO: could x86/PPC have this also perhaps? */ |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 711 | #ifdef CONFIG_ARM |
| 712 | initr_caches, |
| 713 | board_init, /* Setup chipselects */ |
| 714 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 715 | /* |
| 716 | * TODO: printing of the clock inforamtion of the board is now |
| 717 | * implemented as part of bdinfo command. Currently only support for |
| 718 | * davinci SOC's is added. Remove this check once all the board |
| 719 | * implement this. |
| 720 | */ |
| 721 | #ifdef CONFIG_CLOCKS |
| 722 | set_cpu_clk_info, /* Setup clock information */ |
| 723 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 724 | initr_reloc_global_data, |
| 725 | initr_serial, |
| 726 | initr_announce, |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 727 | INIT_FUNC_WATCHDOG_RESET |
| 728 | #ifdef CONFIG_PPC |
| 729 | initr_trap, |
| 730 | #endif |
| 731 | #ifdef CONFIG_ADDR_MAP |
| 732 | initr_addr_map, |
| 733 | #endif |
| 734 | #if defined(CONFIG_BOARD_EARLY_INIT_R) |
| 735 | board_early_init_r, |
| 736 | #endif |
| 737 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 738 | #ifdef CONFIG_LOGBUFFER |
| 739 | initr_logbuffer, |
| 740 | #endif |
| 741 | #ifdef CONFIG_POST |
| 742 | initr_post_backlog, |
| 743 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 744 | INIT_FUNC_WATCHDOG_RESET |
| 745 | #ifdef CONFIG_SYS_DELAYED_ICACHE |
| 746 | initr_icache_enable, |
| 747 | #endif |
| 748 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) |
| 749 | initr_unlock_ram_in_cache, |
| 750 | #endif |
| 751 | #if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT) |
| 752 | /* |
| 753 | * Do early PCI configuration _before_ the flash gets initialised, |
| 754 | * because PCU ressources are crucial for flash access on some boards. |
| 755 | */ |
| 756 | initr_pci, |
| 757 | #endif |
| 758 | #ifdef CONFIG_WINBOND_83C553 |
| 759 | initr_w83c553f, |
| 760 | #endif |
| 761 | initr_barrier, |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 762 | initr_malloc, |
Doug Anderson | 844199d | 2013-04-17 16:13:42 +0000 | [diff] [blame] | 763 | bootstage_relocate, |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 764 | #ifdef CONFIG_ARCH_EARLY_INIT_R |
| 765 | arch_early_init_r, |
| 766 | #endif |
| 767 | power_init_board, |
| 768 | #ifndef CONFIG_SYS_NO_FLASH |
| 769 | initr_flash, |
| 770 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 771 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 772 | #if defined(CONFIG_PPC) || defined(CONFIG_X86) |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 773 | /* initialize higher level parts of CPU like time base and timers */ |
| 774 | cpu_init_r, |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 775 | #endif |
| 776 | #ifdef CONFIG_PPC |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 777 | initr_spi, |
| 778 | #endif |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 779 | #if defined(CONFIG_X86) && defined(CONFIG_SPI) |
| 780 | init_func_spi, |
| 781 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 782 | #ifdef CONFIG_CMD_NAND |
| 783 | initr_nand, |
| 784 | #endif |
| 785 | #ifdef CONFIG_CMD_ONENAND |
| 786 | initr_onenand, |
| 787 | #endif |
| 788 | #ifdef CONFIG_GENERIC_MMC |
| 789 | initr_mmc, |
| 790 | #endif |
| 791 | #ifdef CONFIG_HAS_DATAFLASH |
| 792 | initr_dataflash, |
| 793 | #endif |
| 794 | initr_env, |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 795 | INIT_FUNC_WATCHDOG_RESET |
| 796 | initr_secondary_cpu, |
| 797 | #ifdef CONFIG_SC3 |
| 798 | initr_sc3_read_eeprom, |
| 799 | #endif |
| 800 | #ifdef CONFIG_HERMES |
| 801 | initr_hermes, |
| 802 | #endif |
| 803 | #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET) |
| 804 | mac_read_from_eeprom, |
| 805 | #endif |
| 806 | INIT_FUNC_WATCHDOG_RESET |
| 807 | #if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT) |
| 808 | /* |
| 809 | * Do pci configuration |
| 810 | */ |
| 811 | initr_pci, |
| 812 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 813 | stdio_init, |
| 814 | initr_jumptable, |
| 815 | #ifdef CONFIG_API |
| 816 | initr_api, |
| 817 | #endif |
| 818 | console_init_r, /* fully init console as a device */ |
| 819 | #ifdef CONFIG_DISPLAY_BOARDINFO_LATE |
| 820 | show_model_r, |
| 821 | #endif |
| 822 | #ifdef CONFIG_ARCH_MISC_INIT |
| 823 | arch_misc_init, /* miscellaneous arch-dependent init */ |
| 824 | #endif |
| 825 | #ifdef CONFIG_MISC_INIT_R |
| 826 | misc_init_r, /* miscellaneous platform-dependent init */ |
| 827 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 828 | #ifdef CONFIG_HERMES |
| 829 | initr_hermes_start, |
| 830 | #endif |
| 831 | INIT_FUNC_WATCHDOG_RESET |
| 832 | #ifdef CONFIG_CMD_KGDB |
| 833 | initr_kgdb, |
| 834 | #endif |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 835 | #ifdef CONFIG_X86 |
| 836 | board_early_init_r, |
| 837 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 838 | interrupt_init, |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 839 | #if defined(CONFIG_ARM) || defined(CONFIG_x86) |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 840 | initr_enable_interrupts, |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 841 | #endif |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 842 | #ifdef CONFIG_X86 |
| 843 | timer_init, /* initialize timer */ |
| 844 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 845 | #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT) |
| 846 | initr_status_led, |
| 847 | #endif |
| 848 | /* PPC has a udelay(20) here dating from 2002. Why? */ |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 849 | #ifdef CONFIG_CMD_NET |
| 850 | initr_ethaddr, |
| 851 | #endif |
| 852 | #ifdef CONFIG_BOARD_LATE_INIT |
| 853 | board_late_init, |
| 854 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 855 | #ifdef CONFIG_CMD_SCSI |
| 856 | INIT_FUNC_WATCHDOG_RESET |
| 857 | initr_scsi, |
| 858 | #endif |
| 859 | #ifdef CONFIG_CMD_DOC |
| 860 | INIT_FUNC_WATCHDOG_RESET |
| 861 | initr_doc, |
| 862 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 863 | #ifdef CONFIG_BITBANGMII |
| 864 | initr_bbmii, |
| 865 | #endif |
| 866 | #ifdef CONFIG_CMD_NET |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 867 | INIT_FUNC_WATCHDOG_RESET |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 868 | initr_net, |
| 869 | #endif |
| 870 | #ifdef CONFIG_POST |
| 871 | initr_post, |
| 872 | #endif |
Simon Glass | 5af29bd | 2013-03-14 07:20:12 +0000 | [diff] [blame] | 873 | #if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE) |
| 874 | initr_pcmcia, |
| 875 | #endif |
| 876 | #if defined(CONFIG_CMD_IDE) |
| 877 | initr_ide, |
| 878 | #endif |
| 879 | #ifdef CONFIG_LAST_STAGE_INIT |
| 880 | INIT_FUNC_WATCHDOG_RESET |
| 881 | /* |
| 882 | * Some parts can be only initialized if all others (like |
| 883 | * Interrupts) are up and running (i.e. the PC-style ISA |
| 884 | * keyboard). |
| 885 | */ |
| 886 | last_stage_init, |
| 887 | #endif |
| 888 | #ifdef CONFIG_CMD_BEDBUG |
| 889 | INIT_FUNC_WATCHDOG_RESET |
| 890 | initr_bedbug, |
| 891 | #endif |
| 892 | #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER) |
| 893 | initr_mem, |
| 894 | #endif |
| 895 | #ifdef CONFIG_PS2KBD |
| 896 | initr_kbd, |
| 897 | #endif |
| 898 | #ifdef CONFIG_MODEM_SUPPORT |
| 899 | initr_modem, |
| 900 | #endif |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 901 | run_main_loop, |
| 902 | }; |
| 903 | |
| 904 | void board_init_r(gd_t *new_gd, ulong dest_addr) |
| 905 | { |
Alexey Brodkin | 3f0516f | 2014-01-20 14:30:39 +0400 | [diff] [blame] | 906 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 907 | int i; |
| 908 | #endif |
| 909 | |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 910 | #ifndef CONFIG_X86 |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 911 | gd = new_gd; |
Simon Glass | 6f5567d | 2013-03-05 14:39:53 +0000 | [diff] [blame] | 912 | #endif |
Alexey Brodkin | 3f0516f | 2014-01-20 14:30:39 +0400 | [diff] [blame] | 913 | |
| 914 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 915 | for (i = 0; i < ARRAY_SIZE(init_sequence_r); i++) |
| 916 | init_sequence_r[i] += gd->reloc_off; |
| 917 | #endif |
| 918 | |
Simon Glass | db397fa | 2013-03-11 14:30:37 +0000 | [diff] [blame] | 919 | if (initcall_run_list(init_sequence_r)) |
| 920 | hang(); |
| 921 | |
| 922 | /* NOTREACHED - run_main_loop() does not return */ |
| 923 | hang(); |
| 924 | } |