init_helpers.c 2.5 KB

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