diff --git a/Makefile b/Makefile index 29027746c..57e27ca2c 100644 --- a/Makefile +++ b/Makefile @@ -1206,6 +1206,7 @@ $(eval $(call assert_booleans,\ ENABLE_CONSOLE_GETC \ INIT_UNUSED_NS_EL2 \ PLATFORM_REPORT_CTX_MEM_USE \ + EARLY_CONSOLE \ ))) # Numeric_Flags @@ -1403,6 +1404,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 9f19b4a47..2b3a82719 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -44,6 +44,9 @@ uint64_t bl1_apiakey[2]; ******************************************************************************/ 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 4c68f076a..f12c1a5e4 100644 --- a/bl2/bl2_main.c +++ b/bl2/bl2_main.c @@ -42,6 +42,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); @@ -64,6 +67,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 c0e914463..83be0f6f4 100644 --- a/bl31/bl31_main.c +++ b/bl31/bl31_main.c @@ -95,6 +95,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/aarch32/entrypoint.S b/bl32/sp_min/aarch32/entrypoint.S index 693dd4b82..ba9d90d42 100644 --- a/bl32/sp_min/aarch32/entrypoint.S +++ b/bl32/sp_min/aarch32/entrypoint.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -118,8 +118,7 @@ func sp_min_entrypoint mov r1, r10 mov r2, r11 mov r3, r12 - bl sp_min_early_platform_setup2 - bl sp_min_plat_arch_setup + bl sp_min_setup /* Jump to the main function */ bl sp_min_main diff --git a/bl32/sp_min/sp_min_main.c b/bl32/sp_min/sp_min_main.c index 61feaeca5..a26910cb2 100644 --- a/bl32/sp_min/sp_min_main.c +++ b/bl32/sp_min/sp_min_main.c @@ -170,6 +170,20 @@ uintptr_t get_arm_std_svc_args(unsigned int svc_mask) return (uintptr_t)&psci_args; } +/****************************************************************************** + * The SP_MIN setup function. Calls platforms init functions + *****************************************************************************/ +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(); +} + /****************************************************************************** * The SP_MIN main function. Do the platform and PSCI Library setup. Also * initialize the runtime service framework. diff --git a/bl32/sp_min/sp_min_private.h b/bl32/sp_min/sp_min_private.h index 628581a4c..9c6b5fb29 100644 --- a/bl32/sp_min/sp_min_private.h +++ b/bl32/sp_min/sp_min_private.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,6 +7,10 @@ #ifndef SP_MIN_PRIVATE_H #define SP_MIN_PRIVATE_H +#include + +void sp_min_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2, + u_register_t arg3); void sp_min_main(void); void sp_min_warm_boot(void); void sp_min_fiq(void); 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/plat/st/stm32mpus.rst b/docs/plat/st/stm32mpus.rst index ab6d8fe51..7b4711278 100644 --- a/docs/plat/st/stm32mpus.rst +++ b/docs/plat/st/stm32mpus.rst @@ -54,8 +54,6 @@ Other configuration flags: | Default: stm32mp157c-ev1.dtb - | ``DWL_BUFFER_BASE``: the 'serial boot' load address of FIP, | default location (end of the first 128MB) is used when absent -- | ``STM32MP_EARLY_CONSOLE``: to enable early traces before clock driver is setup. - | Default: 0 (disabled) - | ``STM32MP_RECONFIGURE_CONSOLE``: to re-configure crash console (especially after BL2). | Default: 0 (disabled) - | ``STM32MP_UART_BAUDRATE``: to select UART baud rate. diff --git a/docs/porting-guide.rst b/docs/porting-guide.rst index c25c8cb66..a7600ec51 100644 --- a/docs/porting-guide.rst +++ b/docs/porting-guide.rst @@ -3286,6 +3286,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 @@ -3572,7 +3583,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/drivers/st/bsec/bsec2.c b/drivers/st/bsec/bsec2.c index a6e522094..db07d1c5c 100644 --- a/drivers/st/bsec/bsec2.c +++ b/drivers/st/bsec/bsec2.c @@ -166,11 +166,13 @@ static void bsec_late_init(void) struct dt_node_info bsec_info; if (fdt_get_address(&fdt) == 0) { + EARLY_ERROR("%s: DT not found\n", __func__); panic(); } node = bsec_get_dt_node(&bsec_info); if (node < 0) { + EARLY_ERROR("%s: BSEC node not found\n", __func__); panic(); } @@ -226,13 +228,21 @@ static uint32_t bsec_check_error(uint32_t otp, bool check_disturbed) */ uint32_t bsec_probe(void) { + uint32_t version; + uint32_t id; + if (is_otp_invalid_mode()) { + EARLY_ERROR("%s: otp_invalid_mod\n", __func__); return BSEC_ERROR; } - if (((bsec_get_version() != BSEC_IP_VERSION_1_1) && - (bsec_get_version() != BSEC_IP_VERSION_2_0)) || - (bsec_get_id() != BSEC_IP_ID_2)) { + version = bsec_get_version(); + id = bsec_get_id(); + + if (((version != BSEC_IP_VERSION_1_1) && + (version != BSEC_IP_VERSION_2_0)) || + (id != BSEC_IP_ID_2)) { + EARLY_ERROR("%s: version = 0x%x, id = 0x%x\n", __func__, version, id); panic(); } diff --git a/drivers/st/bsec/bsec3.c b/drivers/st/bsec/bsec3.c index a803a3a9c..3fdaf16fb 100644 --- a/drivers/st/bsec/bsec3.c +++ b/drivers/st/bsec/bsec3.c @@ -188,7 +188,7 @@ uint32_t bsec_probe(void) uint32_t id = bsec_get_id(); if ((version != BSEC_IP_VERSION_1_0) || (id != BSEC_IP_ID_3)) { - ERROR("%s: version = 0x%x, id = 0x%x\n", __func__, version, id); + EARLY_ERROR("%s: version = 0x%x, id = 0x%x\n", __func__, version, id); panic(); } 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 2af49a93e..ce5e8e0d9 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 diff --git a/plat/st/common/common.mk b/plat/st/common/common.mk index b9b62c03f..7ef76652e 100644 --- a/plat/st/common/common.mk +++ b/plat/st/common/common.mk @@ -6,7 +6,6 @@ RESET_TO_BL2 := 1 -STM32MP_EARLY_CONSOLE ?= 0 STM32MP_RECONFIGURE_CONSOLE ?= 0 STM32MP_UART_BAUDRATE ?= 115200 @@ -82,7 +81,6 @@ endif $(eval $(call assert_booleans,\ $(sort \ PLAT_XLAT_TABLES_DYNAMIC \ - STM32MP_EARLY_CONSOLE \ STM32MP_EMMC \ STM32MP_EMMC_BOOT \ STM32MP_RAW_NAND \ @@ -104,7 +102,6 @@ $(eval $(call add_defines,\ $(sort \ PLAT_XLAT_TABLES_DYNAMIC \ STM32_TF_VERSION \ - STM32MP_EARLY_CONSOLE \ STM32MP_EMMC \ STM32MP_EMMC_BOOT \ STM32MP_RAW_NAND \ diff --git a/plat/st/common/include/stm32mp_common.h b/plat/st/common/include/stm32mp_common.h index a1ed1addd..41b86ae0a 100644 --- a/plat/st/common/include/stm32mp_common.h +++ b/plat/st/common/include/stm32mp_common.h @@ -77,14 +77,6 @@ uintptr_t get_uart_address(uint32_t instance_nb); /* Setup the UART console */ int stm32mp_uart_console_setup(void); -#if STM32MP_EARLY_CONSOLE -void stm32mp_setup_early_console(void); -#else -static inline void stm32mp_setup_early_console(void) -{ -} -#endif - /* * Platform util functions for the GPIO driver * @bank: Target GPIO bank ID as per DT bindings diff --git a/plat/st/common/stm32mp_common.c b/plat/st/common/stm32mp_common.c index a1d1c4963..6f36011f9 100644 --- a/plat/st/common/stm32mp_common.c +++ b/plat/st/common/stm32mp_common.c @@ -269,8 +269,8 @@ int stm32mp_uart_console_setup(void) return 0; } -#if STM32MP_EARLY_CONSOLE -void stm32mp_setup_early_console(void) +#if EARLY_CONSOLE +void plat_setup_early_console(void) { #if defined(IMAGE_BL2) || STM32MP_RECONFIGURE_CONSOLE plat_crash_console_init(); @@ -278,7 +278,7 @@ void stm32mp_setup_early_console(void) set_console(STM32MP_DEBUG_USART_BASE, STM32MP_DEBUG_USART_CLK_FRQ); NOTICE("Early console setup\n"); } -#endif /* STM32MP_EARLY_CONSOLE */ +#endif /* EARLY_CONSOLE */ /***************************************************************************** * plat_is_smccc_feature_available() - This function checks whether SMCCC diff --git a/plat/st/stm32mp1/bl2_plat_setup.c b/plat/st/stm32mp1/bl2_plat_setup.c index 798c033c7..bd3903d3e 100644 --- a/plat/st/stm32mp1/bl2_plat_setup.c +++ b/plat/st/stm32mp1/bl2_plat_setup.c @@ -142,8 +142,6 @@ void bl2_el3_early_platform_setup(u_register_t arg0, u_register_t arg2 __unused, u_register_t arg3 __unused) { - stm32mp_setup_early_console(); - stm32mp_save_boot_ctx_address(arg0); } diff --git a/plat/st/stm32mp1/sp_min/sp_min_setup.c b/plat/st/stm32mp1/sp_min/sp_min_setup.c index 245b2d324..7bfe6ba56 100644 --- a/plat/st/stm32mp1/sp_min/sp_min_setup.c +++ b/plat/st/stm32mp1/sp_min/sp_min_setup.c @@ -116,8 +116,6 @@ void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1, bl_params_t *params_from_bl2 = (bl_params_t *)arg0; uintptr_t dt_addr = arg1; - stm32mp_setup_early_console(); - /* Imprecise aborts can be masked in NonSecure */ write_scr(read_scr() | SCR_AW_BIT); diff --git a/plat/st/stm32mp2/bl2_plat_setup.c b/plat/st/stm32mp2/bl2_plat_setup.c index a7cce627c..724209a16 100644 --- a/plat/st/stm32mp2/bl2_plat_setup.c +++ b/plat/st/stm32mp2/bl2_plat_setup.c @@ -18,7 +18,6 @@ void bl2_el3_early_platform_setup(u_register_t arg0 __unused, u_register_t arg2 __unused, u_register_t arg3 __unused) { - stm32mp_setup_early_console(); } void bl2_platform_setup(void) @@ -28,7 +27,7 @@ void bl2_platform_setup(void) void bl2_el3_plat_arch_setup(void) { if (stm32_otp_probe() != 0U) { - ERROR("OTP probe failed\n"); + EARLY_ERROR("OTP probe failed\n"); panic(); } }