board.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (C) 2007,2008
  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 <timestamp.h>
  25. #include <version.h>
  26. #include <watchdog.h>
  27. #include <net.h>
  28. #include <environment.h>
  29. #ifdef CONFIG_BITBANGMII
  30. #include <miiphy.h>
  31. #endif
  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. const char version_string[] = U_BOOT_VERSION" ("U_BOOT_DATE" - "U_BOOT_TIME")";
  37. unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
  38. static int sh_flash_init(void)
  39. {
  40. DECLARE_GLOBAL_DATA_PTR;
  41. gd->bd->bi_flashsize = flash_init();
  42. printf("FLASH: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
  43. return 0;
  44. }
  45. #if defined(CONFIG_CMD_NAND)
  46. # include <nand.h>
  47. # define INIT_FUNC_NAND_INIT nand_init,
  48. #else
  49. # define INIT_FUNC_NAND_INIT
  50. #endif /* CONFIG_CMD_NAND */
  51. #if defined(CONFIG_WATCHDOG)
  52. extern int watchdog_init(void);
  53. extern int watchdog_disable(void);
  54. # define INIT_FUNC_WATCHDOG_INIT watchdog_init,
  55. # define WATCHDOG_DISABLE watchdog_disable
  56. #else
  57. # define INIT_FUNC_WATCHDOG_INIT
  58. # define WATCHDOG_DISABLE
  59. #endif /* CONFIG_WATCHDOG */
  60. #if defined(CONFIG_CMD_IDE)
  61. # include <ide.h>
  62. # define INIT_FUNC_IDE_INIT ide_init,
  63. #else
  64. # define INIT_FUNC_IDE_INIT
  65. #endif /* CONFIG_CMD_IDE */
  66. #if defined(CONFIG_PCI)
  67. #include <pci.h>
  68. static int sh_pci_init(void)
  69. {
  70. pci_init();
  71. return 0;
  72. }
  73. # define INIT_FUNC_PCI_INIT sh_pci_init,
  74. #else
  75. # define INIT_FUNC_PCI_INIT
  76. #endif /* CONFIG_PCI */
  77. static int sh_mem_env_init(void)
  78. {
  79. mem_malloc_init(CONFIG_SYS_TEXT_BASE - CONFIG_SYS_GBL_DATA_SIZE -
  80. CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
  81. env_relocate();
  82. jumptable_init();
  83. return 0;
  84. }
  85. #if defined(CONFIG_CMD_NET)
  86. static int sh_net_init(void)
  87. {
  88. DECLARE_GLOBAL_DATA_PTR;
  89. gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  90. return 0;
  91. }
  92. #endif
  93. typedef int (init_fnc_t) (void);
  94. init_fnc_t *init_sequence[] =
  95. {
  96. cpu_init, /* basic cpu dependent setup */
  97. board_init, /* basic board dependent setup */
  98. interrupt_init, /* set up exceptions */
  99. env_init, /* event init */
  100. serial_init, /* SCIF init */
  101. INIT_FUNC_WATCHDOG_INIT /* watchdog init */
  102. console_init_f,
  103. display_options,
  104. checkcpu,
  105. checkboard, /* Check support board */
  106. dram_init, /* SDRAM init */
  107. timer_init, /* SuperH Timer (TCNT0 only) init */
  108. sh_mem_env_init,
  109. sh_flash_init, /* Flash memory(NOR) init*/
  110. INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
  111. INIT_FUNC_PCI_INIT /* PCI init */
  112. stdio_init,
  113. console_init_r,
  114. interrupt_init,
  115. #ifdef BOARD_LATE_INIT
  116. board_late_init,
  117. #endif
  118. #if defined(CONFIG_CMD_NET)
  119. sh_net_init, /* SH specific eth init */
  120. #endif
  121. NULL /* Terminate this list */
  122. };
  123. void sh_generic_init(void)
  124. {
  125. DECLARE_GLOBAL_DATA_PTR;
  126. bd_t *bd;
  127. init_fnc_t **init_fnc_ptr;
  128. memset(gd, 0, CONFIG_SYS_GBL_DATA_SIZE);
  129. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  130. gd->bd = (bd_t *)(gd + 1); /* At end of global data */
  131. gd->baudrate = CONFIG_BAUDRATE;
  132. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  133. bd = gd->bd;
  134. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  135. bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
  136. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  137. #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
  138. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
  139. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
  140. #endif
  141. bd->bi_baudrate = CONFIG_BAUDRATE;
  142. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  143. WATCHDOG_RESET();
  144. if ((*init_fnc_ptr) () != 0)
  145. hang();
  146. }
  147. #ifdef CONFIG_WATCHDOG
  148. /* disable watchdog if environment is set */
  149. {
  150. char *s = getenv("watchdog");
  151. if (s != NULL)
  152. if (strncmp(s, "off", 3) == 0)
  153. WATCHDOG_DISABLE();
  154. }
  155. #endif /* CONFIG_WATCHDOG*/
  156. #ifdef CONFIG_BITBANGMII
  157. bb_miiphy_init();
  158. #endif
  159. #if defined(CONFIG_CMD_NET)
  160. {
  161. char *s;
  162. puts("Net: ");
  163. eth_initialize(gd->bd);
  164. s = getenv("bootfile");
  165. if (s != NULL)
  166. copy_filename(BootFile, s, sizeof(BootFile));
  167. }
  168. #endif /* CONFIG_CMD_NET */
  169. while (1) {
  170. WATCHDOG_RESET();
  171. main_loop();
  172. }
  173. }
  174. /***********************************************************************/
  175. void hang(void)
  176. {
  177. puts("Board ERROR\n");
  178. for (;;)
  179. ;
  180. }