1b4315306SDan Handley /* 2c228956aSSoby Mathew * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. 3b4315306SDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5b4315306SDan Handley */ 6b4315306SDan Handley 7d323af9eSDaniel Boulby #include <assert.h> 8*09d40e0eSAntonio Nino Diaz 94adb10c1SIsla Mitchell #include <platform_def.h> 10*09d40e0eSAntonio Nino Diaz 11*09d40e0eSAntonio Nino Diaz #include <arch.h> 12*09d40e0eSAntonio Nino Diaz #include <bl1/bl1.h> 13*09d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 14*09d40e0eSAntonio Nino Diaz #include <drivers/arm/sp805.h> 15*09d40e0eSAntonio Nino Diaz #include <lib/utils.h> 16*09d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h> 17*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 18*09d40e0eSAntonio Nino Diaz 19*09d40e0eSAntonio Nino Diaz #include <arm_def.h> 20*09d40e0eSAntonio Nino Diaz #include <plat_arm.h> 2103987d01SAntonio Nino Diaz 223ae8a360SSandrine Bailleux #include "../../../bl1/bl1_private.h" 23b4315306SDan Handley 24b4315306SDan Handley /* Weak definitions may be overridden in specific ARM standard platform */ 25b4315306SDan Handley #pragma weak bl1_early_platform_setup 26b4315306SDan Handley #pragma weak bl1_plat_arch_setup 27b4315306SDan Handley #pragma weak bl1_platform_setup 28b4315306SDan Handley #pragma weak bl1_plat_sec_mem_layout 2907570d59SYatharth Kochar #pragma weak bl1_plat_prepare_exit 304da6f6cdSSathees Balya #pragma weak bl1_plat_get_next_image_id 314da6f6cdSSathees Balya #pragma weak plat_arm_bl1_fwu_needed 32b4315306SDan Handley 33d323af9eSDaniel Boulby #define MAP_BL1_TOTAL MAP_REGION_FLAT( \ 34d323af9eSDaniel Boulby bl1_tzram_layout.total_base, \ 35d323af9eSDaniel Boulby bl1_tzram_layout.total_size, \ 36d323af9eSDaniel Boulby MT_MEMORY | MT_RW | MT_SECURE) 372ecaafd2SDaniel Boulby /* 382ecaafd2SDaniel Boulby * If SEPARATE_CODE_AND_RODATA=1 we define a region for each section 392ecaafd2SDaniel Boulby * otherwise one region is defined containing both 402ecaafd2SDaniel Boulby */ 412ecaafd2SDaniel Boulby #if SEPARATE_CODE_AND_RODATA 422ecaafd2SDaniel Boulby #define MAP_BL1_RO MAP_REGION_FLAT( \ 43d323af9eSDaniel Boulby BL_CODE_BASE, \ 44d323af9eSDaniel Boulby BL1_CODE_END - BL_CODE_BASE, \ 452ecaafd2SDaniel Boulby MT_CODE | MT_SECURE), \ 462ecaafd2SDaniel Boulby MAP_REGION_FLAT( \ 47d323af9eSDaniel Boulby BL1_RO_DATA_BASE, \ 48d323af9eSDaniel Boulby BL1_RO_DATA_END \ 49d323af9eSDaniel Boulby - BL_RO_DATA_BASE, \ 50d323af9eSDaniel Boulby MT_RO_DATA | MT_SECURE) 512ecaafd2SDaniel Boulby #else 522ecaafd2SDaniel Boulby #define MAP_BL1_RO MAP_REGION_FLAT( \ 532ecaafd2SDaniel Boulby BL_CODE_BASE, \ 542ecaafd2SDaniel Boulby BL1_CODE_END - BL_CODE_BASE, \ 552ecaafd2SDaniel Boulby MT_CODE | MT_SECURE) 562ecaafd2SDaniel Boulby #endif 57b4315306SDan Handley 58b4315306SDan Handley /* Data structure which holds the extents of the trusted SRAM for BL1*/ 59b4315306SDan Handley static meminfo_t bl1_tzram_layout; 60b4315306SDan Handley 616c77e749SSandrine Bailleux struct meminfo *bl1_plat_sec_mem_layout(void) 62b4315306SDan Handley { 63b4315306SDan Handley return &bl1_tzram_layout; 64b4315306SDan Handley } 65b4315306SDan Handley 66b4315306SDan Handley /******************************************************************************* 67b4315306SDan Handley * BL1 specific platform actions shared between ARM standard platforms. 68b4315306SDan Handley ******************************************************************************/ 69b4315306SDan Handley void arm_bl1_early_platform_setup(void) 70b4315306SDan Handley { 71b4315306SDan Handley 727b4c1405SJuan Castillo #if !ARM_DISABLE_TRUSTED_WDOG 737b4c1405SJuan Castillo /* Enable watchdog */ 747b4c1405SJuan Castillo sp805_start(ARM_SP805_TWDG_BASE, ARM_TWDG_LOAD_VAL); 757b4c1405SJuan Castillo #endif 767b4c1405SJuan Castillo 77b4315306SDan Handley /* Initialize the console to provide early debug support */ 7888a0523eSAntonio Nino Diaz arm_console_boot_init(); 79b4315306SDan Handley 80b4315306SDan Handley /* Allow BL1 to see the whole Trusted RAM */ 81b4315306SDan Handley bl1_tzram_layout.total_base = ARM_BL_RAM_BASE; 82b4315306SDan Handley bl1_tzram_layout.total_size = ARM_BL_RAM_SIZE; 83b4315306SDan Handley } 84b4315306SDan Handley 85b4315306SDan Handley void bl1_early_platform_setup(void) 86b4315306SDan Handley { 87b4315306SDan Handley arm_bl1_early_platform_setup(); 88b4315306SDan Handley 89b4315306SDan Handley /* 906355f234SVikram Kanigiri * Initialize Interconnect for this cluster during cold boot. 91b4315306SDan Handley * No need for locks as no other CPU is active. 92b4315306SDan Handley */ 936355f234SVikram Kanigiri plat_arm_interconnect_init(); 94b4315306SDan Handley /* 956355f234SVikram Kanigiri * Enable Interconnect coherency for the primary CPU's cluster. 96b4315306SDan Handley */ 976355f234SVikram Kanigiri plat_arm_interconnect_enter_coherency(); 98b4315306SDan Handley } 99b4315306SDan Handley 100b4315306SDan Handley /****************************************************************************** 101b4315306SDan Handley * Perform the very early platform specific architecture setup shared between 102b4315306SDan Handley * ARM standard platforms. This only does basic initialization. Later 103b4315306SDan Handley * architectural setup (bl1_arch_setup()) does not do anything platform 104b4315306SDan Handley * specific. 105b4315306SDan Handley *****************************************************************************/ 106b4315306SDan Handley void arm_bl1_plat_arch_setup(void) 107b4315306SDan Handley { 108943bb7f8SSoby Mathew #if USE_COHERENT_MEM && !ARM_CRYPTOCELL_INTEG 109943bb7f8SSoby Mathew /* 110943bb7f8SSoby Mathew * Ensure ARM platforms don't use coherent memory in BL1 unless 111943bb7f8SSoby Mathew * cryptocell integration is enabled. 112943bb7f8SSoby Mathew */ 113d323af9eSDaniel Boulby assert((BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE) == 0U); 114b4315306SDan Handley #endif 115d323af9eSDaniel Boulby 116d323af9eSDaniel Boulby const mmap_region_t bl_regions[] = { 117d323af9eSDaniel Boulby MAP_BL1_TOTAL, 1182ecaafd2SDaniel Boulby MAP_BL1_RO, 1191eb735d7SRoberto Vargas #if USE_ROMLIB 1201eb735d7SRoberto Vargas ARM_MAP_ROMLIB_CODE, 1211eb735d7SRoberto Vargas ARM_MAP_ROMLIB_DATA, 1221eb735d7SRoberto Vargas #endif 123943bb7f8SSoby Mathew #if ARM_CRYPTOCELL_INTEG 124943bb7f8SSoby Mathew ARM_MAP_BL_COHERENT_RAM, 125943bb7f8SSoby Mathew #endif 126d323af9eSDaniel Boulby {0} 127d323af9eSDaniel Boulby }; 128d323af9eSDaniel Boulby 1290916c38dSRoberto Vargas setup_page_tables(bl_regions, plat_arm_get_mmap()); 13083fc4a93SYatharth Kochar #ifdef AARCH32 1311e54cbb8SAntonio Nino Diaz enable_mmu_svc_mon(0); 13283fc4a93SYatharth Kochar #else 133b5fa6563SSandrine Bailleux enable_mmu_el3(0); 13483fc4a93SYatharth Kochar #endif /* AARCH32 */ 1351eb735d7SRoberto Vargas 1361eb735d7SRoberto Vargas arm_setup_romlib(); 137b4315306SDan Handley } 138b4315306SDan Handley 139b4315306SDan Handley void bl1_plat_arch_setup(void) 140b4315306SDan Handley { 141b4315306SDan Handley arm_bl1_plat_arch_setup(); 142b4315306SDan Handley } 143b4315306SDan Handley 144b4315306SDan Handley /* 145b4315306SDan Handley * Perform the platform specific architecture setup shared between 146b4315306SDan Handley * ARM standard platforms. 147b4315306SDan Handley */ 148b4315306SDan Handley void arm_bl1_platform_setup(void) 149b4315306SDan Handley { 150b4315306SDan Handley /* Initialise the IO layer and register platform IO devices */ 151b4315306SDan Handley plat_arm_io_setup(); 152c228956aSSoby Mathew arm_load_tb_fw_config(); 153ba597da7SJohn Tsichritzis #if TRUSTED_BOARD_BOOT 154ba597da7SJohn Tsichritzis /* Share the Mbed TLS heap info with other images */ 155ba597da7SJohn Tsichritzis arm_bl1_set_mbedtls_heap(); 156ba597da7SJohn Tsichritzis #endif /* TRUSTED_BOARD_BOOT */ 15760e19f57SAntonio Nino Diaz 1583208edcdSSoby Mathew /* 1593208edcdSSoby Mathew * Allow access to the System counter timer module and program 1603208edcdSSoby Mathew * counter frequency for non secure images during FWU 1613208edcdSSoby Mathew */ 1623208edcdSSoby Mathew arm_configure_sys_timer(); 1633208edcdSSoby Mathew write_cntfrq_el0(plat_get_syscnt_freq2()); 164b4315306SDan Handley } 165b4315306SDan Handley 166b4315306SDan Handley void bl1_platform_setup(void) 167b4315306SDan Handley { 168b4315306SDan Handley arm_bl1_platform_setup(); 169b4315306SDan Handley } 170b4315306SDan Handley 1714c117f6cSSandrine Bailleux void bl1_plat_prepare_exit(entry_point_info_t *ep_info) 1724c117f6cSSandrine Bailleux { 1737b4c1405SJuan Castillo #if !ARM_DISABLE_TRUSTED_WDOG 1747b4c1405SJuan Castillo /* Disable watchdog before leaving BL1 */ 1757b4c1405SJuan Castillo sp805_stop(ARM_SP805_TWDG_BASE); 1767b4c1405SJuan Castillo #endif 1777b4c1405SJuan Castillo 1784c117f6cSSandrine Bailleux #ifdef EL3_PAYLOAD_BASE 1794c117f6cSSandrine Bailleux /* 1804c117f6cSSandrine Bailleux * Program the EL3 payload's entry point address into the CPUs mailbox 1814c117f6cSSandrine Bailleux * in order to release secondary CPUs from their holding pen and make 1824c117f6cSSandrine Bailleux * them jump there. 1834c117f6cSSandrine Bailleux */ 1842a246d2eSDimitris Papastamos plat_arm_program_trusted_mailbox(ep_info->pc); 1854c117f6cSSandrine Bailleux dsbsy(); 1864c117f6cSSandrine Bailleux sev(); 1874c117f6cSSandrine Bailleux #endif 1884c117f6cSSandrine Bailleux } 1897b56928aSSoby Mathew 1904da6f6cdSSathees Balya /* 1914da6f6cdSSathees Balya * On Arm platforms, the FWU process is triggered when the FIP image has 1924da6f6cdSSathees Balya * been tampered with. 1934da6f6cdSSathees Balya */ 1944da6f6cdSSathees Balya int plat_arm_bl1_fwu_needed(void) 1954da6f6cdSSathees Balya { 1964da6f6cdSSathees Balya return (arm_io_is_toc_valid() != 1); 1974da6f6cdSSathees Balya } 1984da6f6cdSSathees Balya 1997b56928aSSoby Mathew /******************************************************************************* 2007b56928aSSoby Mathew * The following function checks if Firmware update is needed, 2017b56928aSSoby Mathew * by checking if TOC in FIP image is valid or not. 2027b56928aSSoby Mathew ******************************************************************************/ 2037b56928aSSoby Mathew unsigned int bl1_plat_get_next_image_id(void) 2047b56928aSSoby Mathew { 2054da6f6cdSSathees Balya if (plat_arm_bl1_fwu_needed() != 0) 2067b56928aSSoby Mathew return NS_BL1U_IMAGE_ID; 2077b56928aSSoby Mathew 2087b56928aSSoby Mathew return BL2_IMAGE_ID; 2097b56928aSSoby Mathew } 210