init_helpers.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * (C) Copyright 2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <fdtdec.h>
  26. #include <stdio_dev.h>
  27. #include <version.h>
  28. #include <malloc.h>
  29. #include <net.h>
  30. #include <ide.h>
  31. #include <serial.h>
  32. #include <spi.h>
  33. #include <status_led.h>
  34. #include <asm/processor.h>
  35. #include <asm/sections.h>
  36. #include <asm/u-boot-x86.h>
  37. #include <linux/compiler.h>
  38. #include <asm/init_helpers.h>
  39. DECLARE_GLOBAL_DATA_PTR;
  40. /************************************************************************
  41. * Init Utilities *
  42. ************************************************************************
  43. * Some of this code should be moved into the core functions,
  44. * or dropped completely,
  45. * but let's get it working (again) first...
  46. */
  47. int display_banner(void)
  48. {
  49. printf("\n\n%s\n\n", version_string);
  50. return 0;
  51. }
  52. int display_dram_config(void)
  53. {
  54. int i;
  55. puts("DRAM Configuration:\n");
  56. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  57. printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  58. print_size(gd->bd->bi_dram[i].size, "\n");
  59. }
  60. return 0;
  61. }
  62. int init_baudrate_f(void)
  63. {
  64. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  65. return 0;
  66. }
  67. /* Get the top of usable RAM */
  68. __weak ulong board_get_usable_ram_top(ulong total_size)
  69. {
  70. return gd->ram_size;
  71. }
  72. int calculate_relocation_address(void)
  73. {
  74. const ulong uboot_size = (uintptr_t)&__bss_end -
  75. (uintptr_t)&__text_start;
  76. ulong total_size;
  77. ulong dest_addr;
  78. ulong fdt_size = 0;
  79. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  80. if (gd->fdt_blob)
  81. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  82. #endif
  83. total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
  84. CONFIG_SYS_STACK_SIZE + fdt_size;
  85. dest_addr = board_get_usable_ram_top(total_size);
  86. /*
  87. * NOTE: All destination address are rounded down to 16-byte
  88. * boundary to satisfy various worst-case alignment
  89. * requirements
  90. */
  91. dest_addr &= ~15;
  92. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  93. /*
  94. * If the device tree is sitting immediate above our image then we
  95. * must relocate it. If it is embedded in the data section, then it
  96. * will be relocated with other data.
  97. */
  98. if (gd->fdt_blob) {
  99. dest_addr -= fdt_size;
  100. gd->new_fdt = (void *)dest_addr;
  101. dest_addr &= ~15;
  102. }
  103. #endif
  104. /* U-Boot is below the FDT */
  105. dest_addr -= uboot_size;
  106. dest_addr &= ~((1 << 12) - 1);
  107. gd->relocaddr = dest_addr;
  108. gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
  109. /* Stack is at the bottom, so it can grow down */
  110. gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
  111. return 0;
  112. }
  113. int init_cache_f_r(void)
  114. {
  115. /* Initialise the CPU cache(s) */
  116. return init_cache();
  117. }
  118. int set_reloc_flag_r(void)
  119. {
  120. gd->flags = GD_FLG_RELOC;
  121. return 0;
  122. }
  123. int mem_malloc_init_r(void)
  124. {
  125. mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
  126. CONFIG_SYS_MALLOC_LEN);
  127. return 0;
  128. }
  129. bd_t bd_data;
  130. int init_bd_struct_r(void)
  131. {
  132. gd->bd = &bd_data;
  133. memset(gd->bd, 0, sizeof(bd_t));
  134. return 0;
  135. }
  136. #ifndef CONFIG_SYS_NO_FLASH
  137. int flash_init_r(void)
  138. {
  139. ulong size;
  140. puts("Flash: ");
  141. /* configure available FLASH banks */
  142. size = flash_init();
  143. print_size(size, "\n");
  144. return 0;
  145. }
  146. #endif
  147. #ifdef CONFIG_STATUS_LED
  148. int status_led_set_r(void)
  149. {
  150. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  151. return 0;
  152. }
  153. #endif
  154. int set_load_addr_r(void)
  155. {
  156. /* Initialize from environment */
  157. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  158. return 0;
  159. }
  160. int init_func_spi(void)
  161. {
  162. puts("SPI: ");
  163. spi_init();
  164. puts("ready\n");
  165. return 0;
  166. }
  167. #ifdef CONFIG_OF_CONTROL
  168. int find_fdt(void)
  169. {
  170. #ifdef CONFIG_OF_EMBED
  171. /* Get a pointer to the FDT */
  172. gd->fdt_blob = _binary_dt_dtb_start;
  173. #elif defined CONFIG_OF_SEPARATE
  174. /* FDT is at end of image */
  175. gd->fdt_blob = (ulong *)&_end;
  176. #endif
  177. /* Allow the early environment to override the fdt address */
  178. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  179. (uintptr_t)gd->fdt_blob);
  180. return 0;
  181. }
  182. int prepare_fdt(void)
  183. {
  184. /* For now, put this check after the console is ready */
  185. if (fdtdec_prepare_fdt()) {
  186. panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
  187. "doc/README.fdt-control");
  188. }
  189. return 0;
  190. }
  191. #endif