bl2_main.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch_helpers.h>
  8. #include <arch_features.h>
  9. #include <bl1/bl1.h>
  10. #include <bl2/bl2.h>
  11. #include <common/bl_common.h>
  12. #include <common/debug.h>
  13. #include <drivers/auth/auth_mod.h>
  14. #include <drivers/auth/crypto_mod.h>
  15. #include <drivers/console.h>
  16. #include <drivers/fwu/fwu.h>
  17. #include <lib/bootmarker_capture.h>
  18. #include <lib/extensions/pauth.h>
  19. #include <lib/pmf/pmf.h>
  20. #include <plat/common/platform.h>
  21. #include "bl2_private.h"
  22. #ifdef __aarch64__
  23. #define NEXT_IMAGE "BL31"
  24. #else
  25. #define NEXT_IMAGE "BL32"
  26. #endif
  27. #if ENABLE_RUNTIME_INSTRUMENTATION
  28. PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID,
  29. BL_TOTAL_IDS, PMF_DUMP_ENABLE);
  30. #endif
  31. #if RESET_TO_BL2
  32. /*******************************************************************************
  33. * Setup function for BL2 when RESET_TO_BL2=1
  34. ******************************************************************************/
  35. void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
  36. u_register_t arg3)
  37. {
  38. /* Perform early platform-specific setup */
  39. bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3);
  40. /* Perform late platform-specific setup */
  41. bl2_el3_plat_arch_setup();
  42. #if CTX_INCLUDE_PAUTH_REGS
  43. /*
  44. * Assert that the ARMv8.3-PAuth registers are present or an access
  45. * fault will be triggered when they are being saved or restored.
  46. */
  47. assert(is_armv8_3_pauth_present());
  48. #endif /* CTX_INCLUDE_PAUTH_REGS */
  49. }
  50. #else /* RESET_TO_BL2 */
  51. /*******************************************************************************
  52. * Setup function for BL2 when RESET_TO_BL2=0
  53. ******************************************************************************/
  54. void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
  55. u_register_t arg3)
  56. {
  57. /* Perform early platform-specific setup */
  58. bl2_early_platform_setup2(arg0, arg1, arg2, arg3);
  59. /* Perform late platform-specific setup */
  60. bl2_plat_arch_setup();
  61. #if CTX_INCLUDE_PAUTH_REGS
  62. /*
  63. * Assert that the ARMv8.3-PAuth registers are present or an access
  64. * fault will be triggered when they are being saved or restored.
  65. */
  66. assert(is_armv8_3_pauth_present());
  67. #endif /* CTX_INCLUDE_PAUTH_REGS */
  68. }
  69. #endif /* RESET_TO_BL2 */
  70. /*******************************************************************************
  71. * The only thing to do in BL2 is to load further images and pass control to
  72. * next BL. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2
  73. * runs entirely in S-EL1.
  74. ******************************************************************************/
  75. void bl2_main(void)
  76. {
  77. entry_point_info_t *next_bl_ep_info;
  78. #if ENABLE_RUNTIME_INSTRUMENTATION
  79. PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_ENTRY, PMF_CACHE_MAINT);
  80. #endif
  81. NOTICE("BL2: %s\n", version_string);
  82. NOTICE("BL2: %s\n", build_message);
  83. /* Perform remaining generic architectural setup in S-EL1 */
  84. bl2_arch_setup();
  85. #if PSA_FWU_SUPPORT
  86. fwu_init();
  87. #endif /* PSA_FWU_SUPPORT */
  88. crypto_mod_init();
  89. /* Initialize authentication module */
  90. auth_mod_init();
  91. /* Initialize the Measured Boot backend */
  92. bl2_plat_mboot_init();
  93. /* Initialize boot source */
  94. bl2_plat_preload_setup();
  95. /* Load the subsequent bootloader images. */
  96. next_bl_ep_info = bl2_load_images();
  97. /* Teardown the Measured Boot backend */
  98. bl2_plat_mboot_finish();
  99. #if !BL2_RUNS_AT_EL3
  100. #ifndef __aarch64__
  101. /*
  102. * For AArch32 state BL1 and BL2 share the MMU setup.
  103. * Given that BL2 does not map BL1 regions, MMU needs
  104. * to be disabled in order to go back to BL1.
  105. */
  106. disable_mmu_icache_secure();
  107. #endif /* !__aarch64__ */
  108. #if ENABLE_PAUTH
  109. /*
  110. * Disable pointer authentication before running next boot image
  111. */
  112. pauth_disable_el1();
  113. #endif /* ENABLE_PAUTH */
  114. #if ENABLE_RUNTIME_INSTRUMENTATION
  115. PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
  116. #endif
  117. console_flush();
  118. /*
  119. * Run next BL image via an SMC to BL1. Information on how to pass
  120. * control to the BL32 (if present) and BL33 software images will
  121. * be passed to next BL image as an argument.
  122. */
  123. smc(BL1_SMC_RUN_IMAGE, (unsigned long)next_bl_ep_info, 0, 0, 0, 0, 0, 0);
  124. #else /* if BL2_RUNS_AT_EL3 */
  125. NOTICE("BL2: Booting " NEXT_IMAGE "\n");
  126. print_entry_point_info(next_bl_ep_info);
  127. #if ENABLE_RUNTIME_INSTRUMENTATION
  128. PMF_CAPTURE_TIMESTAMP(bl_svc, BL2_EXIT, PMF_CACHE_MAINT);
  129. #endif
  130. console_flush();
  131. #if ENABLE_PAUTH
  132. /*
  133. * Disable pointer authentication before running next boot image
  134. */
  135. pauth_disable_el3();
  136. #endif /* ENABLE_PAUTH */
  137. bl2_run_next_image(next_bl_ep_info);
  138. #endif /* BL2_RUNS_AT_EL3 */
  139. }