123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- #include <assert.h>
- #include <platform_def.h>
- #include <arch.h>
- #include <arch_features.h>
- #include <arch_helpers.h>
- #include <bl1/bl1.h>
- #include <common/bl_common.h>
- #include <common/build_message.h>
- #include <common/debug.h>
- #include <drivers/auth/auth_mod.h>
- #include <drivers/auth/crypto_mod.h>
- #include <drivers/console.h>
- #include <lib/bootmarker_capture.h>
- #include <lib/cpus/errata.h>
- #include <lib/pmf/pmf.h>
- #include <lib/utils.h>
- #include <plat/common/platform.h>
- #include <smccc_helpers.h>
- #include <tools_share/uuid.h>
- #include "bl1_private.h"
- static void bl1_load_bl2(void);
- #if ENABLE_PAUTH
- uint64_t bl1_apiakey[2];
- #endif
- #if ENABLE_RUNTIME_INSTRUMENTATION
- PMF_REGISTER_SERVICE(bl_svc, PMF_RT_INSTR_SVC_ID,
- BL_TOTAL_IDS, PMF_DUMP_ENABLE)
- #endif
- void bl1_setup(void)
- {
-
- plat_setup_early_console();
-
- bl1_early_platform_setup();
-
- bl1_plat_arch_setup();
- #if CTX_INCLUDE_PAUTH_REGS
-
- assert(is_armv8_3_pauth_present());
- #endif
- }
- void bl1_main(void)
- {
- unsigned int image_id;
- #if ENABLE_RUNTIME_INSTRUMENTATION
- PMF_CAPTURE_TIMESTAMP(bl_svc, BL1_ENTRY, PMF_CACHE_MAINT);
- #endif
-
- NOTICE(FIRMWARE_WELCOME_STR);
- NOTICE("BL1: %s\n", build_version_string);
- NOTICE("BL1: %s\n", build_message);
- INFO("BL1: RAM %p - %p\n", (void *)BL1_RAM_BASE, (void *)BL1_RAM_LIMIT);
- print_errata_status();
- #if ENABLE_ASSERTIONS
- u_register_t val;
-
- #ifdef __aarch64__
- val = read_sctlr_el3();
- #else
- val = read_sctlr();
- #endif
- assert((val & SCTLR_M_BIT) != 0);
- assert((val & SCTLR_C_BIT) != 0);
- assert((val & SCTLR_I_BIT) != 0);
-
- val = (read_ctr_el0() >> CTR_CWG_SHIFT) & CTR_CWG_MASK;
-
- if (val != 0)
- assert(CACHE_WRITEBACK_GRANULE == SIZE_FROM_LOG2_WORDS(val));
- else
- assert(CACHE_WRITEBACK_GRANULE <= MAX_CACHE_LINE_SIZE);
- #endif
-
- bl1_arch_setup();
- crypto_mod_init();
-
- auth_mod_init();
-
- bl1_plat_mboot_init();
-
- bl1_platform_setup();
- #if ENABLE_PAUTH
-
- bl1_apiakey[0] = read_apiakeylo_el1();
- bl1_apiakey[1] = read_apiakeyhi_el1();
- #endif
-
- image_id = bl1_plat_get_next_image_id();
-
- if (image_id == BL2_IMAGE_ID)
- bl1_load_bl2();
- else
- NOTICE("BL1-FWU: *******FWU Process Started*******\n");
-
- bl1_plat_mboot_finish();
- bl1_prepare_next_image(image_id);
- #if ENABLE_RUNTIME_INSTRUMENTATION
- PMF_CAPTURE_TIMESTAMP(bl_svc, BL1_EXIT, PMF_CACHE_MAINT);
- #endif
- console_flush();
- }
- static void bl1_load_bl2(void)
- {
- image_desc_t *desc;
- image_info_t *info;
- int err;
-
- desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
- assert(desc != NULL);
-
- info = &desc->image_info;
- INFO("BL1: Loading BL2\n");
- err = bl1_plat_handle_pre_image_load(BL2_IMAGE_ID);
- if (err != 0) {
- ERROR("Failure in pre image load handling of BL2 (%d)\n", err);
- plat_error_handler(err);
- }
- err = load_auth_image(BL2_IMAGE_ID, info);
- if (err != 0) {
- ERROR("Failed to load BL2 firmware.\n");
- plat_error_handler(err);
- }
-
- err = bl1_plat_handle_post_image_load(BL2_IMAGE_ID);
- if (err != 0) {
- ERROR("Failure in post image load handling of BL2 (%d)\n", err);
- plat_error_handler(err);
- }
- NOTICE("BL1: Booting BL2\n");
- }
- void bl1_print_next_bl_ep_info(const entry_point_info_t *bl_ep_info)
- {
- #ifdef __aarch64__
- NOTICE("BL1: Booting BL31\n");
- #else
- NOTICE("BL1: Booting BL32\n");
- #endif
- print_entry_point_info(bl_ep_info);
- }
- #if SPIN_ON_BL1_EXIT
- void print_debug_loop_message(void)
- {
- NOTICE("BL1: Debug loop, spinning forever\n");
- NOTICE("BL1: Please connect the debugger to continue\n");
- }
- #endif
- u_register_t bl1_smc_handler(unsigned int smc_fid,
- u_register_t x1,
- u_register_t x2,
- u_register_t x3,
- u_register_t x4,
- void *cookie,
- void *handle,
- unsigned int flags)
- {
-
- DEFINE_SVC_UUID2(bl1_svc_uid,
- U(0xd46739fd), 0xcb72, 0x9a4d, 0xb5, 0x75,
- 0x67, 0x15, 0xd6, 0xf4, 0xbb, 0x4a);
- #if TRUSTED_BOARD_BOOT
-
- if (is_fwu_fid(smc_fid)) {
- return bl1_fwu_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
- handle, flags);
- }
- #endif
- switch (smc_fid) {
- case BL1_SMC_CALL_COUNT:
- SMC_RET1(handle, BL1_NUM_SMC_CALLS);
- case BL1_SMC_UID:
- SMC_UUID_RET(handle, bl1_svc_uid);
- case BL1_SMC_VERSION:
- SMC_RET1(handle, BL1_SMC_MAJOR_VER | BL1_SMC_MINOR_VER);
- default:
- WARN("Unimplemented BL1 SMC Call: 0x%x\n", smc_fid);
- SMC_RET1(handle, SMC_UNK);
- }
- }
- u_register_t bl1_smc_wrapper(uint32_t smc_fid,
- void *cookie,
- void *handle,
- unsigned int flags)
- {
- u_register_t x1, x2, x3, x4;
- assert(handle != NULL);
- get_smc_params_from_ctx(handle, x1, x2, x3, x4);
- return bl1_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
- }
|