spl.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <clock_legacy.h>
  7. #include <cpu_func.h>
  8. #include <env.h>
  9. #include <image.h>
  10. #include <init.h>
  11. #include <log.h>
  12. #include <spl.h>
  13. #include <asm/cache.h>
  14. #include <asm/global_data.h>
  15. #include <asm/io.h>
  16. #include <fsl_ifc.h>
  17. #include <i2c.h>
  18. #include <fsl_csu.h>
  19. #include <asm/arch/fdt.h>
  20. #include <asm/arch/ppa.h>
  21. #include <asm/arch/soc.h>
  22. DECLARE_GLOBAL_DATA_PTR;
  23. u32 spl_boot_device(void)
  24. {
  25. #ifdef CONFIG_SPL_MMC_SUPPORT
  26. return BOOT_DEVICE_MMC1;
  27. #endif
  28. #ifdef CONFIG_SPL_NAND_SUPPORT
  29. return BOOT_DEVICE_NAND;
  30. #endif
  31. #ifdef CONFIG_QSPI_BOOT
  32. return BOOT_DEVICE_NOR;
  33. #endif
  34. return 0;
  35. }
  36. #ifdef CONFIG_SPL_BUILD
  37. /* Define board data structure */
  38. static struct bd_info bdata __attribute__ ((section(".data")));
  39. void spl_board_init(void)
  40. {
  41. #if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2)
  42. /*
  43. * In case of Secure Boot, the IBR configures the SMMU
  44. * to allow only Secure transactions.
  45. * SMMU must be reset in bypass mode.
  46. * Set the ClientPD bit and Clear the USFCFG Bit
  47. */
  48. u32 val;
  49. val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  50. out_le32(SMMU_SCR0, val);
  51. val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  52. out_le32(SMMU_NSCR0, val);
  53. #endif
  54. #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
  55. enable_layerscape_ns_access();
  56. #endif
  57. #ifdef CONFIG_SPL_FSL_LS_PPA
  58. ppa_init();
  59. #endif
  60. }
  61. void board_init_f(ulong dummy)
  62. {
  63. icache_enable();
  64. /* Clear global data */
  65. memset((void *)gd, 0, sizeof(gd_t));
  66. board_early_init_f();
  67. timer_init();
  68. #ifdef CONFIG_ARCH_LS2080A
  69. env_init();
  70. #endif
  71. get_clocks();
  72. preloader_console_init();
  73. gd->bd = &bdata;
  74. #ifdef CONFIG_SYS_I2C
  75. #ifdef CONFIG_SPL_I2C_SUPPORT
  76. i2c_init_all();
  77. #endif
  78. #endif
  79. #ifdef CONFIG_VID
  80. init_func_vid();
  81. #endif
  82. dram_init();
  83. #ifdef CONFIG_SPL_FSL_LS_PPA
  84. #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
  85. #error Need secure RAM for PPA
  86. #endif
  87. /*
  88. * Secure memory location is determined in dram_init_banksize().
  89. * gd->ram_size is deducted by the size of secure ram.
  90. */
  91. dram_init_banksize();
  92. /*
  93. * After dram_init_bank_size(), we know U-Boot only uses the first
  94. * memory bank regardless how big the memory is.
  95. */
  96. gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
  97. /*
  98. * If PPA is loaded, U-Boot will resume running at EL2.
  99. * Cache and MMU will be enabled. Need a place for TLB.
  100. * U-Boot will be relocated to the end of available memory
  101. * in first bank. At this point, we cannot know how much
  102. * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
  103. * to avoid overlapping. As soon as the RAM version U-Boot sets
  104. * up new MMU, this space is no longer needed.
  105. */
  106. gd->ram_top -= SPL_TLB_SETBACK;
  107. gd->arch.tlb_size = PGTABLE_SIZE;
  108. gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
  109. gd->arch.tlb_allocated = gd->arch.tlb_addr;
  110. #endif /* CONFIG_SPL_FSL_LS_PPA */
  111. #if defined(CONFIG_QSPI_AHB_INIT) && defined(CONFIG_QSPI_BOOT)
  112. qspi_ahb_init();
  113. #endif
  114. }
  115. #ifdef CONFIG_SPL_OS_BOOT
  116. /*
  117. * Return
  118. * 0 if booting into OS is selected
  119. * 1 if booting into U-Boot is selected
  120. */
  121. int spl_start_uboot(void)
  122. {
  123. env_init();
  124. if (env_get_yesno("boot_os") != 0)
  125. return 0;
  126. return 1;
  127. }
  128. #endif /* CONFIG_SPL_OS_BOOT */
  129. #ifdef CONFIG_SPL_LOAD_FIT
  130. __weak int board_fit_config_name_match(const char *name)
  131. {
  132. /* Just empty function now - can't decide what to choose */
  133. debug("%s: %s\n", __func__, name);
  134. return 0;
  135. }
  136. #endif
  137. #endif /* CONFIG_SPL_BUILD */