board.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <malloc.h>
  9. #include <stdio_dev.h>
  10. #include <version.h>
  11. #include <net.h>
  12. #ifdef CONFIG_BITBANGMII
  13. #include <miiphy.h>
  14. #endif
  15. #include <asm/sections.h>
  16. #include <asm/arch/mmu.h>
  17. #include <asm/arch/hardware.h>
  18. #ifndef CONFIG_IDENT_STRING
  19. #define CONFIG_IDENT_STRING ""
  20. #endif
  21. #ifdef CONFIG_GENERIC_ATMEL_MCI
  22. #include <mmc.h>
  23. #endif
  24. DECLARE_GLOBAL_DATA_PTR;
  25. unsigned long monitor_flash_len;
  26. __weak void dram_init_banksize(void)
  27. {
  28. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  29. gd->bd->bi_dram[0].size = gd->ram_size;
  30. }
  31. /* Weak aliases for optional board functions */
  32. static int __do_nothing(void)
  33. {
  34. return 0;
  35. }
  36. int board_postclk_init(void) __attribute__((weak, alias("__do_nothing")));
  37. int board_early_init_r(void) __attribute__((weak, alias("__do_nothing")));
  38. static int init_baudrate(void)
  39. {
  40. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  41. return 0;
  42. }
  43. static int display_banner (void)
  44. {
  45. printf ("\n\n%s\n\n", version_string);
  46. printf ("U-Boot code: %08lx -> %08lx data: %08lx -> %08lx\n",
  47. (unsigned long)_text, (unsigned long)_etext,
  48. (unsigned long)_data, (unsigned long)(&__bss_end));
  49. return 0;
  50. }
  51. static int display_dram_config (void)
  52. {
  53. int i;
  54. puts ("DRAM Configuration:\n");
  55. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  56. printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  57. print_size (gd->bd->bi_dram[i].size, "\n");
  58. }
  59. return 0;
  60. }
  61. static void display_flash_config (void)
  62. {
  63. puts ("Flash: ");
  64. print_size(gd->bd->bi_flashsize, " ");
  65. printf("at address 0x%08lx\n", gd->bd->bi_flashstart);
  66. }
  67. void board_init_f(ulong board_type)
  68. {
  69. gd_t gd_data;
  70. gd_t *new_gd;
  71. bd_t *bd;
  72. unsigned long *new_sp;
  73. unsigned long monitor_len;
  74. unsigned long monitor_addr;
  75. unsigned long addr;
  76. /* Initialize the global data pointer */
  77. memset(&gd_data, 0, sizeof(gd_data));
  78. gd = &gd_data;
  79. /* Perform initialization sequence */
  80. board_early_init_f();
  81. arch_cpu_init();
  82. board_postclk_init();
  83. env_init();
  84. init_baudrate();
  85. serial_init();
  86. console_init_f();
  87. display_banner();
  88. dram_init();
  89. /* If we have no SDRAM, we can't go on */
  90. if (gd->ram_size <= 0)
  91. panic("No working SDRAM available\n");
  92. /*
  93. * Now that we have DRAM mapped and working, we can
  94. * relocate the code and continue running from DRAM.
  95. *
  96. * Reserve memory at end of RAM for (top down in that order):
  97. * - u-boot image
  98. * - heap for malloc()
  99. * - board info struct
  100. * - global data struct
  101. * - stack
  102. */
  103. addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
  104. monitor_len = (char *)(&__bss_end) - _text;
  105. /*
  106. * Reserve memory for u-boot code, data and bss.
  107. * Round down to next 4 kB limit.
  108. */
  109. addr -= monitor_len;
  110. addr &= ~(4096UL - 1);
  111. monitor_addr = addr;
  112. /* Reserve memory for malloc() */
  113. addr -= CONFIG_SYS_MALLOC_LEN;
  114. #ifdef CONFIG_LCD
  115. #ifdef CONFIG_FB_ADDR
  116. printf("LCD: Frame buffer allocated at preset 0x%08x\n",
  117. CONFIG_FB_ADDR);
  118. gd->fb_base = CONFIG_FB_ADDR;
  119. #else
  120. addr = lcd_setmem(addr);
  121. printf("LCD: Frame buffer allocated at 0x%08lx\n", addr);
  122. gd->fb_base = addr;
  123. #endif /* CONFIG_FB_ADDR */
  124. #endif /* CONFIG_LCD */
  125. /* Allocate a Board Info struct on a word boundary */
  126. addr -= sizeof(bd_t);
  127. addr &= ~3UL;
  128. gd->bd = bd = (bd_t *)addr;
  129. /* Allocate a new global data copy on a 8-byte boundary. */
  130. addr -= sizeof(gd_t);
  131. addr &= ~7UL;
  132. new_gd = (gd_t *)addr;
  133. /* And finally, a new, bigger stack. */
  134. new_sp = (unsigned long *)addr;
  135. gd->start_addr_sp = addr;
  136. *(--new_sp) = 0;
  137. *(--new_sp) = 0;
  138. dram_init_banksize();
  139. memcpy(new_gd, gd, sizeof(gd_t));
  140. relocate_code((unsigned long)new_sp, new_gd, monitor_addr);
  141. }
  142. void board_init_r(gd_t *new_gd, ulong dest_addr)
  143. {
  144. #ifndef CONFIG_ENV_IS_NOWHERE
  145. extern char * env_name_spec;
  146. #endif
  147. bd_t *bd;
  148. gd = new_gd;
  149. bd = gd->bd;
  150. gd->flags |= GD_FLG_RELOC;
  151. gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
  152. /* Enable the MMU so that we can keep u-boot simple */
  153. mmu_init_r(dest_addr);
  154. board_early_init_r();
  155. monitor_flash_len = _edata - _text;
  156. #if defined(CONFIG_NEEDS_MANUAL_RELOC)
  157. /*
  158. * We have to relocate the command table manually
  159. */
  160. fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
  161. ll_entry_count(cmd_tbl_t, cmd));
  162. #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
  163. /* there are some other pointer constants we must deal with */
  164. #ifndef CONFIG_ENV_IS_NOWHERE
  165. env_name_spec += gd->reloc_off;
  166. #endif
  167. timer_init();
  168. /* The malloc area is right below the monitor image in RAM */
  169. mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
  170. CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN);
  171. enable_interrupts();
  172. bd->bi_flashstart = 0;
  173. bd->bi_flashsize = 0;
  174. bd->bi_flashoffset = 0;
  175. #ifndef CONFIG_SYS_NO_FLASH
  176. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  177. bd->bi_flashsize = flash_init();
  178. bd->bi_flashoffset = (unsigned long)_edata - (unsigned long)_text;
  179. if (bd->bi_flashsize)
  180. display_flash_config();
  181. #endif
  182. if (bd->bi_dram[0].size)
  183. display_dram_config();
  184. gd->bd->bi_boot_params = malloc(CONFIG_SYS_BOOTPARAMS_LEN);
  185. if (!gd->bd->bi_boot_params)
  186. puts("WARNING: Cannot allocate space for boot parameters\n");
  187. /* initialize environment */
  188. env_relocate();
  189. stdio_init();
  190. jumptable_init();
  191. console_init_r();
  192. /* Initialize from environment */
  193. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  194. #ifdef CONFIG_BITBANGMII
  195. bb_miiphy_init();
  196. #endif
  197. #if defined(CONFIG_CMD_NET)
  198. puts("Net: ");
  199. eth_initialize(gd->bd);
  200. #endif
  201. #ifdef CONFIG_GENERIC_ATMEL_MCI
  202. mmc_initialize(gd->bd);
  203. #endif
  204. for (;;) {
  205. main_loop();
  206. }
  207. }