1 /*
2  * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include "sdkconfig.h"
10 #include "mcuboot_config.h"
11 
12 extern int ets_printf(const char *fmt, ...);
13 
14 #define MCUBOOT_LOG_LEVEL_OFF      0
15 #define MCUBOOT_LOG_LEVEL_ERROR    1
16 #define MCUBOOT_LOG_LEVEL_WARNING  2
17 #define MCUBOOT_LOG_LEVEL_INFO     3
18 #define MCUBOOT_LOG_LEVEL_DEBUG    4
19 
20 #if CONFIG_IDF_TARGET_ESP32
21 #define TARGET "[esp32]"
22 #elif CONFIG_IDF_TARGET_ESP32S2
23 #define TARGET "[esp32s2]"
24 #elif CONFIG_IDF_TARGET_ESP32S3
25 #define TARGET "[esp32s3]"
26 #elif CONFIG_IDF_TARGET_ESP32C3
27 #define TARGET "[esp32c3]"
28 #elif CONFIG_IDF_TARGET_ESP32C6
29 #define TARGET "[esp32c6]"
30 #elif CONFIG_IDF_TARGET_ESP32C2
31 #define TARGET "[esp32c2]"
32 #elif CONFIG_IDF_TARGET_ESP32H2
33 #define TARGET "[esp32h2]"
34 #else
35 #error "Selected target not supported."
36 #endif
37 
38 #ifndef MCUBOOT_LOG_LEVEL
39 #define MCUBOOT_LOG_LEVEL MCUBOOT_LOG_LEVEL_INFO
40 #endif
41 
42 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_ERROR
43 #define MCUBOOT_LOG_ERR(_fmt, ...)                                      \
44     do {                                                                \
45             ets_printf(TARGET " [ERR] " _fmt "\n\r", ##__VA_ARGS__);         \
46     } while (0)
47 #else
48 #define MCUBOOT_LOG_ERR(_fmt, ...)
49 #endif
50 
51 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_WARNING
52 #define MCUBOOT_LOG_WRN(_fmt, ...)                                      \
53     do {                                                                \
54             ets_printf(TARGET " [WRN] " _fmt "\n\r", ##__VA_ARGS__);         \
55     } while (0)
56 #else
57 #define MCUBOOT_LOG_WRN(_fmt, ...)
58 #endif
59 
60 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_INFO
61 #define MCUBOOT_LOG_INF(_fmt, ...)                                      \
62     do {                                                                \
63             ets_printf(TARGET " [INF] " _fmt "\n\r", ##__VA_ARGS__);         \
64     } while (0)
65 #else
66 #define MCUBOOT_LOG_INF(_fmt, ...)
67 #endif
68 
69 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_DEBUG
70 #define MCUBOOT_LOG_DBG(_fmt, ...)                                      \
71     do {                                                                \
72             ets_printf(TARGET " [DBG] " _fmt "\n\r", ##__VA_ARGS__);         \
73     } while (0)
74 #else
75 #define MCUBOOT_LOG_DBG(_fmt, ...)
76 #endif
77 
78 #define MCUBOOT_LOG_MODULE_DECLARE(...)
79 #define MCUBOOT_LOG_MODULE_REGISTER(...)
80