board.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * U-boot - board.c First C file to be called contains init routines
  3. *
  4. * Copyright (c) 2005 blackfin.uclinux.org
  5. *
  6. * (C) Copyright 2000-2004
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <command.h>
  29. #include <malloc.h>
  30. #include <devices.h>
  31. #include <version.h>
  32. #include <net.h>
  33. #include <environment.h>
  34. #include "blackfin_board.h"
  35. #include "../drivers/smc91111.h"
  36. extern flash_info_t flash_info[];
  37. static void mem_malloc_init(void)
  38. {
  39. mem_malloc_start = CFG_MALLOC_BASE;
  40. mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN);
  41. mem_malloc_brk = mem_malloc_start;
  42. memset((void *) mem_malloc_start, 0,
  43. mem_malloc_end - mem_malloc_start);
  44. }
  45. void *sbrk(ptrdiff_t increment)
  46. {
  47. ulong old = mem_malloc_brk;
  48. ulong new = old + increment;
  49. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  50. return (NULL);
  51. }
  52. mem_malloc_brk = new;
  53. return ((void *) old);
  54. }
  55. static int display_banner(void)
  56. {
  57. sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING);
  58. printf("%s\n", version_string);
  59. return (0);
  60. }
  61. static void display_flash_config(ulong size)
  62. {
  63. puts("FLASH: ");
  64. print_size(size, "\n");
  65. return;
  66. }
  67. static int init_baudrate(void)
  68. {
  69. DECLARE_GLOBAL_DATA_PTR;
  70. uchar tmp[64];
  71. int i = getenv_r("baudrate", tmp, sizeof(tmp));
  72. gd->bd->bi_baudrate = gd->baudrate = (i > 0)
  73. ? (int) simple_strtoul(tmp, NULL, 10)
  74. : CONFIG_BAUDRATE;
  75. return (0);
  76. }
  77. #ifdef DEBUG
  78. static void display_global_data(void)
  79. {
  80. DECLARE_GLOBAL_DATA_PTR;
  81. bd_t *bd;
  82. bd = gd->bd;
  83. printf("--flags:%x\n", gd->flags);
  84. printf("--board_type:%x\n", gd->board_type);
  85. printf("--baudrate:%x\n", gd->baudrate);
  86. printf("--have_console:%x\n", gd->have_console);
  87. printf("--ram_size:%x\n", gd->ram_size);
  88. printf("--reloc_off:%x\n", gd->reloc_off);
  89. printf("--env_addr:%x\n", gd->env_addr);
  90. printf("--env_valid:%x\n", gd->env_valid);
  91. printf("--bd:%x %x\n", gd->bd, bd);
  92. printf("---bi_baudrate:%x\n", bd->bi_baudrate);
  93. printf("---bi_ip_addr:%x\n", bd->bi_ip_addr);
  94. printf("---bi_enetaddr:%x %x %x %x %x %x\n",
  95. bd->bi_enetaddr[0],
  96. bd->bi_enetaddr[1],
  97. bd->bi_enetaddr[2],
  98. bd->bi_enetaddr[3],
  99. bd->bi_enetaddr[4],
  100. bd->bi_enetaddr[5]);
  101. printf("---bi_arch_number:%x\n", bd->bi_arch_number);
  102. printf("---bi_boot_params:%x\n", bd->bi_boot_params);
  103. printf("---bi_memstart:%x\n", bd->bi_memstart);
  104. printf("---bi_memsize:%x\n", bd->bi_memsize);
  105. printf("---bi_flashstart:%x\n", bd->bi_flashstart);
  106. printf("---bi_flashsize:%x\n", bd->bi_flashsize);
  107. printf("---bi_flashoffset:%x\n", bd->bi_flashoffset);
  108. printf("--jt:%x *:%x\n", gd->jt, *(gd->jt));
  109. }
  110. #endif
  111. /*
  112. * All attempts to come up with a "common" initialization sequence
  113. * that works for all boards and architectures failed: some of the
  114. * requirements are just _too_ different. To get rid of the resulting
  115. * mess of board dependend #ifdef'ed code we now make the whole
  116. * initialization sequence configurable to the user.
  117. *
  118. * The requirements for any new initalization function is simple: it
  119. * receives a pointer to the "global data" structure as it's only
  120. * argument, and returns an integer return code, where 0 means
  121. * "continue" and != 0 means "fatal error, hang the system".
  122. */
  123. void board_init_f(ulong bootflag)
  124. {
  125. DECLARE_GLOBAL_DATA_PTR;
  126. ulong addr;
  127. bd_t *bd;
  128. gd = (gd_t *) (CFG_GBL_DATA_ADDR);
  129. memset((void *) gd, 0, sizeof(gd_t));
  130. /* Board data initialization */
  131. addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
  132. /* Align to 4 byte boundary */
  133. addr &= ~(4 - 1);
  134. bd = (bd_t*)addr;
  135. gd->bd = bd;
  136. memset((void *) bd, 0, sizeof(bd_t));
  137. /* Initialize */
  138. init_IRQ();
  139. env_init(); /* initialize environment */
  140. init_baudrate(); /* initialze baudrate settings */
  141. serial_init(); /* serial communications setup */
  142. console_init_f();
  143. display_banner(); /* say that we are here */
  144. checkboard();
  145. #if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE)
  146. rtc_init();
  147. #endif
  148. timer_init();
  149. printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", \
  150. CONFIG_VCO_HZ/1000000, CONFIG_CCLK_HZ/1000000, CONFIG_SCLK_HZ/1000000);
  151. printf("SDRAM: ");
  152. print_size(initdram(0), "\n");
  153. board_init_r((gd_t *) gd, 0x20000010);
  154. }
  155. void board_init_r(gd_t * id, ulong dest_addr)
  156. {
  157. DECLARE_GLOBAL_DATA_PTR;
  158. ulong size;
  159. extern void malloc_bin_reloc(void);
  160. char *s, *e;
  161. bd_t *bd;
  162. int i;
  163. gd = id;
  164. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  165. bd = gd->bd;
  166. #if CONFIG_STAMP
  167. /* There are some other pointer constants we must deal with */
  168. /* configure available FLASH banks */
  169. size = flash_init();
  170. display_flash_config(size);
  171. flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
  172. bd->bi_flashstart = CFG_FLASH_BASE;
  173. bd->bi_flashsize = size;
  174. bd->bi_flashoffset = 0;
  175. #else
  176. bd->bi_flashstart = 0;
  177. bd->bi_flashsize = 0;
  178. bd->bi_flashoffset = 0;
  179. #endif
  180. /* initialize malloc() area */
  181. mem_malloc_init();
  182. malloc_bin_reloc();
  183. /* relocate environment function pointers etc. */
  184. env_relocate();
  185. /* board MAC address */
  186. s = getenv("ethaddr");
  187. for (i = 0; i < 6; ++i) {
  188. bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
  189. if (s)
  190. s = (*e) ? e + 1 : e;
  191. }
  192. /* IP Address */
  193. bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  194. /* Initialize devices */
  195. devices_init();
  196. jumptable_init();
  197. /* Initialize the console (after the relocation and devices init) */
  198. console_init_r();
  199. /* Initialize from environment */
  200. if ((s = getenv("loadaddr")) != NULL) {
  201. load_addr = simple_strtoul(s, NULL, 16);
  202. }
  203. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  204. if ((s = getenv("bootfile")) != NULL) {
  205. copy_filename(BootFile, s, sizeof(BootFile));
  206. }
  207. #endif
  208. #if defined(CONFIG_MISC_INIT_R)
  209. /* miscellaneous platform dependent initialisations */
  210. misc_init_r();
  211. #endif
  212. #ifdef CONFIG_DRIVER_SMC91111
  213. #ifdef SHARED_RESOURCES
  214. /* Switch to Ethernet */
  215. swap_to(ETHERNET);
  216. #endif
  217. if ( (SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT ) {
  218. printf("ERROR: Can't find SMC91111 at address %x\n", SMC_BASE_ADDRESS);
  219. } else {
  220. printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
  221. }
  222. #ifdef SHARED_RESOURCES
  223. swap_to(FLASH);
  224. #endif
  225. #endif
  226. #ifdef CONFIG_SOFT_I2C
  227. init_func_i2c();
  228. #endif
  229. #ifdef DEBUG
  230. display_global_data(void);
  231. #endif
  232. /* main_loop() can return to retry autoboot, if so just run it again. */
  233. for (;;) {
  234. main_loop();
  235. }
  236. }
  237. #ifdef CONFIG_SOFT_I2C
  238. static int init_func_i2c (void)
  239. {
  240. puts ("I2C: ");
  241. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  242. puts ("ready\n");
  243. return (0);
  244. }
  245. #endif
  246. void hang(void)
  247. {
  248. puts("### ERROR ### Please RESET the board ###\n");
  249. for (;;);
  250. }