init_helpers.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <fdtdec.h>
  25. #include <spi.h>
  26. #include <asm/sections.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /* Get the top of usable RAM */
  29. __weak ulong board_get_usable_ram_top(ulong total_size)
  30. {
  31. return gd->ram_size;
  32. }
  33. int calculate_relocation_address(void)
  34. {
  35. const ulong uboot_size = (uintptr_t)&__bss_end -
  36. (uintptr_t)&__text_start;
  37. ulong total_size;
  38. ulong dest_addr;
  39. ulong fdt_size = 0;
  40. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  41. if (gd->fdt_blob)
  42. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  43. #endif
  44. total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
  45. CONFIG_SYS_STACK_SIZE + fdt_size;
  46. dest_addr = board_get_usable_ram_top(total_size);
  47. /*
  48. * NOTE: All destination address are rounded down to 16-byte
  49. * boundary to satisfy various worst-case alignment
  50. * requirements
  51. */
  52. dest_addr &= ~15;
  53. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  54. /*
  55. * If the device tree is sitting immediate above our image then we
  56. * must relocate it. If it is embedded in the data section, then it
  57. * will be relocated with other data.
  58. */
  59. if (gd->fdt_blob) {
  60. dest_addr -= fdt_size;
  61. gd->new_fdt = (void *)dest_addr;
  62. dest_addr &= ~15;
  63. }
  64. #endif
  65. /* U-Boot is below the FDT */
  66. dest_addr -= uboot_size;
  67. dest_addr &= ~((1 << 12) - 1);
  68. gd->relocaddr = dest_addr;
  69. gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
  70. /* Stack is at the bottom, so it can grow down */
  71. gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
  72. return 0;
  73. }
  74. int init_cache_f_r(void)
  75. {
  76. /* Initialise the CPU cache(s) */
  77. return init_cache();
  78. }
  79. bd_t bd_data;
  80. int init_bd_struct_r(void)
  81. {
  82. gd->bd = &bd_data;
  83. memset(gd->bd, 0, sizeof(bd_t));
  84. return 0;
  85. }
  86. int init_func_spi(void)
  87. {
  88. puts("SPI: ");
  89. spi_init();
  90. puts("ready\n");
  91. return 0;
  92. }
  93. int find_fdt(void)
  94. {
  95. #ifdef CONFIG_OF_EMBED
  96. /* Get a pointer to the FDT */
  97. gd->fdt_blob = _binary_dt_dtb_start;
  98. #elif defined CONFIG_OF_SEPARATE
  99. /* FDT is at end of image */
  100. gd->fdt_blob = (ulong *)&_end;
  101. #endif
  102. /* Allow the early environment to override the fdt address */
  103. gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
  104. (uintptr_t)gd->fdt_blob);
  105. return 0;
  106. }
  107. int prepare_fdt(void)
  108. {
  109. /* For now, put this check after the console is ready */
  110. if (fdtdec_prepare_fdt()) {
  111. panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
  112. "doc/README.fdt-control");
  113. }
  114. return 0;
  115. }