spl.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <spl.h>
  8. #include <asm/io.h>
  9. #include <fsl_ifc.h>
  10. #include <i2c.h>
  11. #include <fsl_csu.h>
  12. #include <asm/arch/fdt.h>
  13. #include <asm/arch/ppa.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. u32 spl_boot_device(void)
  16. {
  17. #ifdef CONFIG_SPL_MMC_SUPPORT
  18. return BOOT_DEVICE_MMC1;
  19. #endif
  20. #ifdef CONFIG_SPL_NAND_SUPPORT
  21. return BOOT_DEVICE_NAND;
  22. #endif
  23. return 0;
  24. }
  25. u32 spl_boot_mode(const u32 boot_device)
  26. {
  27. switch (spl_boot_device()) {
  28. case BOOT_DEVICE_MMC1:
  29. #ifdef CONFIG_SPL_FAT_SUPPORT
  30. return MMCSD_MODE_FS;
  31. #else
  32. return MMCSD_MODE_RAW;
  33. #endif
  34. case BOOT_DEVICE_NAND:
  35. return 0;
  36. default:
  37. puts("spl: error: unsupported device\n");
  38. hang();
  39. }
  40. }
  41. #ifdef CONFIG_SPL_BUILD
  42. void spl_board_init(void)
  43. {
  44. #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_LSCH2)
  45. /*
  46. * In case of Secure Boot, the IBR configures the SMMU
  47. * to allow only Secure transactions.
  48. * SMMU must be reset in bypass mode.
  49. * Set the ClientPD bit and Clear the USFCFG Bit
  50. */
  51. u32 val;
  52. val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  53. out_le32(SMMU_SCR0, val);
  54. val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  55. out_le32(SMMU_NSCR0, val);
  56. #endif
  57. #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
  58. enable_layerscape_ns_access();
  59. #endif
  60. #ifdef CONFIG_SPL_FSL_LS_PPA
  61. ppa_init();
  62. #endif
  63. }
  64. void board_init_f(ulong dummy)
  65. {
  66. /* Clear global data */
  67. memset((void *)gd, 0, sizeof(gd_t));
  68. board_early_init_f();
  69. timer_init();
  70. #ifdef CONFIG_ARCH_LS2080A
  71. env_init();
  72. #endif
  73. get_clocks();
  74. preloader_console_init();
  75. spl_set_bd();
  76. #ifdef CONFIG_SPL_I2C_SUPPORT
  77. i2c_init_all();
  78. #endif
  79. dram_init();
  80. #ifdef CONFIG_SPL_FSL_LS_PPA
  81. #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
  82. #error Need secure RAM for PPA
  83. #endif
  84. /*
  85. * Secure memory location is determined in dram_init_banksize().
  86. * gd->ram_size is deducted by the size of secure ram.
  87. */
  88. dram_init_banksize();
  89. /*
  90. * After dram_init_bank_size(), we know U-Boot only uses the first
  91. * memory bank regardless how big the memory is.
  92. */
  93. gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
  94. /*
  95. * If PPA is loaded, U-Boot will resume running at EL2.
  96. * Cache and MMU will be enabled. Need a place for TLB.
  97. * U-Boot will be relocated to the end of available memory
  98. * in first bank. At this point, we cannot know how much
  99. * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
  100. * to avoid overlapping. As soon as the RAM version U-Boot sets
  101. * up new MMU, this space is no longer needed.
  102. */
  103. gd->ram_top -= SPL_TLB_SETBACK;
  104. gd->arch.tlb_size = PGTABLE_SIZE;
  105. gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
  106. gd->arch.tlb_allocated = gd->arch.tlb_addr;
  107. #endif /* CONFIG_SPL_FSL_LS_PPA */
  108. }
  109. #endif /* CONFIG_SPL_BUILD */