From 487461cb6e367a5db397c34ed75fbcfdd6bda1c9 Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Wed, 28 Oct 2015 10:29:42 +0000 Subject: [PATCH 1/3] Introduce console_uninit() API in ARM Trusted Firmware Allowing console base address to be set to NULL conveniently allows console driver to ignore further invocations to console_putc() and console_getc(). This patch adds `console_uninit()` API to the console driver which sets console base address as NULL. The BL images can invoke this API to finish the use of console and ignore any further invocations to print to the console. Change-Id: I00a1762b3e0b7c55f2be2f9c4c9bee3967189dde --- drivers/console/console.S | 15 +++++++++++++++ include/drivers/console.h | 1 + 2 files changed, 16 insertions(+) diff --git a/drivers/console/console.S b/drivers/console/console.S index d966f0d36b..40a6db9f48 100644 --- a/drivers/console/console.S +++ b/drivers/console/console.S @@ -30,6 +30,7 @@ #include .globl console_init + .globl console_uninit .globl console_putc .globl console_getc @@ -66,6 +67,20 @@ init_fail: ret endfunc console_init + /* ----------------------------------------------- + * void console_uninit(void) + * Function to finish the use of console driver. + * It sets the console_base as NULL so that any + * further invocation of `console_putc` or + * `console_getc` APIs would return error. + * ----------------------------------------------- + */ +func console_uninit + mov x0, #0 + adrp x3, console_base + str x0, [x3, :lo12:console_base] +endfunc console_uninit + /* --------------------------------------------- * int console_putc(int c) * Function to output a character over the diff --git a/include/drivers/console.h b/include/drivers/console.h index d374157bd0..69ad0bd740 100644 --- a/include/drivers/console.h +++ b/include/drivers/console.h @@ -35,6 +35,7 @@ int console_init(uintptr_t base_addr, unsigned int uart_clk, unsigned int baud_rate); +void console_uninit(void); int console_putc(int c); int console_getc(void); From 78e61613738e53738e1cc8ddefd4cef2f2443f4c Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Wed, 9 Dec 2015 11:28:43 +0000 Subject: [PATCH 2/3] Ensure BL31 does not print to boot console by default It is not ideal for BL31 to continue to use boot console at runtime which could be potentially uninitialized. This patch introduces a new optional platform porting API `bl31_plat_runtime_setup()` which allows the platform to perform any BL31 runtime setup just prior to BL31 exit during cold boot. The default weak implementation of this function will invoke `console_uninit()` which will suppress any BL31 runtime logs. On the ARM Standard platforms, there is an anomaly that the boot console will be reinitialized on resumption from system suspend in `arm_system_pwr_domain_resume()`. This will be resolved in the following patch. NOTE: The default weak definition of `bl31_plat_runtime_setup()` disables the BL31 console. To print the BL31 runtime messages, platforms must override this API and initialize a runtime console. Fixes ARM-software/tf-issues#328 Change-Id: Ibaf8346fcceb447fe1a5674094c9f8eb4c09ac4a --- bl31/bl31_main.c | 8 +++++++- docs/porting-guide.md | 11 +++++++++++ include/plat/common/platform.h | 1 + plat/common/aarch64/plat_common.c | 13 ++++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bl31/bl31_main.c b/bl31/bl31_main.c index 9abc395bf0..f22e6121c5 100644 --- a/bl31/bl31_main.c +++ b/bl31/bl31_main.c @@ -77,7 +77,7 @@ void bl31_main(void) /* Perform remaining generic architectural setup from EL3 */ bl31_arch_setup(); - /* Perform platform setup in BL1 */ + /* Perform platform setup in BL31 */ bl31_platform_setup(); /* Initialise helper libraries */ @@ -109,6 +109,12 @@ void bl31_main(void) * corresponding to the desired security state after the next ERET. */ bl31_prepare_next_image_entry(); + + /* + * Perform any platform specific runtime setup prior to cold boot exit + * from BL31 + */ + bl31_plat_runtime_setup(); } /******************************************************************************* diff --git a/docs/porting-guide.md b/docs/porting-guide.md index e5b4a9c789..2f71d80a95 100644 --- a/docs/porting-guide.md +++ b/docs/porting-guide.md @@ -1172,6 +1172,17 @@ In ARM standard platforms, this function does the following: * Detects the system topology. +### Function : bl31_plat_runtime_setup() [optional] + + Argument : void + Return : void + +The purpose of this function is allow the platform to perform any BL31 runtime +setup just prior to BL31 exit during cold boot. The default weak +implementation of this function will invoke `console_uninit()` which will +suppress any BL31 runtime logs. + + ### Function : bl31_get_next_image_info() [mandatory] Argument : unsigned int diff --git a/include/plat/common/platform.h b/include/plat/common/platform.h index de9848b7c1..956d17f764 100644 --- a/include/plat/common/platform.h +++ b/include/plat/common/platform.h @@ -179,6 +179,7 @@ void bl31_early_platform_setup(struct bl31_params *from_bl2, void *plat_params_from_bl2); void bl31_plat_arch_setup(void); void bl31_platform_setup(void); +void bl31_plat_runtime_setup(void); struct entry_point_info *bl31_plat_get_next_image_ep_info(uint32_t type); /******************************************************************************* diff --git a/plat/common/aarch64/plat_common.c b/plat/common/aarch64/plat_common.c index a6a8476557..9070c613ce 100644 --- a/plat/common/aarch64/plat_common.c +++ b/plat/common/aarch64/plat_common.c @@ -28,16 +28,18 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include #include /* - * The following 2 platform setup functions are weakly defined. They + * The following platform setup functions are weakly defined. They * provide typical implementations that may be re-used by multiple * platforms but may also be overridden by a platform if required. */ #pragma weak bl31_plat_enable_mmu #pragma weak bl32_plat_enable_mmu +#pragma weak bl31_plat_runtime_setup void bl31_plat_enable_mmu(uint32_t flags) { @@ -49,6 +51,15 @@ void bl32_plat_enable_mmu(uint32_t flags) enable_mmu_el1(flags); } +void bl31_plat_runtime_setup(void) +{ + /* + * Finish the use of console driver in BL31 so that any runtime logs + * from BL31 will be suppressed. + */ + console_uninit(); +} + #if !ENABLE_PLAT_COMPAT /* * Helper function for platform_get_pos() when platform compatibility is From 080225dacd7c1e11c53756ec66d72d3573d1a70d Mon Sep 17 00:00:00 2001 From: Soby Mathew Date: Wed, 9 Dec 2015 11:38:43 +0000 Subject: [PATCH 3/3] Specify BL31 runtime console for ARM Standard platforms This patch overrides the default weak definition of `bl31_plat_runtime_setup()` for ARM Standard platforms to specify a BL31 runtime console. ARM Standard platforms are now expected to define `PLAT_ARM_BL31_RUN_UART_BASE` and `PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ` macros which is required by `arm_bl31_plat_runtime_setup()` to initialize the runtime console. The system suspend resume helper `arm_system_pwr_domain_resume()` is fixed to initialize the runtime console rather than the boot console on resumption from system suspend. Fixes ARM-software/tf-issues#220 Change-Id: I80eafe5b6adcfc7f1fdf8b99659aca1c64d96975 --- docs/porting-guide.md | 4 ++++ include/plat/arm/board/common/board_css_def.h | 7 +++++-- include/plat/arm/common/plat_arm.h | 1 + plat/arm/board/fvp/include/platform_def.h | 7 +++++-- plat/arm/common/arm_bl31_setup.c | 16 ++++++++++++++++ plat/arm/common/arm_pm.c | 2 +- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/docs/porting-guide.md b/docs/porting-guide.md index 2f71d80a95..ba550f0464 100644 --- a/docs/porting-guide.md +++ b/docs/porting-guide.md @@ -1182,6 +1182,10 @@ setup just prior to BL31 exit during cold boot. The default weak implementation of this function will invoke `console_uninit()` which will suppress any BL31 runtime logs. +In ARM Standard platforms, this function will initialize the BL31 runtime +console which will cause all further BL31 logs to be output to the +runtime console. + ### Function : bl31_get_next_image_info() [mandatory] diff --git a/include/plat/arm/board/common/board_css_def.h b/include/plat/arm/board/common/board_css_def.h index 2e32b41c53..975f1fc55d 100644 --- a/include/plat/arm/board/common/board_css_def.h +++ b/include/plat/arm/board/common/board_css_def.h @@ -74,8 +74,11 @@ #define PLAT_ARM_BOOT_UART_BASE SOC_CSS_UART0_BASE #define PLAT_ARM_BOOT_UART_CLK_IN_HZ SOC_CSS_UART0_CLK_IN_HZ -#define PLAT_ARM_CRASH_UART_BASE SOC_CSS_UART1_BASE -#define PLAT_ARM_CRASH_UART_CLK_IN_HZ SOC_CSS_UART1_CLK_IN_HZ +#define PLAT_ARM_BL31_RUN_UART_BASE SOC_CSS_UART1_BASE +#define PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ SOC_CSS_UART1_CLK_IN_HZ + +#define PLAT_ARM_CRASH_UART_BASE PLAT_ARM_BL31_RUN_UART_BASE +#define PLAT_ARM_CRASH_UART_CLK_IN_HZ PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ #define PLAT_ARM_TSP_UART_BASE V2M_IOFPGA_UART0_BASE #define PLAT_ARM_TSP_UART_CLK_IN_HZ V2M_IOFPGA_UART0_CLK_IN_HZ diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h index aadf58d838..ed65d05bfa 100644 --- a/include/plat/arm/common/plat_arm.h +++ b/include/plat/arm/common/plat_arm.h @@ -170,6 +170,7 @@ uint32_t arm_get_spsr_for_bl33_entry(void); void arm_bl31_early_platform_setup(bl31_params_t *from_bl2, void *plat_params_from_bl2); void arm_bl31_platform_setup(void); +void arm_bl31_plat_runtime_setup(void); void arm_bl31_plat_arch_setup(void); /* TSP utility functions */ diff --git a/plat/arm/board/fvp/include/platform_def.h b/plat/arm/board/fvp/include/platform_def.h index 9ada6b2aa3..203f7b7e51 100644 --- a/plat/arm/board/fvp/include/platform_def.h +++ b/plat/arm/board/fvp/include/platform_def.h @@ -78,8 +78,11 @@ #define PLAT_ARM_BOOT_UART_BASE V2M_IOFPGA_UART0_BASE #define PLAT_ARM_BOOT_UART_CLK_IN_HZ V2M_IOFPGA_UART0_CLK_IN_HZ -#define PLAT_ARM_CRASH_UART_BASE V2M_IOFPGA_UART1_BASE -#define PLAT_ARM_CRASH_UART_CLK_IN_HZ V2M_IOFPGA_UART1_CLK_IN_HZ +#define PLAT_ARM_BL31_RUN_UART_BASE V2M_IOFPGA_UART1_BASE +#define PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ V2M_IOFPGA_UART1_CLK_IN_HZ + +#define PLAT_ARM_CRASH_UART_BASE PLAT_ARM_BL31_RUN_UART_BASE +#define PLAT_ARM_CRASH_UART_CLK_IN_HZ PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ #define PLAT_ARM_TSP_UART_BASE V2M_IOFPGA_UART2_BASE #define PLAT_ARM_TSP_UART_CLK_IN_HZ V2M_IOFPGA_UART2_CLK_IN_HZ diff --git a/plat/arm/common/arm_bl31_setup.c b/plat/arm/common/arm_bl31_setup.c index 8682fd19a8..28268252f5 100644 --- a/plat/arm/common/arm_bl31_setup.c +++ b/plat/arm/common/arm_bl31_setup.c @@ -224,11 +224,27 @@ void arm_bl31_platform_setup(void) plat_arm_pwrc_setup(); } +/******************************************************************************* + * Perform any BL3-1 platform runtime setup prior to BL3-1 exit common to ARM + * standard platforms + ******************************************************************************/ +void arm_bl31_plat_runtime_setup(void) +{ + /* Initialize the runtime console */ + console_init(PLAT_ARM_BL31_RUN_UART_BASE, PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ, + ARM_CONSOLE_BAUDRATE); +} + void bl31_platform_setup(void) { arm_bl31_platform_setup(); } +void bl31_plat_runtime_setup(void) +{ + arm_bl31_plat_runtime_setup(); +} + /******************************************************************************* * Perform the very early platform specific architectural setup here. At the * moment this is only intializes the mmu in a quick and dirty way. diff --git a/plat/arm/common/arm_pm.c b/plat/arm/common/arm_pm.c index cae65970fb..679dd6b6e5 100644 --- a/plat/arm/common/arm_pm.c +++ b/plat/arm/common/arm_pm.c @@ -158,7 +158,7 @@ int arm_validate_ns_entrypoint(uintptr_t entrypoint) *****************************************************************************/ void arm_system_pwr_domain_resume(void) { - console_init(PLAT_ARM_BOOT_UART_BASE, PLAT_ARM_BOOT_UART_CLK_IN_HZ, + console_init(PLAT_ARM_BL31_RUN_UART_BASE, PLAT_ARM_BL31_RUN_UART_CLK_IN_HZ, ARM_CONSOLE_BAUDRATE); /* Assert system power domain is available on the platform */