board.c 5.5 KB

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