bl2_main.c 4.1 KB

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