Boot: Move logging macros to project specific file
Move the logging macros to mcuboot_logging.h and add another project
specific mcuboot_config.h file as they are needed to build TF-M with
upstream MCUBoot.
Change-Id: I01d0c6aed028f8e9c6db6acfd290e12afd3dfdc1
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/bl2/ext/mcuboot/CMakeLists.txt b/bl2/ext/mcuboot/CMakeLists.txt
index 8d7aa35..2f47f6c 100644
--- a/bl2/ext/mcuboot/CMakeLists.txt
+++ b/bl2/ext/mcuboot/CMakeLists.txt
@@ -211,7 +211,7 @@
#Configure log level for MCUBoot.
get_property(_log_levels CACHE MCUBOOT_LOG_LEVEL PROPERTY STRINGS)
list(FIND _log_levels ${MCUBOOT_LOG_LEVEL} LOG_LEVEL_ID)
-target_compile_definitions(${PROJECT_NAME} PRIVATE BOOT_LOG_LEVEL=${LOG_LEVEL_ID})
+target_compile_definitions(${PROJECT_NAME} PRIVATE MCUBOOT_LOG_LEVEL=${LOG_LEVEL_ID})
#Set install location. Keep original value to avoid overriding command line settings.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
diff --git a/bl2/ext/mcuboot/bl2_main.c b/bl2/ext/mcuboot/bl2_main.c
index 641fd95..be231b0 100644
--- a/bl2/ext/mcuboot/bl2_main.c
+++ b/bl2/ext/mcuboot/bl2_main.c
@@ -28,7 +28,7 @@
#include "bl2/include/boot_record.h"
#include "security_cnt.h"
#include "bl2/include/boot_hal.h"
-#if BOOT_LOG_LEVEL > BOOT_LOG_LEVEL_OFF
+#if MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF
#include "uart_stdout.h"
#endif
#if defined(CRYPTO_HW_ACCELERATOR) || \
@@ -134,7 +134,7 @@
BOOT_LOG_ERR("Error while uninitializing Flash Interface");
}
-#if BOOT_LOG_LEVEL > BOOT_LOG_LEVEL_OFF
+#if MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF
stdio_uninit();
#endif
@@ -166,7 +166,7 @@
__set_MSPLIM(msp_stack_bottom);
#endif
-#if BOOT_LOG_LEVEL > BOOT_LOG_LEVEL_OFF
+#if MCUBOOT_LOG_LEVEL > MCUBOOT_LOG_LEVEL_OFF
stdio_init();
#endif
diff --git a/bl2/ext/mcuboot/bootutil/include/bootutil/bootutil_log.h b/bl2/ext/mcuboot/bootutil/include/bootutil/bootutil_log.h
index ba161d4..c7bb70f 100644
--- a/bl2/ext/mcuboot/bootutil/include/bootutil/bootutil_log.h
+++ b/bl2/ext/mcuboot/bootutil/include/bootutil/bootutil_log.h
@@ -23,51 +23,24 @@
extern "C" {
#endif
-#include <stdio.h>
+#include <mcuboot_config/mcuboot_config.h>
+#include <mcuboot_config/mcuboot_logging.h>
-#define BOOT_LOG_LEVEL_OFF 0
-#define BOOT_LOG_LEVEL_ERROR 1
-#define BOOT_LOG_LEVEL_WARNING 2
-#define BOOT_LOG_LEVEL_INFO 3
-#define BOOT_LOG_LEVEL_DEBUG 4
+#ifdef MCUBOOT_HAVE_LOGGING
-/*
- * The compiled log level determines the maximum level that can be
- * printed. Messages at or below this level can be printed.
- */
-#ifndef BOOT_LOG_LEVEL
-#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
-#endif
+#define BOOT_LOG_ERR(...) MCUBOOT_LOG_ERR(__VA_ARGS__)
+#define BOOT_LOG_WRN(...) MCUBOOT_LOG_WRN(__VA_ARGS__)
+#define BOOT_LOG_INF(...) MCUBOOT_LOG_INF(__VA_ARGS__)
+#define BOOT_LOG_DBG(...) MCUBOOT_LOG_DBG(__VA_ARGS__)
-int sim_log_enabled(int level);
-
-#if BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_ERROR
-#define BOOT_LOG_ERR(_fmt, ...) \
- printf("[ERR] " _fmt "\r\n", ##__VA_ARGS__)
#else
+
#define BOOT_LOG_ERR(...) IGNORE(__VA_ARGS__)
-#endif
-
-#if BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_WARNING
-#define BOOT_LOG_WRN(_fmt, ...) \
- printf("[WRN] " _fmt "\r\n", ##__VA_ARGS__)
-#else
#define BOOT_LOG_WRN(...) IGNORE(__VA_ARGS__)
-#endif
-
-#if BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_INFO
-#define BOOT_LOG_INF(_fmt, ...) \
- printf("[INF] " _fmt "\r\n", ##__VA_ARGS__)
-#else
#define BOOT_LOG_INF(...) IGNORE(__VA_ARGS__)
-#endif
-
-#if BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_DEBUG
-#define BOOT_LOG_DBG(_fmt, ...) \
- printf("[DBG] " _fmt "\r\n", ##__VA_ARGS__)
-#else
#define BOOT_LOG_DBG(...) IGNORE(__VA_ARGS__)
-#endif
+
+#endif /* MCUBOOT_HAVE_LOGGING */
#ifdef __cplusplus
}
diff --git a/bl2/ext/mcuboot/include/mcuboot_config/mcuboot_config.h b/bl2/ext/mcuboot/include/mcuboot_config/mcuboot_config.h
new file mode 100644
index 0000000..a0dfe09
--- /dev/null
+++ b/bl2/ext/mcuboot/include/mcuboot_config/mcuboot_config.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018 Open Source Foundries Limited
+ * Copyright (c) 2019 Arm Limited
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/*
+ * Original code taken from mcuboot project at:
+ * https://github.com/JuulLabs-OSS/mcuboot
+ * Git SHA of the original version: ac55554059147fff718015be9f4bd3108123f50a
+ */
+
+#ifndef __MCUBOOT_CONFIG_H__
+#define __MCUBOOT_CONFIG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This file is also included by the simulator, but we don't want to
+ * define anything here in simulator builds.
+ *
+ * Instead of using mcuboot_config.h, the simulator adds MCUBOOT_xxx
+ * configuration flags to the compiler command lines based on the
+ * values of environment variables. However, the file still must
+ * exist, or bootutil won't build.
+ */
+#ifndef __BOOTSIM__
+
+/*
+ * In TF-M most of the configuration flags (e.g. signature type,
+ * upgrade mode ...) are handled by the CMake-based buildsystem and
+ * added to the compiler command lines.
+ */
+
+/*
+ * Cryptographic settings
+ */
+#define MCUBOOT_USE_MBED_TLS
+
+/*
+ * Logging
+ */
+#define MCUBOOT_HAVE_LOGGING 1
+
+#endif /* !__BOOTSIM__ */
+
+/*
+ * Watchdog feeding
+ */
+#define MCUBOOT_WATCHDOG_FEED() \
+ do { \
+ /* Do nothing. */ \
+ } while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MCUBOOT_CONFIG_H__ */
diff --git a/bl2/ext/mcuboot/include/mcuboot_config/mcuboot_logging.h b/bl2/ext/mcuboot/include/mcuboot_config/mcuboot_logging.h
new file mode 100644
index 0000000..f4bb1ec
--- /dev/null
+++ b/bl2/ext/mcuboot/include/mcuboot_config/mcuboot_logging.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2017 Linaro Limited
+ * Copyright (c) 2019 Arm Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MCUBOOT_LOGGING_H__
+#define __MCUBOOT_LOGGING_H__
+
+#include "bootutil/ignore.h"
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MCUBOOT_LOG_LEVEL_OFF 0
+#define MCUBOOT_LOG_LEVEL_ERROR 1
+#define MCUBOOT_LOG_LEVEL_WARNING 2
+#define MCUBOOT_LOG_LEVEL_INFO 3
+#define MCUBOOT_LOG_LEVEL_DEBUG 4
+
+/*
+ * The compiled log level determines the maximum level that can be
+ * printed. Messages at or below this level can be printed.
+ */
+#ifndef MCUBOOT_LOG_LEVEL
+#define MCUBOOT_LOG_LEVEL MCUBOOT_LOG_LEVEL_INFO
+#endif
+
+#define MCUBOOT_LOG_MODULE_DECLARE(domain) /* Ignore */
+#define MCUBOOT_LOG_MODULE_REGISTER(domain) /* Ignore */
+
+#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_ERROR
+#define MCUBOOT_LOG_ERR(_fmt, ...) \
+ printf("[ERR] " _fmt "\r\n", ##__VA_ARGS__)
+#else
+#define MCUBOOT_LOG_ERR(...) IGNORE(__VA_ARGS__)
+#endif
+
+#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_WARNING
+#define MCUBOOT_LOG_WRN(_fmt, ...) \
+ printf("[WRN] " _fmt "\r\n", ##__VA_ARGS__)
+#else
+#define MCUBOOT_LOG_WRN(...) IGNORE(__VA_ARGS__)
+#endif
+
+#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_INFO
+#define MCUBOOT_LOG_INF(_fmt, ...) \
+ printf("[INF] " _fmt "\r\n", ##__VA_ARGS__)
+#else
+#define MCUBOOT_LOG_INF(...) IGNORE(__VA_ARGS__)
+#endif
+
+#if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_DEBUG
+#define MCUBOOT_LOG_DBG(_fmt, ...) \
+ printf("[DBG] " _fmt "\r\n", ##__VA_ARGS__)
+#else
+#define MCUBOOT_LOG_DBG(...) IGNORE(__VA_ARGS__)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MCUBOOT_LOGGING_H__ */