init_helpers.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * (C) Copyright 2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <fdtdec.h>
  9. #include <spi.h>
  10. #include <asm/errno.h>
  11. #include <asm/mtrr.h>
  12. #include <asm/sections.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. /* Get the top of usable RAM */
  15. __weak ulong board_get_usable_ram_top(ulong total_size)
  16. {
  17. return gd->ram_size;
  18. }
  19. int calculate_relocation_address(void)
  20. {
  21. const ulong uboot_size = (uintptr_t)&__bss_end -
  22. (uintptr_t)&__text_start;
  23. ulong total_size;
  24. ulong dest_addr;
  25. ulong fdt_size = 0;
  26. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  27. if (gd->fdt_blob)
  28. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  29. #endif
  30. total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
  31. CONFIG_SYS_STACK_SIZE + fdt_size;
  32. dest_addr = board_get_usable_ram_top(total_size);
  33. /*
  34. * NOTE: All destination address are rounded down to 16-byte
  35. * boundary to satisfy various worst-case alignment
  36. * requirements
  37. */
  38. dest_addr &= ~15;
  39. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  40. /*
  41. * If the device tree is sitting immediate above our image then we
  42. * must relocate it. If it is embedded in the data section, then it
  43. * will be relocated with other data.
  44. */
  45. if (gd->fdt_blob) {
  46. dest_addr -= fdt_size;
  47. gd->new_fdt = (void *)dest_addr;
  48. dest_addr &= ~15;
  49. }
  50. #endif
  51. /* U-Boot is below the FDT */
  52. dest_addr -= uboot_size;
  53. dest_addr &= ~((1 << 12) - 1);
  54. gd->relocaddr = dest_addr;
  55. gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
  56. /* Stack is at the bottom, so it can grow down */
  57. gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
  58. return 0;
  59. }
  60. int init_cache_f_r(void)
  61. {
  62. #if defined(CONFIG_X86_RESET_VECTOR) & !defined(CONFIG_HAVE_FSP)
  63. int ret;
  64. ret = mtrr_commit(false);
  65. /* If MTRR MSR is not implemented by the processor, just ignore it */
  66. if (ret && ret != -ENOSYS)
  67. return ret;
  68. #endif
  69. /* Initialise the CPU cache(s) */
  70. return init_cache();
  71. }
  72. bd_t bd_data;
  73. int init_bd_struct_r(void)
  74. {
  75. gd->bd = &bd_data;
  76. memset(gd->bd, 0, sizeof(bd_t));
  77. return 0;
  78. }