board.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. *
  4. * (C) Copyright 2002-2006
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * (C) Copyright 2002
  8. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  9. * Marius Groeger <mgroeger@sysgo.de>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. /*
  30. * This file was taken from ARM and changed to remove things we don't
  31. * need. This is most of it, so have tried to avoid being over-zealous!
  32. * For example, we want to have an emulation of the 'DRAM' used by
  33. * U-Boot.
  34. *
  35. * has been talk upstream of unifying the architectures w.r.t board.c,
  36. * so the less change here the better.
  37. */
  38. #include <common.h>
  39. #include <command.h>
  40. #include <malloc.h>
  41. #include <stdio_dev.h>
  42. #include <timestamp.h>
  43. #include <version.h>
  44. #include <serial.h>
  45. DECLARE_GLOBAL_DATA_PTR;
  46. /************************************************************************
  47. * Init Utilities *
  48. ************************************************************************
  49. * Some of this code should be moved into the core functions,
  50. * or dropped completely,
  51. * but let's get it working (again) first...
  52. */
  53. static int display_banner(void)
  54. {
  55. display_options();
  56. return 0;
  57. }
  58. /**
  59. * Configure and report on the DRAM configuration, which in our case is
  60. * fairly simple.
  61. */
  62. static int display_dram_config(void)
  63. {
  64. ulong size = 0;
  65. int i;
  66. debug("RAM Configuration:\n");
  67. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  68. #ifdef DEBUG
  69. printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  70. print_size(gd->bd->bi_dram[i].size, "\n");
  71. #endif
  72. size += gd->bd->bi_dram[i].size;
  73. }
  74. puts("DRAM: ");
  75. print_size(size, "\n");
  76. return 0;
  77. }
  78. /*
  79. * Breathe some life into the board...
  80. *
  81. * Initialize a serial port as console, and carry out some hardware
  82. * tests.
  83. *
  84. * The first part of initialization is running from Flash memory;
  85. * its main purpose is to initialize the RAM so that we
  86. * can relocate the monitor code to RAM.
  87. */
  88. /*
  89. * All attempts to come up with a "common" initialization sequence
  90. * that works for all boards and architectures failed: some of the
  91. * requirements are just _too_ different. To get rid of the resulting
  92. * mess of board dependent #ifdef'ed code we now make the whole
  93. * initialization sequence configurable to the user.
  94. *
  95. * The requirements for any new initalization function is simple: it
  96. * receives a pointer to the "global data" structure as it's only
  97. * argument, and returns an integer return code, where 0 means
  98. * "continue" and != 0 means "fatal error, hang the system".
  99. */
  100. typedef int (init_fnc_t) (void);
  101. void __dram_init_banksize(void)
  102. {
  103. gd->bd->bi_dram[0].start = 0;
  104. gd->bd->bi_dram[0].size = gd->ram_size;
  105. }
  106. void dram_init_banksize(void)
  107. __attribute__((weak, alias("__dram_init_banksize")));
  108. init_fnc_t *init_sequence[] = {
  109. #if defined(CONFIG_ARCH_CPU_INIT)
  110. arch_cpu_init, /* basic arch cpu dependent setup */
  111. #endif
  112. #if defined(CONFIG_BOARD_EARLY_INIT_F)
  113. board_early_init_f,
  114. #endif
  115. timer_init, /* initialize timer */
  116. env_init, /* initialize environment */
  117. serial_init, /* serial communications setup */
  118. console_init_f, /* stage 1 init of console */
  119. display_banner, /* say that we are here */
  120. #if defined(CONFIG_DISPLAY_CPUINFO)
  121. print_cpuinfo, /* display cpu info (and speed) */
  122. #endif
  123. #if defined(CONFIG_DISPLAY_BOARDINFO)
  124. checkboard, /* display board info */
  125. #endif
  126. dram_init, /* configure available RAM banks */
  127. NULL,
  128. };
  129. void board_init_f(ulong bootflag)
  130. {
  131. init_fnc_t **init_fnc_ptr;
  132. uchar *mem;
  133. unsigned long addr_sp, addr, size;
  134. gd = malloc(sizeof(gd_t));
  135. assert(gd);
  136. memset((void *)gd, 0, sizeof(gd_t));
  137. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  138. if ((*init_fnc_ptr)() != 0)
  139. hang();
  140. }
  141. size = CONFIG_SYS_SDRAM_SIZE;
  142. mem = malloc(size);
  143. assert(mem);
  144. gd->ram_buf = mem;
  145. addr = (ulong)(mem + size);
  146. /*
  147. * reserve memory for malloc() arena
  148. */
  149. addr_sp = addr - TOTAL_MALLOC_LEN;
  150. debug("Reserving %dk for malloc() at: %08lx\n",
  151. TOTAL_MALLOC_LEN >> 10, addr_sp);
  152. /*
  153. * (permanently) allocate a Board Info struct
  154. * and a permanent copy of the "global" data
  155. */
  156. addr_sp -= sizeof(bd_t);
  157. gd->bd = (bd_t *) addr_sp;
  158. debug("Reserving %zu Bytes for Board Info at: %08lx\n",
  159. sizeof(bd_t), addr_sp);
  160. /* Ram ist board specific, so move it to board code ... */
  161. dram_init_banksize();
  162. display_dram_config(); /* and display it */
  163. /* We don't relocate, so just run the post-relocation code */
  164. board_init_r(NULL, 0);
  165. /* NOTREACHED - no way out of command loop except booting */
  166. }
  167. /************************************************************************
  168. *
  169. * This is the next part if the initialization sequence: we are now
  170. * running from RAM and have a "normal" C environment, i. e. global
  171. * data can be written, BSS has been cleared, the stack size in not
  172. * that critical any more, etc.
  173. *
  174. ************************************************************************
  175. */
  176. void board_init_r(gd_t *id, ulong dest_addr)
  177. {
  178. if (id)
  179. gd = id;
  180. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  181. #ifdef CONFIG_SERIAL_MULTI
  182. serial_initialize();
  183. #endif
  184. #ifdef CONFIG_POST
  185. post_output_backlog();
  186. #endif
  187. #if 0 /* Sandbox uses system malloc for now */
  188. /* The Malloc area is immediately below the monitor copy in DRAM */
  189. malloc_start = dest_addr - TOTAL_MALLOC_LEN;
  190. mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
  191. #endif
  192. /* initialize environment */
  193. env_relocate();
  194. /* IP Address */
  195. gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  196. stdio_init(); /* get the devices list going. */
  197. jumptable_init();
  198. console_init_r(); /* fully init console as a device */
  199. #if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
  200. checkboard();
  201. #endif
  202. #if defined(CONFIG_ARCH_MISC_INIT)
  203. /* miscellaneous arch dependent initialisations */
  204. arch_misc_init();
  205. #endif
  206. #if defined(CONFIG_MISC_INIT_R)
  207. /* miscellaneous platform dependent initialisations */
  208. misc_init_r();
  209. #endif
  210. /* set up exceptions */
  211. interrupt_init();
  212. /* enable exceptions */
  213. enable_interrupts();
  214. #ifdef CONFIG_BOARD_LATE_INIT
  215. board_late_init();
  216. #endif
  217. #ifdef CONFIG_POST
  218. post_run(NULL, POST_RAM | post_bootmode_get(0));
  219. #endif
  220. /*
  221. * For now, run the main loop. Later we might let this be done
  222. * in the main program.
  223. */
  224. while (1)
  225. main_loop();
  226. /* NOTREACHED - no way out of command loop except booting */
  227. }
  228. void hang(void)
  229. {
  230. puts("### ERROR ### Please RESET the board ###\n");
  231. for (;;)
  232. ;
  233. }