init_helpers.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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/u-boot-x86.h>
  36. #include <linux/compiler.h>
  37. #include <asm/init_helpers.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. /************************************************************************
  40. * Init Utilities *
  41. ************************************************************************
  42. * Some of this code should be moved into the core functions,
  43. * or dropped completely,
  44. * but let's get it working (again) first...
  45. */
  46. int display_banner(void)
  47. {
  48. printf("\n\n%s\n\n", version_string);
  49. return 0;
  50. }
  51. 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. int init_baudrate_f(void)
  62. {
  63. gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
  64. return 0;
  65. }
  66. /* Get the top of usable RAM */
  67. __weak ulong board_get_usable_ram_top(ulong total_size)
  68. {
  69. return gd->ram_size;
  70. }
  71. int calculate_relocation_address(void)
  72. {
  73. const ulong uboot_size = (uintptr_t)&__bss_end -
  74. (uintptr_t)&__text_start;
  75. ulong total_size;
  76. ulong dest_addr;
  77. ulong fdt_size = 0;
  78. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  79. if (gd->fdt_blob)
  80. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  81. #endif
  82. total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
  83. CONFIG_SYS_STACK_SIZE + fdt_size;
  84. dest_addr = board_get_usable_ram_top(total_size);
  85. /*
  86. * NOTE: All destination address are rounded down to 16-byte
  87. * boundary to satisfy various worst-case alignment
  88. * requirements
  89. */
  90. dest_addr &= ~15;
  91. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  92. /*
  93. * If the device tree is sitting immediate above our image then we
  94. * must relocate it. If it is embedded in the data section, then it
  95. * will be relocated with other data.
  96. */
  97. if (gd->fdt_blob) {
  98. dest_addr -= fdt_size;
  99. gd->new_fdt = (void *)dest_addr;
  100. dest_addr &= ~15;
  101. }
  102. #endif
  103. /* U-Boot is below the FDT */
  104. dest_addr -= uboot_size;
  105. dest_addr &= ~((1 << 12) - 1);
  106. gd->relocaddr = dest_addr;
  107. gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
  108. /* Stack is at the bottom, so it can grow down */
  109. gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
  110. return 0;
  111. }
  112. int init_cache_f_r(void)
  113. {
  114. /* Initialise the CPU cache(s) */
  115. return init_cache();
  116. }
  117. int set_reloc_flag_r(void)
  118. {
  119. gd->flags = GD_FLG_RELOC;
  120. return 0;
  121. }
  122. int mem_malloc_init_r(void)
  123. {
  124. mem_malloc_init(((gd->relocaddr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
  125. CONFIG_SYS_MALLOC_LEN);
  126. return 0;
  127. }
  128. bd_t bd_data;
  129. int init_bd_struct_r(void)
  130. {
  131. gd->bd = &bd_data;
  132. memset(gd->bd, 0, sizeof(bd_t));
  133. return 0;
  134. }
  135. #ifndef CONFIG_SYS_NO_FLASH
  136. int flash_init_r(void)
  137. {
  138. ulong size;
  139. puts("Flash: ");
  140. /* configure available FLASH banks */
  141. size = flash_init();
  142. print_size(size, "\n");
  143. return 0;
  144. }
  145. #endif
  146. #ifdef CONFIG_STATUS_LED
  147. int status_led_set_r(void)
  148. {
  149. status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
  150. return 0;
  151. }
  152. #endif
  153. int set_load_addr_r(void)
  154. {
  155. /* Initialize from environment */
  156. load_addr = getenv_ulong("loadaddr", 16, load_addr);
  157. return 0;
  158. }
  159. int init_func_spi(void)
  160. {
  161. puts("SPI: ");
  162. spi_init();
  163. puts("ready\n");
  164. return 0;
  165. }
  166. #ifdef CONFIG_OF_CONTROL
  167. int find_fdt(void)
  168. {
  169. #ifdef CONFIG_OF_EMBED
  170. /* Get a pointer to the FDT */
  171. gd->fdt_blob = _binary_dt_dtb_start;
  172. #elif defined CONFIG_OF_SEPARATE
  173. /* FDT is at end of image */
  174. gd->fdt_blob = (ulong *)&_end;
  175. #endif
  176. /* Allow the early environment to override the fdt address */
  177. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  178. (uintptr_t)gd->fdt_blob);
  179. return 0;
  180. }
  181. int prepare_fdt(void)
  182. {
  183. /* For now, put this check after the console is ready */
  184. if (fdtdec_prepare_fdt()) {
  185. panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
  186. "doc/README.fdt-control");
  187. }
  188. return 0;
  189. }
  190. #endif