13fc4124cSDan Handley /* 2*0ab49645SAlexei Fedorov * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved. 33fc4124cSDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 53fc4124cSDan Handley */ 63fc4124cSDan Handley 7*0ab49645SAlexei Fedorov #include <assert.h> 8*0ab49645SAlexei Fedorov 9*0ab49645SAlexei Fedorov #include <bl1/bl1.h> 1009d40e0eSAntonio Nino Diaz #include <common/tbbr/tbbr_img_def.h> 111461ad9fSAlexei Fedorov #include <drivers/arm/smmu_v3.h> 12b0c97dafSAditya Angadi #include <drivers/arm/sp805.h> 131461ad9fSAlexei Fedorov #include <plat/arm/common/arm_config.h> 14bd9344f6SAntonio Nino Diaz #include <plat/arm/common/plat_arm.h> 15b0c97dafSAditya Angadi #include <plat/arm/common/arm_def.h> 1609d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 1709d40e0eSAntonio Nino Diaz #include "fvp_private.h" 183fc4124cSDan Handley 193fc4124cSDan Handley /******************************************************************************* 203fc4124cSDan Handley * Perform any BL1 specific platform actions. 213fc4124cSDan Handley ******************************************************************************/ 223fc4124cSDan Handley void bl1_early_platform_setup(void) 233fc4124cSDan Handley { 243fc4124cSDan Handley arm_bl1_early_platform_setup(); 253fc4124cSDan Handley 263fc4124cSDan Handley /* Initialize the platform config for future decision making */ 273fc4124cSDan Handley fvp_config_setup(); 283fc4124cSDan Handley 293fc4124cSDan Handley /* 306355f234SVikram Kanigiri * Initialize Interconnect for this cluster during cold boot. 313fc4124cSDan Handley * No need for locks as no other CPU is active. 323fc4124cSDan Handley */ 336355f234SVikram Kanigiri fvp_interconnect_init(); 343fc4124cSDan Handley /* 356355f234SVikram Kanigiri * Enable coherency in Interconnect for the primary CPU's cluster. 363fc4124cSDan Handley */ 376355f234SVikram Kanigiri fvp_interconnect_enable(); 383fc4124cSDan Handley } 39b0c97dafSAditya Angadi 40b0c97dafSAditya Angadi void plat_arm_secure_wdt_start(void) 41b0c97dafSAditya Angadi { 42b0c97dafSAditya Angadi sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL); 43b0c97dafSAditya Angadi } 44b0c97dafSAditya Angadi 45b0c97dafSAditya Angadi void plat_arm_secure_wdt_stop(void) 46b0c97dafSAditya Angadi { 47b0c97dafSAditya Angadi sp805_stop(ARM_SP805_TWDG_BASE); 48b0c97dafSAditya Angadi } 491461ad9fSAlexei Fedorov 501461ad9fSAlexei Fedorov void bl1_platform_setup(void) 511461ad9fSAlexei Fedorov { 521461ad9fSAlexei Fedorov arm_bl1_platform_setup(); 531461ad9fSAlexei Fedorov 541b597c22SAlexei Fedorov /* Initialize System level generic or SP804 timer */ 551b597c22SAlexei Fedorov fvp_timer_init(); 561b597c22SAlexei Fedorov 571461ad9fSAlexei Fedorov /* On FVP RevC, initialize SMMUv3 */ 581461ad9fSAlexei Fedorov if ((arm_config.flags & ARM_CONFIG_FVP_HAS_SMMUV3) != 0U) 591461ad9fSAlexei Fedorov smmuv3_security_init(PLAT_FVP_SMMUV3_BASE); 601461ad9fSAlexei Fedorov } 6137b70031SAmbroise Vincent 6237b70031SAmbroise Vincent __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) 6337b70031SAmbroise Vincent { 6437b70031SAmbroise Vincent /* Setup the watchdog to reset the system as soon as possible */ 6537b70031SAmbroise Vincent sp805_refresh(ARM_SP805_TWDG_BASE, 1U); 6637b70031SAmbroise Vincent 6737b70031SAmbroise Vincent while (1) 6837b70031SAmbroise Vincent wfi(); 6937b70031SAmbroise Vincent } 70*0ab49645SAlexei Fedorov 71*0ab49645SAlexei Fedorov #if MEASURED_BOOT 72*0ab49645SAlexei Fedorov /* 73*0ab49645SAlexei Fedorov * Implementation for bl1_plat_handle_post_image_load(). This function 74*0ab49645SAlexei Fedorov * populates the default arguments to BL2. The BL2 memory layout structure 75*0ab49645SAlexei Fedorov * is allocated and the calculated layout is populated in arg1 to BL2. 76*0ab49645SAlexei Fedorov */ 77*0ab49645SAlexei Fedorov int bl1_plat_handle_post_image_load(unsigned int image_id) 78*0ab49645SAlexei Fedorov { 79*0ab49645SAlexei Fedorov meminfo_t *bl2_tzram_layout; 80*0ab49645SAlexei Fedorov meminfo_t *bl1_tzram_layout; 81*0ab49645SAlexei Fedorov image_desc_t *image_desc; 82*0ab49645SAlexei Fedorov entry_point_info_t *ep_info; 83*0ab49645SAlexei Fedorov 84*0ab49645SAlexei Fedorov if (image_id != BL2_IMAGE_ID) { 85*0ab49645SAlexei Fedorov return 0; 86*0ab49645SAlexei Fedorov } 87*0ab49645SAlexei Fedorov 88*0ab49645SAlexei Fedorov /* Get the image descriptor */ 89*0ab49645SAlexei Fedorov image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); 90*0ab49645SAlexei Fedorov assert(image_desc != NULL); 91*0ab49645SAlexei Fedorov 92*0ab49645SAlexei Fedorov /* Calculate BL2 hash and set it in TB_FW_CONFIG */ 93*0ab49645SAlexei Fedorov arm_bl1_set_bl2_hash(image_desc); 94*0ab49645SAlexei Fedorov 95*0ab49645SAlexei Fedorov /* Get the entry point info */ 96*0ab49645SAlexei Fedorov ep_info = &image_desc->ep_info; 97*0ab49645SAlexei Fedorov 98*0ab49645SAlexei Fedorov /* Find out how much free trusted ram remains after BL1 load */ 99*0ab49645SAlexei Fedorov bl1_tzram_layout = bl1_plat_sec_mem_layout(); 100*0ab49645SAlexei Fedorov 101*0ab49645SAlexei Fedorov /* 102*0ab49645SAlexei Fedorov * Create a new layout of memory for BL2 as seen by BL1 i.e. 103*0ab49645SAlexei Fedorov * tell it the amount of total and free memory available. 104*0ab49645SAlexei Fedorov * This layout is created at the first free address visible 105*0ab49645SAlexei Fedorov * to BL2. BL2 will read the memory layout before using its 106*0ab49645SAlexei Fedorov * memory for other purposes. 107*0ab49645SAlexei Fedorov */ 108*0ab49645SAlexei Fedorov bl2_tzram_layout = (meminfo_t *)bl1_tzram_layout->total_base; 109*0ab49645SAlexei Fedorov 110*0ab49645SAlexei Fedorov bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); 111*0ab49645SAlexei Fedorov 112*0ab49645SAlexei Fedorov ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout; 113*0ab49645SAlexei Fedorov 114*0ab49645SAlexei Fedorov VERBOSE("BL1: BL2 memory layout address = %p\n", 115*0ab49645SAlexei Fedorov (void *)bl2_tzram_layout); 116*0ab49645SAlexei Fedorov return 0; 117*0ab49645SAlexei Fedorov } 118*0ab49645SAlexei Fedorov #endif /* MEASURED_BOOT */ 119