board.c 4.8 KB

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