init_helpers.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/mtrr.h>
  11. #include <asm/sections.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. /* Get the top of usable RAM */
  14. __weak ulong board_get_usable_ram_top(ulong total_size)
  15. {
  16. return gd->ram_size;
  17. }
  18. int calculate_relocation_address(void)
  19. {
  20. const ulong uboot_size = (uintptr_t)&__bss_end -
  21. (uintptr_t)&__text_start;
  22. ulong total_size;
  23. ulong dest_addr;
  24. ulong fdt_size = 0;
  25. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  26. if (gd->fdt_blob)
  27. fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
  28. #endif
  29. total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
  30. CONFIG_SYS_STACK_SIZE + fdt_size;
  31. dest_addr = board_get_usable_ram_top(total_size);
  32. /*
  33. * NOTE: All destination address are rounded down to 16-byte
  34. * boundary to satisfy various worst-case alignment
  35. * requirements
  36. */
  37. dest_addr &= ~15;
  38. #if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
  39. /*
  40. * If the device tree is sitting immediate above our image then we
  41. * must relocate it. If it is embedded in the data section, then it
  42. * will be relocated with other data.
  43. */
  44. if (gd->fdt_blob) {
  45. dest_addr -= fdt_size;
  46. gd->new_fdt = (void *)dest_addr;
  47. dest_addr &= ~15;
  48. }
  49. #endif
  50. /* U-Boot is below the FDT */
  51. dest_addr -= uboot_size;
  52. dest_addr &= ~((1 << 12) - 1);
  53. gd->relocaddr = dest_addr;
  54. gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
  55. /* Stack is at the bottom, so it can grow down */
  56. gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
  57. return 0;
  58. }
  59. int init_cache_f_r(void)
  60. {
  61. #if defined(CONFIG_X86_RESET_VECTOR) & !defined(CONFIG_HAVE_FSP)
  62. int ret;
  63. ret = mtrr_commit(false);
  64. if (ret)
  65. return ret;
  66. #endif
  67. /* Initialise the CPU cache(s) */
  68. return init_cache();
  69. }
  70. bd_t bd_data;
  71. int init_bd_struct_r(void)
  72. {
  73. gd->bd = &bd_data;
  74. memset(gd->bd, 0, sizeof(bd_t));
  75. return 0;
  76. }
  77. int init_func_spi(void)
  78. {
  79. puts("SPI: ");
  80. spi_init();
  81. puts("ready\n");
  82. return 0;
  83. }