board.c 5.4 KB

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