board.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2007, 2008, 2010
  3. * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <malloc.h>
  10. #include <stdio_dev.h>
  11. #include <version.h>
  12. #include <watchdog.h>
  13. #include <net.h>
  14. #include <mmc.h>
  15. #include <environment.h>
  16. #ifdef CONFIG_BITBANGMII
  17. #include <miiphy.h>
  18. #endif
  19. DECLARE_GLOBAL_DATA_PTR;
  20. extern int cpu_init(void);
  21. extern int board_init(void);
  22. extern int dram_init(void);
  23. extern int timer_init(void);
  24. unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
  25. #ifndef CONFIG_SYS_NO_FLASH
  26. static int sh_flash_init(void)
  27. {
  28. gd->bd->bi_flashsize = flash_init();
  29. if (gd->bd->bi_flashsize >= (1024 * 1024))
  30. printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
  31. else
  32. printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
  33. return 0;
  34. }
  35. #endif /* CONFIG_SYS_NO_FLASH */
  36. #if defined(CONFIG_CMD_NAND)
  37. # include <nand.h>
  38. # define INIT_FUNC_NAND_INIT nand_init,
  39. #else
  40. # define INIT_FUNC_NAND_INIT
  41. #endif /* CONFIG_CMD_NAND */
  42. #if defined(CONFIG_WATCHDOG)
  43. extern int watchdog_init(void);
  44. extern int watchdog_disable(void);
  45. # undef INIT_FUNC_WATCHDOG_INIT
  46. # define INIT_FUNC_WATCHDOG_INIT watchdog_init,
  47. # define WATCHDOG_DISABLE watchdog_disable
  48. #else
  49. # define INIT_FUNC_WATCHDOG_INIT
  50. # define WATCHDOG_DISABLE
  51. #endif /* CONFIG_WATCHDOG */
  52. #if defined(CONFIG_CMD_IDE)
  53. # include <ide.h>
  54. # define INIT_FUNC_IDE_INIT ide_init,
  55. #else
  56. # define INIT_FUNC_IDE_INIT
  57. #endif /* CONFIG_CMD_IDE */
  58. #if defined(CONFIG_PCI)
  59. #include <pci.h>
  60. static int sh_pci_init(void)
  61. {
  62. pci_init();
  63. return 0;
  64. }
  65. # define INIT_FUNC_PCI_INIT sh_pci_init,
  66. #else
  67. # define INIT_FUNC_PCI_INIT
  68. #endif /* CONFIG_PCI */
  69. static int sh_mem_env_init(void)
  70. {
  71. mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
  72. CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
  73. env_relocate();
  74. jumptable_init();
  75. return 0;
  76. }
  77. #if defined(CONFIG_CMD_MMC)
  78. static int sh_mmc_init(void)
  79. {
  80. puts("MMC: ");
  81. mmc_initialize(gd->bd);
  82. return 0;
  83. }
  84. #endif
  85. typedef int (init_fnc_t) (void);
  86. init_fnc_t *init_sequence[] =
  87. {
  88. cpu_init, /* basic cpu dependent setup */
  89. board_init, /* basic board dependent setup */
  90. interrupt_init, /* set up exceptions */
  91. env_init, /* event init */
  92. serial_init, /* SCIF init */
  93. INIT_FUNC_WATCHDOG_INIT /* watchdog init */
  94. console_init_f,
  95. display_options,
  96. checkcpu,
  97. checkboard, /* Check support board */
  98. dram_init, /* SDRAM init */
  99. timer_init, /* SuperH Timer (TCNT0 only) init */
  100. sh_mem_env_init,
  101. #ifndef CONFIG_SYS_NO_FLASH
  102. sh_flash_init, /* Flash memory init*/
  103. #endif
  104. INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
  105. INIT_FUNC_PCI_INIT /* PCI init */
  106. stdio_init,
  107. console_init_r,
  108. interrupt_init,
  109. #ifdef CONFIG_BOARD_LATE_INIT
  110. board_late_init,
  111. #endif
  112. #if defined(CONFIG_CMD_MMC)
  113. sh_mmc_init,
  114. #endif
  115. NULL /* Terminate this list */
  116. };
  117. void sh_generic_init(void)
  118. {
  119. bd_t *bd;
  120. init_fnc_t **init_fnc_ptr;
  121. memset(gd, 0, GENERATED_GBL_DATA_SIZE);
  122. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  123. gd->bd = (bd_t *)(gd + 1); /* At end of global data */
  124. gd->baudrate = CONFIG_BAUDRATE;
  125. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  126. bd = gd->bd;
  127. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  128. bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
  129. #ifndef CONFIG_SYS_NO_FLASH
  130. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  131. #endif
  132. #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
  133. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
  134. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
  135. #endif
  136. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  137. WATCHDOG_RESET();
  138. if ((*init_fnc_ptr) () != 0)
  139. hang();
  140. }
  141. #ifdef CONFIG_WATCHDOG
  142. /* disable watchdog if environment is set */
  143. {
  144. char *s = getenv("watchdog");
  145. if (s != NULL)
  146. if (strncmp(s, "off", 3) == 0)
  147. WATCHDOG_DISABLE();
  148. }
  149. #endif /* CONFIG_WATCHDOG*/
  150. #ifdef CONFIG_BITBANGMII
  151. bb_miiphy_init();
  152. #endif
  153. #if defined(CONFIG_CMD_NET)
  154. puts("Net: ");
  155. eth_initialize(gd->bd);
  156. #endif /* CONFIG_CMD_NET */
  157. while (1) {
  158. WATCHDOG_RESET();
  159. main_loop();
  160. }
  161. }