Skip to content

Commit 43744b4

Browse files
jackson-cooperdstgloorious
authored andcommitted
LIB: Replace MCUBoot log level with BL2 log level
Completely replace the MCUBOOT_LOG_LEVEL with TFM_BL2_LOG_LEVEL, which specifies the log level to use for all of BL2. Change-Id: I2e454c6709d32d283454730d11b4b22d7c550071 Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit aa09e6f) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent 16f2951 commit 43744b4

File tree

13 files changed

+65
-110
lines changed

13 files changed

+65
-110
lines changed

bl2/ext/mcuboot/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ target_link_libraries(bl2
7272
bootutil
7373
)
7474

75-
set(LOG_LEVEL_ID ${BL2_LOG_LEVEL})
76-
7775
if (MCUBOOT_ALIGN_VAL GREATER 8)
7876
set (MCUBOOT_BOOT_MAX_ALIGN ${MCUBOOT_ALIGN_VAL})
7977
else()

bl2/ext/mcuboot/Kconfig

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2023-2024, Arm Limited. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -244,27 +244,35 @@ config MCUBOOT_PSA_CRYPTO_CONFIG_FILEPATH
244244
string "Mbed TLS PSA Crypto config file to use with MCUboot"
245245
default "$(TFM_SOURCE_DIR)/bl2/ext/mcuboot/config/mcuboot_crypto_config.h"
246246

247-
choice MCUBOOT_LOG_LEVEL_CHOICE
248-
prompt "MCUBoot Log Level"
249-
default MCUBOOT_LOG_LEVEL_INFO
247+
choice BL2_LOG_LEVEL
248+
prompt "TFM BL2 Log Level"
249+
default LOG_LEVEL_INFO
250250

251-
config MCUBOOT_LOG_LEVEL_DEBUG
252-
bool "Debug"
253-
config MCUBOOT_LOG_LEVEL_INFO
251+
config LOG_LEVEL_VERBOSE
252+
bool "Verbose"
253+
254+
config LOG_LEVEL_INFO
254255
bool "Info"
255-
config MCUBOOT_LOG_LEVEL_WARNING
256+
257+
config LOG_LEVEL_WARNING
256258
bool "Warning"
257-
config MCUBOOT_LOG_LEVEL_ERROR
259+
260+
config LOG_LEVEL_NOTICE
261+
bool "Notice"
262+
263+
config LOG_LEVEL_ERROR
258264
bool "Error"
259-
config MCUBOOT_LOG_LEVEL_OFF
260-
bool "Off"
265+
266+
config LOG_LEVEL_NONE
267+
bool "None"
261268
endchoice
262269

263-
config MCUBOOT_LOG_LEVEL
264-
string
265-
default "DEBUG" if MCUBOOT_LOG_LEVEL_DEBUG
266-
default "INFO" if MCUBOOT_LOG_LEVEL_INFO
267-
default "WARNING" if MCUBOOT_LOG_LEVEL_WARNING
268-
default "ERROR" if MCUBOOT_LOG_LEVEL_ERROR
269-
default "OFF" if MCUBOOT_LOG_LEVEL_OFF
270+
config TFM_BL2_LOG_LEVEL
271+
int
272+
default 50 if LOG_LEVEL_VERBOSE
273+
default 40 if LOG_LEVEL_INFO
274+
default 30 if LOG_LEVEL_WARN
275+
default 20 if LOG_LEVEL_NOTICE
276+
default 10 if LOG_LEVEL_ERROR
277+
default 0 if LOG_LEVEL_NONE
270278
endif

bl2/ext/mcuboot/bl2_main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* Copyright (c) 2012-2014 Wind River Systems, Inc.
3-
* Copyright (c) 2017-2024 Arm Limited.
3+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
46
*
57
* Licensed under the Apache License, Version 2.0 (the "License");
68
* you may not use this file except in compliance with the License.
@@ -90,7 +92,7 @@ static void do_boot(struct boot_rsp *rsp)
9092
rsp->br_hdr->ih_hdr_size);
9193
}
9294

93-
#if (MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF) || defined(TEST_BL2)
95+
#if (LOG_LEVEL > LOG_LEVEL_NONE) || defined(TEST_BL2)
9496
stdio_uninit();
9597
#endif
9698

@@ -120,7 +122,7 @@ int main(void)
120122
*/
121123
mbedtls_memory_buffer_alloc_init(mbedtls_mem_buf, BL2_MBEDTLS_MEM_BUF_LEN);
122124

123-
#if (MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF) || defined(TEST_BL2)
125+
#if (LOG_LEVEL > LOG_LEVEL_NONE) || defined(TEST_BL2)
124126
stdio_init();
125127
#if defined(TEST_BL2)
126128
for (int i = 0; i < 0xFFFFF; i++) {
@@ -130,7 +132,7 @@ int main(void)
130132
}
131133
(void)stdio_output_string("\r\n", 2);
132134
#endif /* defined(TEST_BL2) */
133-
#endif /* (MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF) || defined(TEST_BL2) */
135+
#endif /* (LOG_LEVEL > LOG_LEVEL_NONE) || defined(TEST_BL2) */
134136

135137
/* Perform platform specific initialization */
136138
err = boot_platform_init();

bl2/ext/mcuboot/include/mcuboot_config/mcuboot_config.h.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (c) 2018 Open Source Foundries Limited
3-
* Copyright (c) 2019-2024 Arm Limited
3+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
44
*
5-
* SPDX-License-Identifier: Apache-2.0
5+
* SPDX-License-Identifier: BSD-3-Clause
66
*/
77

88
/*
@@ -80,7 +80,6 @@ extern "C" {
8080
* Logging
8181
*/
8282
#define MCUBOOT_HAVE_LOGGING 1
83-
#define MCUBOOT_LOG_LEVEL @LOG_LEVEL_ID@
8483

8584
#endif /* !__BOOTSIM__ */
8685

bl2/ext/mcuboot/include/mcuboot_config/mcuboot_logging.h

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (c) 2017 Linaro Limited
33
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
44
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*
57
* Licensed under the Apache License, Version 2.0 (the "License");
68
* you may not use this file except in compliance with the License.
79
* You may obtain a copy of the License at
@@ -18,63 +20,22 @@
1820
#ifndef __MCUBOOT_LOGGING_H__
1921
#define __MCUBOOT_LOGGING_H__
2022

21-
#include "bootutil/ignore.h"
22-
23-
/*
24-
* MCUBoot uses MCUBOOT_LOG_LEVEL to specify the log level
25-
* but tfm_log.h requires the definition of LOG_LEVEL. Define
26-
* the maximum possible LOG_LEVEL which ensures that all
27-
* macros are valid. MCUBoot can then use its log level
28-
* to determine what to log.
29-
*/
30-
#undef LOG_LEVEL
31-
#define LOG_LEVEL LOG_LEVEL_VERBOSE
3223
#include "tfm_log.h"
3324

3425
#ifdef __cplusplus
3526
extern "C" {
3627
#endif
3728

38-
#define MCUBOOT_LOG_LEVEL_OFF LOG_LEVEL_NONE
39-
#define MCUBOOT_LOG_LEVEL_ERROR LOG_LEVEL_ERROR
40-
#define MCUBOOT_LOG_LEVEL_WARNING LOG_LEVEL_WARNING
41-
#define MCUBOOT_LOG_LEVEL_INFO LOG_LEVEL_INFO
42-
#define MCUBOOT_LOG_LEVEL_DEBUG LOG_LEVEL_VERBOSE
43-
44-
#ifndef MCUBOOT_LOG_LEVEL
45-
#define MCUBOOT_LOG_LEVEL MCUBOOT_LOG_LEVEL_INFO
46-
#endif
47-
4829
#define MCUBOOT_LOG_MODULE_DECLARE(domain) /* Ignore */
4930
#define MCUBOOT_LOG_MODULE_REGISTER(domain) /* Ignore */
5031

51-
#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_ERROR
52-
#define MCUBOOT_LOG_ERR(_fmt, ...) \
53-
ERROR(_fmt "\n", ##__VA_ARGS__)
54-
#else
55-
#define MCUBOOT_LOG_ERR(...) IGNORE(__VA_ARGS__)
56-
#endif
32+
#define MCUBOOT_LOG_ERR(_fmt, ...) ERROR(_fmt "\n", ##__VA_ARGS__)
5733

58-
#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_WARNING
59-
#define MCUBOOT_LOG_WRN(_fmt, ...) \
60-
WARN(_fmt "\n", ##__VA_ARGS__)
61-
#else
62-
#define MCUBOOT_LOG_WRN(...) IGNORE(__VA_ARGS__)
63-
#endif
34+
#define MCUBOOT_LOG_WRN(_fmt, ...) WARN(_fmt "\n", ##__VA_ARGS__)
6435

65-
#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_INFO
66-
#define MCUBOOT_LOG_INF(_fmt, ...) \
67-
INFO(_fmt "\n", ##__VA_ARGS__)
68-
#else
69-
#define MCUBOOT_LOG_INF(...) IGNORE(__VA_ARGS__)
70-
#endif
36+
#define MCUBOOT_LOG_INF(_fmt, ...) INFO(_fmt "\n", ##__VA_ARGS__)
7137

72-
#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_DEBUG
73-
#define MCUBOOT_LOG_DBG(_fmt, ...) \
74-
VERBOSE(_fmt "\n", ##__VA_ARGS__)
75-
#else
76-
#define MCUBOOT_LOG_DBG(...) IGNORE(__VA_ARGS__)
77-
#endif
38+
#define MCUBOOT_LOG_DBG(_fmt, ...) VERBOSE(_fmt "\n", ##__VA_ARGS__)
7839

7940
#ifdef __cplusplus
8041
}

bl2/ext/mcuboot/mcuboot_default_config.cmake

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(MCUBOOT_NS_IMAGE_FLASH_AREA_NUM 1 CACHE STRING "ID of the f
1717

1818
set(MCUBOOT_IMAGE_NUMBER 2 CACHE STRING "Whether to combine S and NS into either 1 image, or sign each seperately")
1919
set(MCUBOOT_EXECUTION_SLOT 1 CACHE STRING "Slot from which to execute the image, used for XIP mode")
20-
set(MCUBOOT_LOG_LEVEL "INFO" CACHE STRING "Level of logging to use for MCUboot [OFF, ERROR, WARNING, INFO, DEBUG]")
20+
set(TFM_BL2_LOG_LEVEL LOG_LEVEL_INFO CACHE STRING "Level of logging to use for BL2: LOG_LEVEL_[NONE, ERROR, WARNING, INFO, VERBOSE]")
2121
set(MCUBOOT_HW_KEY ON CACHE BOOL "Whether to embed the entire public key in the image metadata instead of the hash only")
2222
set(MCUBOOT_BUILTIN_KEY OFF CACHE BOOL "Use builtin key(s) for validation, no public key data is embedded into the image metadata")
2323
set(MCUBOOT_UPGRADE_STRATEGY "OVERWRITE_ONLY" CACHE STRING "Upgrade strategy for images")
@@ -26,21 +26,6 @@ set(BL2_TRAILER_SIZE 0x400 CACHE STRING "Trailer siz
2626
set(MCUBOOT_ALIGN_VAL 1 CACHE STRING "align option for mcuboot and build image with imgtool [1, 2, 4, 8, 16, 32]")
2727
set(MCUBOOT_CONFIRM_IMAGE OFF CACHE BOOL "Whether to confirm the image if REVERT is supported in MCUboot")
2828

29-
# Determine TF-M BL2 logging level based on configured MCUBOOT_LOG_LEVEL
30-
if(${MCUBOOT_LOG_LEVEL} STREQUAL "OFF")
31-
set(BL2_LOG_LEVEL "LOG_LEVEL_NONE" CACHE STRING "Level of logging defined in TF-M logging library")
32-
elseif(${MCUBOOT_LOG_LEVEL} STREQUAL "ERROR")
33-
set(BL2_LOG_LEVEL "LOG_LEVEL_ERROR" CACHE STRING "Level of logging defined in TF-M logging library")
34-
elseif(${MCUBOOT_LOG_LEVEL} STREQUAL "WARNING")
35-
set(BL2_LOG_LEVEL "LOG_LEVEL_WARNING" CACHE STRING "Level of logging defined in TF-M logging library")
36-
elseif(${MCUBOOT_LOG_LEVEL} STREQUAL "INFO")
37-
set(BL2_LOG_LEVEL "LOG_LEVEL_INFO" CACHE STRING "Level of logging defined in TF-M logging library")
38-
elseif(${MCUBOOT_LOG_LEVEL} STREQUAL "DEBUG")
39-
set(BL2_LOG_LEVEL "LOG_LEVEL_VERBOSE" CACHE STRING "Level of logging defined in TF-M logging library")
40-
else()
41-
message(FATAL_ERROR "Invalid MCUBOOT_LOG_LEVEL")
42-
endif()
43-
4429
# Specifying a scope of the accepted values of MCUBOOT_UPGRADE_STRATEGY for
4530
# platforms to choose a specific upgrade strategy for images. These certain
4631
# configurations will be used to facilitate the later validation.

config/build_type/Kconfig.minsizerel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#-------------------------------------------------------------------------------
77

88
if BL2
9-
config MCUBOOT_LOG_LEVEL
10-
default "OFF"
9+
config BL2_LOG_LEVEL
10+
default LOG_LEVEL_NONE
1111
endif
1212

1313
choice SPM_LOG_LEVEL

config/build_type/Kconfig.release

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ config BL1_2_BUILD_TYPE
1212
default "minsizerel"
1313

1414
if BL2
15-
config MCUBOOT_LOG_LEVEL
16-
default "OFF"
15+
config BL2_LOG_LEVEL
16+
default LOG_LEVEL_NONE
1717
endif
1818

1919
choice SPM_LOG_LEVEL

config/build_type/minsizerel.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
#-------------------------------------------------------------------------------
77

8-
set(MCUBOOT_LOG_LEVEL "OFF" CACHE STRING "Level of logging to use for MCUboot [OFF, ERROR, WARNING, INFO, DEBUG]")
8+
set(TFM_BL2_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Level of logging to use for BL2: LOG_LEVEL_[NONE, ERROR, WARNING, INFO, VERBOSE]")
99
set(TFM_SPM_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set minsizerel SPM log level as Silence level")
1010
set(TFM_PARTITION_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set minsizerel SP log level as Silence level")
1111
set(TFM_BL1_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "The level of BL1 logging to uart")

config/build_type/release.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
set(MBEDCRYPTO_BUILD_TYPE minsizerel CACHE STRING "Build type of Mbed Crypto library")
99
set(BL1_2_BUILD_TYPE minsizerel CACHE STRING "Build type of BL1_2")
10-
set(MCUBOOT_LOG_LEVEL "OFF" CACHE STRING "Level of logging to use for MCUboot [OFF, ERROR, WARNING, INFO, DEBUG]")
10+
set(TFM_BL2_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Level of logging to use for BL2: LOG_LEVEL_[NONE, ERROR, WARNING, INFO, VERBOSE]")
1111
set(TFM_SPM_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set release SPM log level as Silence level")
1212
set(TFM_PARTITION_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "Set release SP log level as Silence level")
1313
set(TFM_BL1_LOG_LEVEL LOG_LEVEL_NONE CACHE STRING "The level of BL1 logging to uart")

0 commit comments

Comments
 (0)