board.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (C) 2007, 2008, 2010
  3. * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <command.h>
  22. #include <malloc.h>
  23. #include <stdio_dev.h>
  24. #include <version.h>
  25. #include <watchdog.h>
  26. #include <net.h>
  27. #include <environment.h>
  28. #ifdef CONFIG_BITBANGMII
  29. #include <miiphy.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. extern int cpu_init(void);
  33. extern int board_init(void);
  34. extern int dram_init(void);
  35. extern int timer_init(void);
  36. unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
  37. #ifndef CONFIG_SYS_NO_FLASH
  38. static int sh_flash_init(void)
  39. {
  40. gd->bd->bi_flashsize = flash_init();
  41. if (gd->bd->bi_flashsize >= (1024 * 1024))
  42. printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
  43. else
  44. printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
  45. return 0;
  46. }
  47. #endif /* CONFIG_SYS_NO_FLASH */
  48. #if defined(CONFIG_CMD_NAND)
  49. # include <nand.h>
  50. # define INIT_FUNC_NAND_INIT nand_init,
  51. #else
  52. # define INIT_FUNC_NAND_INIT
  53. #endif /* CONFIG_CMD_NAND */
  54. #if defined(CONFIG_WATCHDOG)
  55. extern int watchdog_init(void);
  56. extern int watchdog_disable(void);
  57. # define INIT_FUNC_WATCHDOG_INIT watchdog_init,
  58. # define WATCHDOG_DISABLE watchdog_disable
  59. #else
  60. # define INIT_FUNC_WATCHDOG_INIT
  61. # define WATCHDOG_DISABLE
  62. #endif /* CONFIG_WATCHDOG */
  63. #if defined(CONFIG_CMD_IDE)
  64. # include <ide.h>
  65. # define INIT_FUNC_IDE_INIT ide_init,
  66. #else
  67. # define INIT_FUNC_IDE_INIT
  68. #endif /* CONFIG_CMD_IDE */
  69. #if defined(CONFIG_PCI)
  70. #include <pci.h>
  71. static int sh_pci_init(void)
  72. {
  73. pci_init();
  74. return 0;
  75. }
  76. # define INIT_FUNC_PCI_INIT sh_pci_init,
  77. #else
  78. # define INIT_FUNC_PCI_INIT
  79. #endif /* CONFIG_PCI */
  80. static int sh_mem_env_init(void)
  81. {
  82. mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
  83. CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
  84. env_relocate();
  85. jumptable_init();
  86. return 0;
  87. }
  88. #if defined(CONFIG_CMD_NET)
  89. static int sh_net_init(void)
  90. {
  91. gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  92. return 0;
  93. }
  94. #endif
  95. #if defined(CONFIG_CMD_MMC)
  96. static int sh_mmc_init(void)
  97. {
  98. puts("MMC: ");
  99. mmc_initialize(gd->bd);
  100. return 0;
  101. }
  102. #endif
  103. typedef int (init_fnc_t) (void);
  104. init_fnc_t *init_sequence[] =
  105. {
  106. cpu_init, /* basic cpu dependent setup */
  107. board_init, /* basic board dependent setup */
  108. interrupt_init, /* set up exceptions */
  109. env_init, /* event init */
  110. serial_init, /* SCIF init */
  111. INIT_FUNC_WATCHDOG_INIT /* watchdog init */
  112. console_init_f,
  113. display_options,
  114. checkcpu,
  115. checkboard, /* Check support board */
  116. dram_init, /* SDRAM init */
  117. timer_init, /* SuperH Timer (TCNT0 only) init */
  118. sh_mem_env_init,
  119. #ifndef CONFIG_SYS_NO_FLASH
  120. sh_flash_init, /* Flash memory init*/
  121. #endif
  122. INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
  123. INIT_FUNC_PCI_INIT /* PCI init */
  124. stdio_init,
  125. console_init_r,
  126. interrupt_init,
  127. #ifdef CONFIG_BOARD_LATE_INIT
  128. board_late_init,
  129. #endif
  130. #if defined(CONFIG_CMD_NET)
  131. sh_net_init, /* SH specific eth init */
  132. #endif
  133. #if defined(CONFIG_CMD_MMC)
  134. sh_mmc_init,
  135. #endif
  136. NULL /* Terminate this list */
  137. };
  138. void sh_generic_init(void)
  139. {
  140. bd_t *bd;
  141. init_fnc_t **init_fnc_ptr;
  142. memset(gd, 0, GENERATED_GBL_DATA_SIZE);
  143. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  144. gd->bd = (bd_t *)(gd + 1); /* At end of global data */
  145. gd->baudrate = CONFIG_BAUDRATE;
  146. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  147. bd = gd->bd;
  148. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  149. bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
  150. #ifndef CONFIG_SYS_NO_FLASH
  151. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  152. #endif
  153. #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
  154. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
  155. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
  156. #endif
  157. bd->bi_baudrate = CONFIG_BAUDRATE;
  158. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  159. WATCHDOG_RESET();
  160. if ((*init_fnc_ptr) () != 0)
  161. hang();
  162. }
  163. #ifdef CONFIG_WATCHDOG
  164. /* disable watchdog if environment is set */
  165. {
  166. char *s = getenv("watchdog");
  167. if (s != NULL)
  168. if (strncmp(s, "off", 3) == 0)
  169. WATCHDOG_DISABLE();
  170. }
  171. #endif /* CONFIG_WATCHDOG*/
  172. #ifdef CONFIG_BITBANGMII
  173. bb_miiphy_init();
  174. #endif
  175. #if defined(CONFIG_CMD_NET)
  176. {
  177. char *s;
  178. puts("Net: ");
  179. eth_initialize(gd->bd);
  180. s = getenv("bootfile");
  181. if (s != NULL)
  182. copy_filename(BootFile, s, sizeof(BootFile));
  183. }
  184. #endif /* CONFIG_CMD_NET */
  185. while (1) {
  186. WATCHDOG_RESET();
  187. main_loop();
  188. }
  189. }
  190. /***********************************************************************/
  191. void hang(void)
  192. {
  193. puts("Board ERROR\n");
  194. for (;;)
  195. ;
  196. }