bl2_main.c 4.8 KB

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