spl.c 3.3 KB

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