From ae770fedf459d5643125d29f48659e3e936ebd2d Mon Sep 17 00:00:00 2001 From: Yann Gautier Date: Tue, 16 Jan 2024 19:39:31 +0100 Subject: [PATCH] feat(console): introduce EARLY_CONSOLE This is a generic porting of what was done on ST platforms with flag STM32MP_EARLY_CONSOLE. It creates the flag and the prototype for plat_setup_early_console(). This function depends on platform implementation. This function call is added at the beginning of each BL image early setup function. The patch also introduce an extra log macro: EARLY_ERROR. This can replace ERROR macro in code that will only be executed before the default console is enabled, and will do nothing when the EARLY_CONSOLE is not enabled. This can then save some space in memory. Signed-off-by: Yann Gautier Change-Id: I77bf0a0c4289b4c7df94e4bfb783a938e05bf023 --- Makefile | 2 ++ bl1/bl1_main.c | 5 ++++- bl2/bl2_main.c | 8 +++++++- bl31/bl31_main.c | 5 ++++- bl32/sp_min/sp_min_main.c | 3 +++ bl32/tsp/tsp_common.c | 5 ++++- docs/getting_started/build-options.rst | 7 +++++++ docs/porting-guide.rst | 13 ++++++++++++- include/common/debug.h | 8 +++++++- include/plat/common/platform.h | 8 ++++++++ make_helpers/defaults.mk | 5 ++++- 11 files changed, 62 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 6b1f47cf3..a9be6a75b 100644 --- a/Makefile +++ b/Makefile @@ -1197,6 +1197,7 @@ $(eval $(call assert_booleans,\ ENABLE_CONSOLE_GETC \ INIT_UNUSED_NS_EL2 \ PLATFORM_REPORT_CTX_MEM_USE \ + EARLY_CONSOLE \ ))) # Numeric_Flags @@ -1394,6 +1395,7 @@ $(eval $(call add_defines,\ ENABLE_CONSOLE_GETC \ INIT_UNUSED_NS_EL2 \ PLATFORM_REPORT_CTX_MEM_USE \ + EARLY_CONSOLE \ ))) ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1) diff --git a/bl1/bl1_main.c b/bl1/bl1_main.c index 6fe551188..657366b9e 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -64,6 +64,9 @@ void bl1_calc_bl2_mem_layout(const meminfo_t *bl1_mem_layout, ******************************************************************************/ void bl1_setup(void) { + /* Enable early console if EARLY_CONSOLE flag is enabled */ + plat_setup_early_console(); + /* Perform early platform-specific setup */ bl1_early_platform_setup(); diff --git a/bl2/bl2_main.c b/bl2/bl2_main.c index 923a554fb..3df0bfae2 100644 --- a/bl2/bl2_main.c +++ b/bl2/bl2_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -41,6 +41,9 @@ void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3) { + /* Enable early console if EARLY_CONSOLE flag is enabled */ + plat_setup_early_console(); + /* Perform early platform-specific setup */ bl2_el3_early_platform_setup(arg0, arg1, arg2, arg3); @@ -63,6 +66,9 @@ void bl2_el3_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, void bl2_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3) { + /* Enable early console if EARLY_CONSOLE flag is enabled */ + plat_setup_early_console(); + /* Perform early platform-specific setup */ bl2_early_platform_setup2(arg0, arg1, arg2, arg3); diff --git a/bl31/bl31_main.c b/bl31/bl31_main.c index 98078171d..cfa07b1b6 100644 --- a/bl31/bl31_main.c +++ b/bl31/bl31_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -94,6 +94,9 @@ static void __init bl31_lib_init(void) void bl31_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3) { + /* Enable early console if EARLY_CONSOLE flag is enabled */ + plat_setup_early_console(); + /* Perform early platform-specific setup */ bl31_early_platform_setup2(arg0, arg1, arg2, arg3); diff --git a/bl32/sp_min/sp_min_main.c b/bl32/sp_min/sp_min_main.c index 1c7e9600a..39dfa71c4 100644 --- a/bl32/sp_min/sp_min_main.c +++ b/bl32/sp_min/sp_min_main.c @@ -175,6 +175,9 @@ uintptr_t get_arm_std_svc_args(unsigned int svc_mask) void sp_min_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3) { + /* Enable early console if EARLY_CONSOLE flag is enabled */ + plat_setup_early_console(); + /* Perform early platform-specific setup */ sp_min_early_platform_setup2(arg0, arg1, arg2, arg3); sp_min_plat_arch_setup(); diff --git a/bl32/tsp/tsp_common.c b/bl32/tsp/tsp_common.c index 908b4ff09..3a6c9d97f 100644 --- a/bl32/tsp/tsp_common.c +++ b/bl32/tsp/tsp_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2022-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -66,6 +66,9 @@ smc_args_t *set_smc_args(uint64_t arg0, ******************************************************************************/ void tsp_setup(void) { + /* Enable early console if EARLY_CONSOLE flag is enabled */ + plat_setup_early_console(); + /* Perform early platform-specific setup. */ tsp_early_platform_setup(); diff --git a/docs/getting_started/build-options.rst b/docs/getting_started/build-options.rst index c18c1552c..2892dc6e6 100644 --- a/docs/getting_started/build-options.rst +++ b/docs/getting_started/build-options.rst @@ -230,6 +230,13 @@ Common build options contributions are still expected to build with ``W=0`` and ``E=1`` (the default). +- ``EARLY_CONSOLE``: This option is used to enable early traces before default + console is properly setup. It introduces EARLY_* traces macros, that will + use the non-EARLY traces macros if the flag is enabled, or do nothing + otherwise. To use this feature, platforms will have to create the function + plat_setup_early_console(). + Default is 0 (disabled) + - ``EL3_PAYLOAD_BASE``: This option enables booting an EL3 payload instead of the normal boot flow. It must specify the entry point address of the EL3 payload. Please refer to the "Booting an EL3 payload" section for more diff --git a/docs/porting-guide.rst b/docs/porting-guide.rst index 7c66d1118..59023c095 100644 --- a/docs/porting-guide.rst +++ b/docs/porting-guide.rst @@ -3274,6 +3274,17 @@ This API is used by the crash reporting mechanism to force write of all buffered data on the designated crash console. It should only use general purpose registers x0 through x5 to do its work. +Function : plat_setup_early_console [optional] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:: + + Argument : void + Return : void + +This API is used to setup the early console, it is required only if the flag +``EARLY_CONSOLE`` is enabled. + .. _External Abort handling and RAS Support: External Abort handling and RAS Support @@ -3560,7 +3571,7 @@ to :ref:`Measured Boot Design` for more details. -------------- -*Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.* +*Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.* .. _PSCI: https://developer.arm.com/documentation/den0022/latest/ .. _Arm Generic Interrupt Controller version 2.0 (GICv2): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html diff --git a/include/common/debug.h b/include/common/debug.h index 5ea541da0..0ddb40079 100644 --- a/include/common/debug.h +++ b/include/common/debug.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -91,6 +91,12 @@ # define VERBOSE(...) no_tf_log(LOG_MARKER_VERBOSE __VA_ARGS__) #endif +#if EARLY_CONSOLE +#define EARLY_ERROR(...) ERROR(__VA_ARGS__) +#else /* !EARLY_CONSOLE */ +#define EARLY_ERROR(...) no_tf_log(LOG_MARKER_ERROR __VA_ARGS__) +#endif /* EARLY_CONSOLE */ + const char *get_el_str(unsigned int el); #if ENABLE_BACKTRACE diff --git a/include/plat/common/platform.h b/include/plat/common/platform.h index 4fe362005..d4db77862 100644 --- a/include/plat/common/platform.h +++ b/include/plat/common/platform.h @@ -184,6 +184,14 @@ static inline int plat_mboot_measure_key(const void *pk_oid __unused, } #endif /* MEASURED_BOOT */ +#if EARLY_CONSOLE +void plat_setup_early_console(void); +#else +static inline void plat_setup_early_console(void) +{ +} +#endif /* EARLY_CONSOLE */ + /******************************************************************************* * Mandatory BL1 functions ******************************************************************************/ diff --git a/make_helpers/defaults.mk b/make_helpers/defaults.mk index 26d2a00cd..b9ea81081 100644 --- a/make_helpers/defaults.mk +++ b/make_helpers/defaults.mk @@ -1,5 +1,5 @@ # -# Copyright (c) 2016-2023, Arm Limited. All rights reserved. +# Copyright (c) 2016-2024, Arm Limited. All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # @@ -392,3 +392,6 @@ CTX_INCLUDE_MPAM_REGS := 0 # Enable context memory usage reporting during BL31 setup. PLATFORM_REPORT_CTX_MEM_USE := 0 + +# Enable early console +EARLY_CONSOLE := 0