bl2_main.c 4.1 KB

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