board.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. DECLARE_GLOBAL_DATA_PTR;
  37. extern flash_info_t flash_info[];
  38. static void mem_malloc_init(void)
  39. {
  40. mem_malloc_start = CFG_MALLOC_BASE;
  41. mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN);
  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. ulong old = mem_malloc_brk;
  49. ulong new = old + increment;
  50. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  51. return (NULL);
  52. }
  53. mem_malloc_brk = new;
  54. return ((void *) old);
  55. }
  56. static int display_banner(void)
  57. {
  58. sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING);
  59. printf("%s\n", version_string);
  60. return (0);
  61. }
  62. static void display_flash_config(ulong size)
  63. {
  64. puts("FLASH: ");
  65. print_size(size, "\n");
  66. return;
  67. }
  68. static int init_baudrate(void)
  69. {
  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. bd_t *bd;
  81. bd = gd->bd;
  82. printf("--flags:%x\n", gd->flags);
  83. printf("--board_type:%x\n", gd->board_type);
  84. printf("--baudrate:%x\n", gd->baudrate);
  85. printf("--have_console:%x\n", gd->have_console);
  86. printf("--ram_size:%x\n", gd->ram_size);
  87. printf("--reloc_off:%x\n", gd->reloc_off);
  88. printf("--env_addr:%x\n", gd->env_addr);
  89. printf("--env_valid:%x\n", gd->env_valid);
  90. printf("--bd:%x %x\n", gd->bd, bd);
  91. printf("---bi_baudrate:%x\n", bd->bi_baudrate);
  92. printf("---bi_ip_addr:%x\n", bd->bi_ip_addr);
  93. printf("---bi_enetaddr:%x %x %x %x %x %x\n",
  94. bd->bi_enetaddr[0],
  95. bd->bi_enetaddr[1],
  96. bd->bi_enetaddr[2],
  97. bd->bi_enetaddr[3],
  98. bd->bi_enetaddr[4],
  99. bd->bi_enetaddr[5]);
  100. printf("---bi_arch_number:%x\n", bd->bi_arch_number);
  101. printf("---bi_boot_params:%x\n", bd->bi_boot_params);
  102. printf("---bi_memstart:%x\n", bd->bi_memstart);
  103. printf("---bi_memsize:%x\n", bd->bi_memsize);
  104. printf("---bi_flashstart:%x\n", bd->bi_flashstart);
  105. printf("---bi_flashsize:%x\n", bd->bi_flashsize);
  106. printf("---bi_flashoffset:%x\n", bd->bi_flashoffset);
  107. printf("--jt:%x *:%x\n", gd->jt, *(gd->jt));
  108. }
  109. #endif
  110. /*
  111. * All attempts to come up with a "common" initialization sequence
  112. * that works for all boards and architectures failed: some of the
  113. * requirements are just _too_ different. To get rid of the resulting
  114. * mess of board dependend #ifdef'ed code we now make the whole
  115. * initialization sequence configurable to the user.
  116. *
  117. * The requirements for any new initalization function is simple: it
  118. * receives a pointer to the "global data" structure as it's only
  119. * argument, and returns an integer return code, where 0 means
  120. * "continue" and != 0 means "fatal error, hang the system".
  121. */
  122. void board_init_f(ulong bootflag)
  123. {
  124. ulong addr;
  125. bd_t *bd;
  126. gd = (gd_t *) (CFG_GBL_DATA_ADDR);
  127. memset((void *) gd, 0, sizeof(gd_t));
  128. /* Board data initialization */
  129. addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
  130. /* Align to 4 byte boundary */
  131. addr &= ~(4 - 1);
  132. bd = (bd_t*)addr;
  133. gd->bd = bd;
  134. memset((void *) bd, 0, sizeof(bd_t));
  135. /* Initialize */
  136. init_IRQ();
  137. env_init(); /* initialize environment */
  138. init_baudrate(); /* initialze baudrate settings */
  139. serial_init(); /* serial communications setup */
  140. console_init_f();
  141. display_banner(); /* say that we are here */
  142. checkboard();
  143. #if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE)
  144. rtc_init();
  145. #endif
  146. timer_init();
  147. printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", \
  148. CONFIG_VCO_HZ/1000000, CONFIG_CCLK_HZ/1000000, CONFIG_SCLK_HZ/1000000);
  149. printf("SDRAM: ");
  150. print_size(initdram(0), "\n");
  151. board_init_r((gd_t *) gd, 0x20000010);
  152. }
  153. void board_init_r(gd_t * id, ulong dest_addr)
  154. {
  155. ulong size;
  156. extern void malloc_bin_reloc(void);
  157. char *s, *e;
  158. bd_t *bd;
  159. int i;
  160. gd = id;
  161. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  162. bd = gd->bd;
  163. #if CONFIG_STAMP
  164. /* There are some other pointer constants we must deal with */
  165. /* configure available FLASH banks */
  166. size = flash_init();
  167. display_flash_config(size);
  168. flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
  169. bd->bi_flashstart = CFG_FLASH_BASE;
  170. bd->bi_flashsize = size;
  171. bd->bi_flashoffset = 0;
  172. #else
  173. bd->bi_flashstart = 0;
  174. bd->bi_flashsize = 0;
  175. bd->bi_flashoffset = 0;
  176. #endif
  177. /* initialize malloc() area */
  178. mem_malloc_init();
  179. malloc_bin_reloc();
  180. /* relocate environment function pointers etc. */
  181. env_relocate();
  182. /* board MAC address */
  183. s = getenv("ethaddr");
  184. for (i = 0; i < 6; ++i) {
  185. bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
  186. if (s)
  187. s = (*e) ? e + 1 : e;
  188. }
  189. /* IP Address */
  190. bd->bi_ip_addr = getenv_IPaddr("ipaddr");
  191. /* Initialize devices */
  192. devices_init();
  193. jumptable_init();
  194. /* Initialize the console (after the relocation and devices init) */
  195. console_init_r();
  196. /* Initialize from environment */
  197. if ((s = getenv("loadaddr")) != NULL) {
  198. load_addr = simple_strtoul(s, NULL, 16);
  199. }
  200. #if (CONFIG_COMMANDS & CFG_CMD_NET)
  201. if ((s = getenv("bootfile")) != NULL) {
  202. copy_filename(BootFile, s, sizeof(BootFile));
  203. }
  204. #endif
  205. #if defined(CONFIG_MISC_INIT_R)
  206. /* miscellaneous platform dependent initialisations */
  207. misc_init_r();
  208. #endif
  209. #ifdef CONFIG_DRIVER_SMC91111
  210. #ifdef SHARED_RESOURCES
  211. /* Switch to Ethernet */
  212. swap_to(ETHERNET);
  213. #endif
  214. if ( (SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT ) {
  215. printf("ERROR: Can't find SMC91111 at address %x\n", SMC_BASE_ADDRESS);
  216. } else {
  217. printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
  218. }
  219. #ifdef SHARED_RESOURCES
  220. swap_to(FLASH);
  221. #endif
  222. #endif
  223. #ifdef CONFIG_SOFT_I2C
  224. init_func_i2c();
  225. #endif
  226. #ifdef DEBUG
  227. display_global_data(void);
  228. #endif
  229. /* main_loop() can return to retry autoboot, if so just run it again. */
  230. for (;;) {
  231. main_loop();
  232. }
  233. }
  234. #ifdef CONFIG_SOFT_I2C
  235. static int init_func_i2c (void)
  236. {
  237. puts ("I2C: ");
  238. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  239. puts ("ready\n");
  240. return (0);
  241. }
  242. #endif
  243. void hang(void)
  244. {
  245. puts("### ERROR ### Please RESET the board ###\n");
  246. for (;;);
  247. }