13fc4124cSDan Handley /* 20ab49645SAlexei 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 70ab49645SAlexei Fedorov #include <assert.h> 80ab49645SAlexei Fedorov 90ab49645SAlexei 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 } 700ab49645SAlexei Fedorov 710ab49645SAlexei Fedorov #if MEASURED_BOOT 720ab49645SAlexei Fedorov /* 73*4a135bc3SAlexei Fedorov * Calculates and writes BL2 hash data to TB_FW_CONFIG DTB. 74*4a135bc3SAlexei Fedorov */ 75*4a135bc3SAlexei Fedorov void bl1_plat_set_bl2_hash(const image_desc_t *image_desc) 76*4a135bc3SAlexei Fedorov { 77*4a135bc3SAlexei Fedorov arm_bl1_set_bl2_hash(image_desc); 78*4a135bc3SAlexei Fedorov } 79*4a135bc3SAlexei Fedorov 80*4a135bc3SAlexei Fedorov /* 810ab49645SAlexei Fedorov * Implementation for bl1_plat_handle_post_image_load(). This function 820ab49645SAlexei Fedorov * populates the default arguments to BL2. The BL2 memory layout structure 830ab49645SAlexei Fedorov * is allocated and the calculated layout is populated in arg1 to BL2. 840ab49645SAlexei Fedorov */ 850ab49645SAlexei Fedorov int bl1_plat_handle_post_image_load(unsigned int image_id) 860ab49645SAlexei Fedorov { 870ab49645SAlexei Fedorov meminfo_t *bl2_tzram_layout; 880ab49645SAlexei Fedorov meminfo_t *bl1_tzram_layout; 890ab49645SAlexei Fedorov image_desc_t *image_desc; 900ab49645SAlexei Fedorov entry_point_info_t *ep_info; 910ab49645SAlexei Fedorov 920ab49645SAlexei Fedorov if (image_id != BL2_IMAGE_ID) { 930ab49645SAlexei Fedorov return 0; 940ab49645SAlexei Fedorov } 950ab49645SAlexei Fedorov 960ab49645SAlexei Fedorov /* Get the image descriptor */ 970ab49645SAlexei Fedorov image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); 980ab49645SAlexei Fedorov assert(image_desc != NULL); 990ab49645SAlexei Fedorov 1000ab49645SAlexei Fedorov /* Calculate BL2 hash and set it in TB_FW_CONFIG */ 101*4a135bc3SAlexei Fedorov bl1_plat_set_bl2_hash(image_desc); 1020ab49645SAlexei Fedorov 1030ab49645SAlexei Fedorov /* Get the entry point info */ 1040ab49645SAlexei Fedorov ep_info = &image_desc->ep_info; 1050ab49645SAlexei Fedorov 1060ab49645SAlexei Fedorov /* Find out how much free trusted ram remains after BL1 load */ 1070ab49645SAlexei Fedorov bl1_tzram_layout = bl1_plat_sec_mem_layout(); 1080ab49645SAlexei Fedorov 1090ab49645SAlexei Fedorov /* 1100ab49645SAlexei Fedorov * Create a new layout of memory for BL2 as seen by BL1 i.e. 1110ab49645SAlexei Fedorov * tell it the amount of total and free memory available. 1120ab49645SAlexei Fedorov * This layout is created at the first free address visible 1130ab49645SAlexei Fedorov * to BL2. BL2 will read the memory layout before using its 1140ab49645SAlexei Fedorov * memory for other purposes. 1150ab49645SAlexei Fedorov */ 1160ab49645SAlexei Fedorov bl2_tzram_layout = (meminfo_t *)bl1_tzram_layout->total_base; 1170ab49645SAlexei Fedorov 1180ab49645SAlexei Fedorov bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); 1190ab49645SAlexei Fedorov 1200ab49645SAlexei Fedorov ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout; 1210ab49645SAlexei Fedorov 1220ab49645SAlexei Fedorov VERBOSE("BL1: BL2 memory layout address = %p\n", 1230ab49645SAlexei Fedorov (void *)bl2_tzram_layout); 1240ab49645SAlexei Fedorov return 0; 1250ab49645SAlexei Fedorov } 1260ab49645SAlexei Fedorov #endif /* MEASURED_BOOT */ 127