hikey_bl1_setup.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <inttypes.h>
  9. #include <stdint.h>
  10. #include <string.h>
  11. #include <arch_helpers.h>
  12. #include <bl1/tbbr/tbbr_img_desc.h>
  13. #include <common/bl_common.h>
  14. #include <common/debug.h>
  15. #include <drivers/arm/pl011.h>
  16. #include <drivers/mmc.h>
  17. #include <drivers/synopsys/dw_mmc.h>
  18. #include <lib/mmio.h>
  19. #include <plat/common/platform.h>
  20. #include <hi6220.h>
  21. #include <hikey_def.h>
  22. #include <hikey_layout.h>
  23. #include "hikey_private.h"
  24. /* Data structure which holds the extents of the trusted RAM for BL1 */
  25. static meminfo_t bl1_tzram_layout;
  26. static console_t console;
  27. static struct mmc_device_info mmc_info;
  28. enum {
  29. BOOT_NORMAL = 0,
  30. BOOT_USB_DOWNLOAD,
  31. BOOT_UART_DOWNLOAD,
  32. };
  33. meminfo_t *bl1_plat_sec_mem_layout(void)
  34. {
  35. return &bl1_tzram_layout;
  36. }
  37. /*
  38. * Perform any BL1 specific platform actions.
  39. */
  40. void bl1_early_platform_setup(void)
  41. {
  42. /* Initialize the console to provide early debug support */
  43. console_pl011_register(CONSOLE_BASE, PL011_UART_CLK_IN_HZ,
  44. PL011_BAUDRATE, &console);
  45. /* Allow BL1 to see the whole Trusted RAM */
  46. bl1_tzram_layout.total_base = BL1_RW_BASE;
  47. bl1_tzram_layout.total_size = BL1_RW_SIZE;
  48. INFO("BL1: 0x%lx - 0x%lx [size = %lu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
  49. BL1_RAM_LIMIT - BL1_RAM_BASE); /* bl1_size */
  50. }
  51. /*
  52. * Perform the very early platform specific architecture setup here. At the
  53. * moment this only does basic initialization. Later architectural setup
  54. * (bl1_arch_setup()) does not do anything platform specific.
  55. */
  56. void bl1_plat_arch_setup(void)
  57. {
  58. hikey_init_mmu_el3(bl1_tzram_layout.total_base,
  59. bl1_tzram_layout.total_size,
  60. BL1_RO_BASE,
  61. BL1_RO_LIMIT,
  62. BL_COHERENT_RAM_BASE,
  63. BL_COHERENT_RAM_END);
  64. }
  65. /*
  66. * Function which will perform any remaining platform-specific setup that can
  67. * occur after the MMU and data cache have been enabled.
  68. */
  69. void bl1_platform_setup(void)
  70. {
  71. dw_mmc_params_t params;
  72. assert((HIKEY_BL1_MMC_DESC_BASE >= SRAM_BASE) &&
  73. ((SRAM_BASE + SRAM_SIZE) >=
  74. (HIKEY_BL1_MMC_DATA_BASE + HIKEY_BL1_MMC_DATA_SIZE)));
  75. hikey_sp804_init();
  76. hikey_gpio_init();
  77. hikey_pmussi_init();
  78. hikey_hi6553_init();
  79. hikey_rtc_init();
  80. hikey_mmc_pll_init();
  81. memset(&params, 0, sizeof(dw_mmc_params_t));
  82. params.reg_base = DWMMC0_BASE;
  83. params.desc_base = HIKEY_BL1_MMC_DESC_BASE;
  84. params.desc_size = 1 << 20;
  85. params.clk_rate = 24 * 1000 * 1000;
  86. params.bus_width = MMC_BUS_WIDTH_8;
  87. params.flags = MMC_FLAG_CMD23;
  88. mmc_info.mmc_dev_type = MMC_IS_EMMC;
  89. dw_mmc_init(&params, &mmc_info);
  90. hikey_io_setup();
  91. }
  92. /*
  93. * The following function checks if Firmware update is needed,
  94. * by checking if TOC in FIP image is valid or not.
  95. */
  96. unsigned int bl1_plat_get_next_image_id(void)
  97. {
  98. int32_t boot_mode;
  99. unsigned int ret;
  100. boot_mode = mmio_read_32(ONCHIPROM_PARAM_BASE);
  101. switch (boot_mode) {
  102. case BOOT_USB_DOWNLOAD:
  103. case BOOT_UART_DOWNLOAD:
  104. ret = NS_BL1U_IMAGE_ID;
  105. break;
  106. default:
  107. WARN("Invalid boot mode is found:%d\n", boot_mode);
  108. panic();
  109. }
  110. return ret;
  111. }
  112. image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
  113. {
  114. unsigned int index = 0;
  115. while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
  116. if (bl1_tbbr_image_descs[index].image_id == image_id)
  117. return &bl1_tbbr_image_descs[index];
  118. index++;
  119. }
  120. return NULL;
  121. }
  122. void bl1_plat_set_ep_info(unsigned int image_id,
  123. entry_point_info_t *ep_info)
  124. {
  125. uint64_t data = 0;
  126. if (image_id == BL2_IMAGE_ID)
  127. panic();
  128. inv_dcache_range(NS_BL1U_BASE, NS_BL1U_SIZE);
  129. __asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
  130. do {
  131. data |= 3 << 20;
  132. __asm__ volatile ("msr cpacr_el1, %0" : : "r"(data));
  133. __asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
  134. } while ((data & (3 << 20)) != (3 << 20));
  135. INFO("cpacr_el1:0x%" PRIx64 "\n", data);
  136. ep_info->args.arg0 = 0xffff & read_mpidr();
  137. ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
  138. DISABLE_ALL_EXCEPTIONS);
  139. }