board.c 3.0 KB

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