board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * (C) Copyright 2011
  3. * Julius Baxter, julius@opencores.org
  4. *
  5. * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
  6. * Scott McNutt <smcnutt@psyent.com>
  7. *
  8. * (C) Copyright 2000-2002
  9. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  10. *
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <stdio_dev.h>
  16. #include <watchdog.h>
  17. #include <malloc.h>
  18. #include <mmc.h>
  19. #include <net.h>
  20. #ifdef CONFIG_STATUS_LED
  21. #include <status_led.h>
  22. #endif
  23. #ifdef CONFIG_CMD_NAND
  24. #include <nand.h> /* cannot even include nand.h if it isnt configured */
  25. #endif
  26. #include <timestamp.h>
  27. #include <version.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. /*
  30. * All attempts to come up with a "common" initialization sequence
  31. * that works for all boards and architectures failed: some of the
  32. * requirements are just _too_ different. To get rid of the resulting
  33. * mess of board dependend #ifdef'ed code we now make the whole
  34. * initialization sequence configurable to the user.
  35. *
  36. * The requirements for any new initalization function is simple: it
  37. * receives a pointer to the "global data" structure as it's only
  38. * argument, and returns an integer return code, where 0 means
  39. * "continue" and != 0 means "fatal error, hang the system".
  40. */
  41. extern int cache_init(void);
  42. /*
  43. * Initialization sequence
  44. */
  45. static int (* const init_sequence[])(void) = {
  46. cache_init,
  47. timer_init, /* initialize timer */
  48. env_init,
  49. serial_init,
  50. console_init_f,
  51. display_options,
  52. checkcpu,
  53. checkboard,
  54. };
  55. /***********************************************************************/
  56. void board_init(void)
  57. {
  58. bd_t *bd;
  59. int i;
  60. gd = (gd_t *)CONFIG_SYS_GBL_DATA_ADDR;
  61. memset((void *)gd, 0, GENERATED_GBL_DATA_SIZE);
  62. gd->bd = (bd_t *)(gd+1); /* At end of global data */
  63. gd->baudrate = CONFIG_BAUDRATE;
  64. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  65. bd = gd->bd;
  66. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  67. bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
  68. #ifndef CONFIG_SYS_NO_FLASH
  69. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  70. #endif
  71. #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
  72. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
  73. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
  74. #endif
  75. for (i = 0; i < ARRAY_SIZE(init_sequence); i++) {
  76. WATCHDOG_RESET();
  77. if (init_sequence[i]())
  78. hang();
  79. }
  80. WATCHDOG_RESET();
  81. /* The Malloc area is immediately below the monitor copy in RAM */
  82. mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
  83. #ifndef CONFIG_SYS_NO_FLASH
  84. WATCHDOG_RESET();
  85. bd->bi_flashsize = flash_init();
  86. #endif
  87. #ifdef CONFIG_CMD_NAND
  88. puts("NAND: ");
  89. nand_init();
  90. #endif
  91. #ifdef CONFIG_GENERIC_MMC
  92. puts("MMC: ");
  93. mmc_initialize(bd);
  94. #endif
  95. WATCHDOG_RESET();
  96. env_relocate();
  97. WATCHDOG_RESET();
  98. stdio_init();
  99. jumptable_init();
  100. console_init_r();
  101. WATCHDOG_RESET();
  102. interrupt_init();
  103. #if defined(CONFIG_BOARD_LATE_INIT)
  104. board_late_init();
  105. #endif
  106. #if defined(CONFIG_CMD_NET)
  107. puts("NET: ");
  108. eth_initialize(bd);
  109. #endif
  110. /* main_loop */
  111. for (;;) {
  112. WATCHDOG_RESET();
  113. main_loop();
  114. }
  115. }