board.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 <net.h>
  26. #include <environment.h>
  27. extern void malloc_bin_reloc (void);
  28. extern int cpu_init(void);
  29. extern int board_init(void);
  30. extern int dram_init(void);
  31. extern int watchdog_init(void);
  32. extern int timer_init(void);
  33. const char version_string[] = U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
  34. unsigned long monitor_flash_len = CFG_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 - CFG_GBL_DATA_SIZE - CFG_MALLOC_LEN);
  41. mem_malloc_end = (mem_malloc_start + CFG_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: %dMB\n", gd->bd->bi_flashsize / (1024*1024));
  62. return 0;
  63. }
  64. #if defined(CONFIG_CMD_NAND)
  65. #include <nand.h>
  66. static int sh_nand_init(void)
  67. {
  68. printf("NAND: ");
  69. nand_init(); /* go init the NAND */
  70. return 0;
  71. }
  72. #endif /* CONFIG_CMD_NAND */
  73. #if defined(CONFIG_CMD_IDE)
  74. #include <ide.h>
  75. static int sh_marubun_init(void)
  76. {
  77. puts ("IDE: ");
  78. ide_init();
  79. return 0;
  80. }
  81. #endif /* (CONFIG_CMD_IDE) */
  82. #if defined(CONFIG_PCI)
  83. static int sh_pci_init(void)
  84. {
  85. pci_init();
  86. return 0;
  87. }
  88. #endif /* CONFIG_PCI */
  89. static int sh_mem_env_init(void)
  90. {
  91. mem_malloc_init();
  92. malloc_bin_reloc();
  93. env_relocate();
  94. jumptable_init();
  95. return 0;
  96. }
  97. #if defined(CONFIG_CMD_NET)
  98. static int sh_net_init(void)
  99. {
  100. DECLARE_GLOBAL_DATA_PTR;
  101. char *s, *e;
  102. int i;
  103. gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  104. s = getenv("ethaddr");
  105. for (i = 0; i < 6; ++i) {
  106. gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
  107. if (s) s = (*e) ? e + 1 : e;
  108. }
  109. return 0;
  110. }
  111. #endif
  112. typedef int (init_fnc_t) (void);
  113. init_fnc_t *init_sequence[] =
  114. {
  115. cpu_init, /* basic cpu dependent setup */
  116. board_init, /* basic board dependent setup */
  117. interrupt_init, /* set up exceptions */
  118. env_init, /* event init */
  119. serial_init, /* SCIF init */
  120. watchdog_init, /* watchdog init */
  121. console_init_f,
  122. display_options,
  123. checkcpu,
  124. checkboard, /* Check support board */
  125. dram_init, /* SDRAM init */
  126. timer_init, /* SuperH Timer (TCNT0 only) init */
  127. sh_flash_init, /* Flash memory(NOR) init*/
  128. sh_mem_env_init,
  129. #if defined(CONFIG_CMD_NAND)
  130. sh_nand_init, /* Flash memory (NAND) init */
  131. #endif
  132. #if defined(CONFIG_PCI)
  133. sh_pci_init, /* PCI Init */
  134. #endif
  135. devices_init,
  136. console_init_r,
  137. interrupt_init,
  138. #ifdef BOARD_LATE_INIT
  139. board_late_init,
  140. #endif
  141. #if defined(CONFIG_CMD_NET)
  142. sh_net_init, /* SH specific eth init */
  143. #endif
  144. NULL /* Terminate this list */
  145. };
  146. void sh_generic_init (void)
  147. {
  148. DECLARE_GLOBAL_DATA_PTR;
  149. bd_t *bd;
  150. init_fnc_t **init_fnc_ptr;
  151. int i;
  152. char *s;
  153. memset (gd, 0, CFG_GBL_DATA_SIZE);
  154. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  155. gd->bd = (bd_t *) (gd + 1); /* At end of global data */
  156. gd->baudrate = CONFIG_BAUDRATE;
  157. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  158. bd = gd->bd;
  159. bd->bi_memstart = CFG_SDRAM_BASE;
  160. bd->bi_memsize = CFG_SDRAM_SIZE;
  161. bd->bi_flashstart = CFG_FLASH_BASE;
  162. #if defined(CFG_SRAM_BASE) && defined(CFG_SRAM_SIZE)
  163. bd->bi_sramstart= CFG_SRAM_BASE;
  164. bd->bi_sramsize = CFG_SRAM_SIZE;
  165. #endif
  166. bd->bi_baudrate = CONFIG_BAUDRATE;
  167. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr , i++) {
  168. if ((*init_fnc_ptr) () != 0) {
  169. hang();
  170. }
  171. }
  172. #if defined(CONFIG_CMD_NET)
  173. puts ("Net: ");
  174. eth_initialize(gd->bd);
  175. if ((s = getenv ("bootfile")) != NULL) {
  176. copy_filename (BootFile, s, sizeof (BootFile));
  177. }
  178. #endif /* CONFIG_CMD_NET */
  179. while (1) {
  180. main_loop();
  181. }
  182. }
  183. /***********************************************************************/
  184. void hang (void)
  185. {
  186. puts ("Board ERROR\n");
  187. for (;;);
  188. }