spl.c 3.3 KB

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