diff options
-rw-r--r-- | bl1/aarch64/bl1_arch_setup.c | 2 | ||||
-rw-r--r-- | bl31/aarch64/bl31_arch_setup.c | 3 | ||||
-rw-r--r-- | bl31/aarch64/crash_reporting.S | 4 | ||||
-rw-r--r-- | common/context_mgmt.c | 5 | ||||
-rw-r--r-- | docs/firmware-design.md | 5 | ||||
-rw-r--r-- | docs/user-guide.md | 9 | ||||
-rw-r--r-- | include/common/el3_common_macros.S | 11 | ||||
-rw-r--r-- | include/lib/aarch64/arch.h | 5 | ||||
-rw-r--r-- | include/lib/aarch64/arch_helpers.h | 9 | ||||
-rw-r--r-- | include/plat/arm/board/common/board_arm_def.h | 6 | ||||
-rw-r--r-- | include/plat/arm/common/arm_def.h | 39 | ||||
-rw-r--r-- | plat/arm/board/fvp/aarch64/fvp_common.c | 3 | ||||
-rw-r--r-- | plat/arm/board/fvp/include/platform_def.h | 6 | ||||
-rw-r--r-- | plat/arm/common/arm_bl2_setup.c | 20 | ||||
-rw-r--r-- | plat/arm/common/arm_common.mk | 5 | ||||
-rw-r--r-- | plat/mediatek/mt8173/bl31_plat_setup.c | 18 | ||||
-rw-r--r-- | plat/mediatek/mt8173/drivers/spm/spm.c | 4 | ||||
-rw-r--r-- | plat/mediatek/mt8173/include/mt8173_def.h | 10 |
18 files changed, 131 insertions, 33 deletions
diff --git a/bl1/aarch64/bl1_arch_setup.c b/bl1/aarch64/bl1_arch_setup.c index 6a3f0623..61c01e19 100644 --- a/bl1/aarch64/bl1_arch_setup.c +++ b/bl1/aarch64/bl1_arch_setup.c @@ -38,7 +38,7 @@ void bl1_arch_setup(void) { /* Set the next EL to be AArch64 */ - write_scr_el3(SCR_RES1_BITS | SCR_RW_BIT); + write_scr_el3(read_scr_el3() | SCR_RW_BIT); } /******************************************************************************* diff --git a/bl31/aarch64/bl31_arch_setup.c b/bl31/aarch64/bl31_arch_setup.c index edf10188..0871b419 100644 --- a/bl31/aarch64/bl31_arch_setup.c +++ b/bl31/aarch64/bl31_arch_setup.c @@ -43,9 +43,6 @@ ******************************************************************************/ void bl31_arch_setup(void) { - /* Set the RES1 bits in the SCR_EL3 */ - write_scr_el3(SCR_RES1_BITS); - /* Program the counter frequency */ write_cntfrq_el0(plat_get_syscnt_freq()); diff --git a/bl31/aarch64/crash_reporting.S b/bl31/aarch64/crash_reporting.S index ff915728..b22ce71e 100644 --- a/bl31/aarch64/crash_reporting.S +++ b/bl31/aarch64/crash_reporting.S @@ -70,7 +70,8 @@ non_el3_sys_regs: "tpidrro_el0", "dacr32_el2", "ifsr32_el2", "par_el1",\ "mpidr_el1", "afsr0_el1", "afsr1_el1", "contextidr_el1",\ "vbar_el1", "cntp_ctl_el0", "cntp_cval_el0", "cntv_ctl_el0",\ - "cntv_cval_el0", "cntkctl_el1", "fpexc32_el2", "sp_el0", "" + "cntv_cval_el0", "cntkctl_el1", "fpexc32_el2", "sp_el0",\ + "isr_el1", "" panic_msg: .asciz "PANIC in EL3 at x30 = 0x" @@ -338,6 +339,7 @@ func do_crash_reporting mrs x8, cntkctl_el1 mrs x9, fpexc32_el2 mrs x10, sp_el0 + mrs x11, isr_el1 bl str_in_crash_buf_print /* Get the cpu specific registers to report */ diff --git a/common/context_mgmt.c b/common/context_mgmt.c index 68ec8945..586d42a4 100644 --- a/common/context_mgmt.c +++ b/common/context_mgmt.c @@ -111,6 +111,11 @@ static void cm_init_context_common(cpu_context_t *ctx, const entry_point_info_t if (EP_GET_ST(ep->h.attr)) scr_el3 |= SCR_ST_BIT; +#ifndef HANDLE_EA_EL3_FIRST + /* Explicitly stop to trap aborts from lower exception levels. */ + scr_el3 &= ~SCR_EA_BIT; +#endif + #if IMAGE_BL31 /* * IRQ/FIQ bits only need setting if interrupt routing diff --git a/docs/firmware-design.md b/docs/firmware-design.md index 54c50680..fe3c3f03 100644 --- a/docs/firmware-design.md +++ b/docs/firmware-design.md @@ -174,8 +174,9 @@ BL1 performs minimal architectural initialization as follows. `SCTLR_EL3.A` and `SCTLR_EL3.SA` bits. Exception endianness is set to little-endian by clearing the `SCTLR_EL3.EE` bit. - - `SCR_EL3`. The register width of the next lower exception level is set to - AArch64 by setting the `SCR.RW` bit. + - `SCR_EL3`. The register width of the next lower exception level is set + to AArch64 by setting the `SCR.RW` bit. The `SCR.EA` bit is set to trap + both External Aborts and SError Interrupts in EL3. - `CPTR_EL3`. Accesses to the `CPACR_EL1` register from EL1 or EL2, or the `CPTR_EL2` register from EL2 are configured to not trap to EL3 by diff --git a/docs/user-guide.md b/docs/user-guide.md index ea10a81e..37e20346 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -439,6 +439,9 @@ performed. where applicable). Defaults to a string that contains the time and date of the compilation. +* `HANDLE_EA_EL3_FIRST`: When defined External Aborts and SError Interrupts + will be always trapped in EL3 i.e. in BL31 at runtime. + #### ARM development platform specific build options * `ARM_TSP_RAM_LOCATION`: location of the TSP binary. Options: @@ -495,6 +498,12 @@ map is explained in the [Firmware Design]. that wish to optimise memory usage for page tables need to set this flag to 1 and must override the related macros. +* 'ARM_BL31_IN_DRAM': Boolean option to select loading of BL31 in TZC secured + DRAM. By default, BL31 is in the secure SRAM. Set this flag to 1 to load + BL31 in TZC secured DRAM. If TSP is present, then setting this option also + sets the TSP location to DRAM and ignores the `ARM_TSP_RAM_LOCATION` build + flag. + #### ARM CSS platform specific build options * `CSS_DETECT_PRE_1_7_0_SCP`: Boolean flag to detect SCP version diff --git a/include/common/el3_common_macros.S b/include/common/el3_common_macros.S index 0cd85c34..ba80d95d 100644 --- a/include/common/el3_common_macros.S +++ b/include/common/el3_common_macros.S @@ -70,8 +70,15 @@ isb /* --------------------------------------------------------------------- - * Enable the SError interrupt now that the exception vectors have been - * setup. + * Early set RES1 bits in SCR_EL3. Set EA bit as well to catch both + * External Aborts and SError Interrupts in EL3. + * --------------------------------------------------------------------- + */ + mov x0, #(SCR_RES1_BITS | SCR_EA_BIT) + msr scr_el3, x0 + /* --------------------------------------------------------------------- + * Enable External Aborts and SError Interrupts now that the exception + * vectors have been setup. * --------------------------------------------------------------------- */ msr daifclr, #DAIF_ABT_BIT diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h index a9b2dbb2..f9b8ed6a 100644 --- a/include/lib/aarch64/arch.h +++ b/include/lib/aarch64/arch.h @@ -186,6 +186,11 @@ #define HCR_IMO_BIT (1 << 4) #define HCR_FMO_BIT (1 << 3) +/* ISR definitions */ +#define ISR_A_SHIFT 8 +#define ISR_I_SHIFT 7 +#define ISR_F_SHIFT 6 + /* CNTHCTL_EL2 definitions */ #define EVNTEN_BIT (1 << 2) #define EL1PCEN_BIT (1 << 1) diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h index 8be27cd5..f9f0715f 100644 --- a/include/lib/aarch64/arch_helpers.h +++ b/include/lib/aarch64/arch_helpers.h @@ -159,15 +159,6 @@ void disable_mmu_icache_el3(void); DEFINE_SYSREG_WRITE_CONST_FUNC(daifset) DEFINE_SYSREG_WRITE_CONST_FUNC(daifclr) -#define enable_irq() write_daifclr(DAIF_IRQ_BIT) -#define enable_fiq() write_daifclr(DAIF_FIQ_BIT) -#define enable_serror() write_daifclr(DAIF_ABT_BIT) -#define enable_debug_exceptions() write_daifclr(DAIF_DBG_BIT) -#define disable_irq() write_daifset(DAIF_IRQ_BIT) -#define disable_fiq() write_daifset(DAIF_FIQ_BIT) -#define disable_serror() write_daifset(DAIF_ABT_BIT) -#define disable_debug_exceptions() write_daifset(DAIF_DBG_BIT) - DEFINE_SYSREG_READ_FUNC(par_el1) DEFINE_SYSREG_READ_FUNC(id_pfr1_el1) DEFINE_SYSREG_READ_FUNC(id_aa64pfr0_el1) diff --git a/include/plat/arm/board/common/board_arm_def.h b/include/plat/arm/board/common/board_arm_def.h index b065537d..d70fbb46 100644 --- a/include/plat/arm/board/common/board_arm_def.h +++ b/include/plat/arm/board/common/board_arm_def.h @@ -75,10 +75,10 @@ */ #if IMAGE_BL31 || IMAGE_BL32 # define PLAT_ARM_MMAP_ENTRIES 6 -# define MAX_XLAT_TABLES 3 -#else -# define PLAT_ARM_MMAP_ENTRIES 9 # define MAX_XLAT_TABLES 4 +#else +# define PLAT_ARM_MMAP_ENTRIES 10 +# define MAX_XLAT_TABLES 5 #endif #endif /* ARM_BOARD_OPTIMISE_MMAP */ diff --git a/include/plat/arm/common/arm_def.h b/include/plat/arm/common/arm_def.h index d04f9d6f..18fe7180 100644 --- a/include/plat/arm/common/arm_def.h +++ b/include/plat/arm/common/arm_def.h @@ -165,6 +165,12 @@ TSP_SEC_MEM_SIZE, \ MT_MEMORY | MT_RW | MT_SECURE) +#if ARM_BL31_IN_DRAM +#define ARM_MAP_BL31_SEC_DRAM MAP_REGION_FLAT( \ + BL31_BASE, \ + PLAT_ARM_MAX_BL31_SIZE, \ + MT_MEMORY | MT_RW | MT_SECURE) +#endif /* * The number of regions like RO(code), coherent and data required by @@ -240,15 +246,32 @@ /******************************************************************************* * BL2 specific defines. ******************************************************************************/ +#if ARM_BL31_IN_DRAM +/* + * BL31 is loaded in the DRAM. + * Put BL2 just below BL1. + */ +#define BL2_BASE (BL1_RW_BASE - PLAT_ARM_MAX_BL2_SIZE) +#define BL2_LIMIT BL1_RW_BASE +#else /* * Put BL2 just below BL31. */ #define BL2_BASE (BL31_BASE - PLAT_ARM_MAX_BL2_SIZE) #define BL2_LIMIT BL31_BASE +#endif /******************************************************************************* * BL31 specific defines. ******************************************************************************/ +#if ARM_BL31_IN_DRAM +/* + * Put BL31 at the bottom of TZC secured DRAM + */ +#define BL31_BASE ARM_AP_TZC_DRAM1_BASE +#define BL31_LIMIT (ARM_AP_TZC_DRAM1_BASE + \ + PLAT_ARM_MAX_BL31_SIZE) +#else /* * Put BL31 at the top of the Trusted SRAM. */ @@ -257,6 +280,7 @@ PLAT_ARM_MAX_BL31_SIZE) #define BL31_PROGBITS_LIMIT BL1_RW_BASE #define BL31_LIMIT (ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE) +#endif /******************************************************************************* * BL32 specific defines. @@ -266,7 +290,16 @@ * Trusted DRAM (if available) or the DRAM region secured by the TrustZone * controller. */ -#if ARM_TSP_RAM_LOCATION_ID == ARM_TRUSTED_SRAM_ID +#if ARM_BL31_IN_DRAM +# define TSP_SEC_MEM_BASE (ARM_AP_TZC_DRAM1_BASE + \ + PLAT_ARM_MAX_BL31_SIZE) +# define TSP_SEC_MEM_SIZE (ARM_AP_TZC_DRAM1_SIZE - \ + PLAT_ARM_MAX_BL31_SIZE) +# define BL32_BASE (ARM_AP_TZC_DRAM1_BASE + \ + PLAT_ARM_MAX_BL31_SIZE) +# define BL32_LIMIT (ARM_AP_TZC_DRAM1_BASE + \ + ARM_AP_TZC_DRAM1_SIZE) +#elif ARM_TSP_RAM_LOCATION_ID == ARM_TRUSTED_SRAM_ID # define TSP_SEC_MEM_BASE ARM_BL_RAM_BASE # define TSP_SEC_MEM_SIZE ARM_BL_RAM_SIZE # define TSP_PROGBITS_LIMIT BL2_BASE @@ -292,7 +325,11 @@ * FWU Images: NS_BL1U, BL2U & NS_BL2U defines. ******************************************************************************/ #define BL2U_BASE BL2_BASE +#if ARM_BL31_IN_DRAM +#define BL2U_LIMIT BL1_RW_BASE +#else #define BL2U_LIMIT BL31_BASE +#endif #define NS_BL2U_BASE ARM_NS_DRAM1_BASE #define NS_BL1U_BASE (PLAT_ARM_NVM_BASE + 0x03EB8000) diff --git a/plat/arm/board/fvp/aarch64/fvp_common.c b/plat/arm/board/fvp/aarch64/fvp_common.c index f684d977..1de99991 100644 --- a/plat/arm/board/fvp/aarch64/fvp_common.c +++ b/plat/arm/board/fvp/aarch64/fvp_common.c @@ -97,6 +97,9 @@ const mmap_region_t plat_arm_mmap[] = { MAP_DEVICE2, ARM_MAP_NS_DRAM1, ARM_MAP_TSP_SEC_MEM, +#if ARM_BL31_IN_DRAM + ARM_MAP_BL31_SEC_DRAM, +#endif {0} }; #endif diff --git a/plat/arm/board/fvp/include/platform_def.h b/plat/arm/board/fvp/include/platform_def.h index a8267dec..3428cb51 100644 --- a/plat/arm/board/fvp/include/platform_def.h +++ b/plat/arm/board/fvp/include/platform_def.h @@ -146,11 +146,7 @@ * PLAT_ARM_MAX_BL1_RW_SIZE is calculated using the current BL1 RW debug size * plus a little space for growth. */ -#if TRUSTED_BOARD_BOOT -# define PLAT_ARM_MAX_BL1_RW_SIZE 0x9000 -#else -# define PLAT_ARM_MAX_BL1_RW_SIZE 0x6000 -#endif +#define PLAT_ARM_MAX_BL1_RW_SIZE 0xA000 /* * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c index 97c2bca3..a528830a 100644 --- a/plat/arm/common/arm_bl2_setup.c +++ b/plat/arm/common/arm_bl2_setup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -96,11 +96,27 @@ static bl2_to_bl31_params_mem_t bl31_params_mem; #pragma weak bl2_plat_get_bl33_meminfo #pragma weak bl2_plat_set_bl33_ep_info - +#if ARM_BL31_IN_DRAM +meminfo_t *bl2_plat_sec_mem_layout(void) +{ + static meminfo_t bl2_dram_layout + __aligned(CACHE_WRITEBACK_GRANULE) = { + .total_base = BL31_BASE, + .total_size = (ARM_AP_TZC_DRAM1_BASE + + ARM_AP_TZC_DRAM1_SIZE) - BL31_BASE, + .free_base = BL31_BASE, + .free_size = (ARM_AP_TZC_DRAM1_BASE + + ARM_AP_TZC_DRAM1_SIZE) - BL31_BASE + }; + + return &bl2_dram_layout; +} +#else meminfo_t *bl2_plat_sec_mem_layout(void) { return &bl2_tzram_layout; } +#endif /******************************************************************************* * This function assigns a pointer to the memory that the platform has kept diff --git a/plat/arm/common/arm_common.mk b/plat/arm/common/arm_common.mk index 425e0d36..973e583e 100644 --- a/plat/arm/common/arm_common.mk +++ b/plat/arm/common/arm_common.mk @@ -77,6 +77,11 @@ ARM_CONFIG_CNTACR := 1 $(eval $(call assert_boolean,ARM_CONFIG_CNTACR)) $(eval $(call add_define,ARM_CONFIG_CNTACR)) +# Process ARM_BL31_IN_DRAM flag +ARM_BL31_IN_DRAM := 0 +$(eval $(call assert_boolean,ARM_BL31_IN_DRAM)) +$(eval $(call add_define,ARM_BL31_IN_DRAM)) + PLAT_INCLUDES += -Iinclude/common/tbbr \ -Iinclude/plat/arm/common \ -Iinclude/plat/arm/common/aarch64 diff --git a/plat/mediatek/mt8173/bl31_plat_setup.c b/plat/mediatek/mt8173/bl31_plat_setup.c index 87837759..749009ea 100644 --- a/plat/mediatek/mt8173/bl31_plat_setup.c +++ b/plat/mediatek/mt8173/bl31_plat_setup.c @@ -50,13 +50,15 @@ unsigned long __COHERENT_RAM_START__; unsigned long __COHERENT_RAM_END__; /* - * The next 2 constants identify the extents of the code & RO data region. - * These addresses are used by the MMU setup code and therefore they must be - * page-aligned. It is the responsibility of the linker script to ensure that - * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses. + * The next 3 constants identify the extents of the code, RO data region and the + * limit of the BL31 image. These addresses are used by the MMU setup code and + * therefore they must be page-aligned. It is the responsibility of the linker + * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols + * refer to page-aligned addresses. */ #define BL31_RO_BASE (unsigned long)(&__RO_START__) #define BL31_RO_LIMIT (unsigned long)(&__RO_END__) +#define BL31_END (unsigned long)(&__BL31_END__) /* * The next 2 constants identify the extents of the coherent memory region. @@ -108,6 +110,13 @@ static void platform_setup_cpu(void) MCU_BUS_DCM_EN); } +static void platform_setup_sram(void) +{ + /* protect BL31 memory from non-secure read/write access */ + mmio_write_32(SRAMROM_SEC_ADDR, (uint32_t)(BL31_END + 0x3ff) & 0x3fc00); + mmio_write_32(SRAMROM_SEC_CTRL, 0x10000ff9); +} + /******************************************************************************* * Return a pointer to the 'entry_point_info' structure of the next image for * the security state specified. BL33 corresponds to the non-secure image type @@ -156,6 +165,7 @@ void bl31_early_platform_setup(bl31_params_t *from_bl2, void bl31_platform_setup(void) { platform_setup_cpu(); + platform_setup_sram(); plat_delay_timer_init(); diff --git a/plat/mediatek/mt8173/drivers/spm/spm.c b/plat/mediatek/mt8173/drivers/spm/spm.c index 45defd8a..f28b2640 100644 --- a/plat/mediatek/mt8173/drivers/spm/spm.c +++ b/plat/mediatek/mt8173/drivers/spm/spm.c @@ -384,6 +384,10 @@ enum wake_reason_t spm_output_wake_reason(struct wake_status *wakesta) void spm_boot_init(void) { + /* set spm transaction to secure mode */ + mmio_write_32(DEVAPC0_APC_CON, 0x0); + mmio_write_32(DEVAPC0_MAS_SEC_0, 0x200); + /* Only CPU0 is online during boot, initialize cpu online reserve bit */ mmio_write_32(SPM_PCM_RESERVE, 0xFE); mmio_clrbits_32(AP_PLL_CON3, 0xFFFFF); diff --git a/plat/mediatek/mt8173/include/mt8173_def.h b/plat/mediatek/mt8173/include/mt8173_def.h index 39bab149..0113d609 100644 --- a/plat/mediatek/mt8173/include/mt8173_def.h +++ b/plat/mediatek/mt8173/include/mt8173_def.h @@ -40,11 +40,13 @@ /* Register base address */ #define IO_PHYS (0x10000000) #define INFRACFG_AO_BASE (IO_PHYS + 0x1000) +#define SRAMROM_SEC_BASE (IO_PHYS + 0x1800) #define PERI_CON_BASE (IO_PHYS + 0x3000) #define GPIO_BASE (IO_PHYS + 0x5000) #define SPM_BASE (IO_PHYS + 0x6000) #define RGU_BASE (IO_PHYS + 0x7000) #define PMIC_WRAP_BASE (IO_PHYS + 0xD000) +#define DEVAPC0_BASE (IO_PHYS + 0xE000) #define MCUCFG_BASE (IO_PHYS + 0x200000) #define APMIXED_BASE (IO_PHYS + 0x209000) #define TRNG_BASE (IO_PHYS + 0x20F000) @@ -57,6 +59,14 @@ #define MTK_DEV_RNG1_BASE (IO_PHYS + 0x1000000) #define MTK_DEV_RNG1_SIZE 0x4000000 +/* SRAMROM related registers */ +#define SRAMROM_SEC_CTRL (SRAMROM_SEC_BASE + 0x4) +#define SRAMROM_SEC_ADDR (SRAMROM_SEC_BASE + 0x8) + +/* DEVAPC0 related registers */ +#define DEVAPC0_MAS_SEC_0 (DEVAPC0_BASE + 0x500) +#define DEVAPC0_APC_CON (DEVAPC0_BASE + 0xF00) + /******************************************************************************* * UART related constants ******************************************************************************/ |