1 /* 2 * Copyright (c) 2023 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 #else 29 #error "Selected target not supported." 30 #endif 31 32 #ifndef MCUBOOT_LOG_LEVEL 33 #define MCUBOOT_LOG_LEVEL MCUBOOT_LOG_LEVEL_INFO 34 #endif 35 36 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_ERROR 37 #define MCUBOOT_LOG_ERR(_fmt, ...) \ 38 do { \ 39 ets_printf(TARGET " [ERR] " _fmt "\n\r", ##__VA_ARGS__); \ 40 } while (0) 41 #else 42 #define MCUBOOT_LOG_ERR(_fmt, ...) 43 #endif 44 45 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_WARNING 46 #define MCUBOOT_LOG_WRN(_fmt, ...) \ 47 do { \ 48 ets_printf(TARGET " [WRN] " _fmt "\n\r", ##__VA_ARGS__); \ 49 } while (0) 50 #else 51 #define MCUBOOT_LOG_WRN(_fmt, ...) 52 #endif 53 54 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_INFO 55 #define MCUBOOT_LOG_INF(_fmt, ...) \ 56 do { \ 57 ets_printf(TARGET " [INF] " _fmt "\n\r", ##__VA_ARGS__); \ 58 } while (0) 59 #else 60 #define MCUBOOT_LOG_INF(_fmt, ...) 61 #endif 62 63 #if MCUBOOT_LOG_LEVEL >= MCUBOOT_LOG_LEVEL_DEBUG 64 #define MCUBOOT_LOG_DBG(_fmt, ...) \ 65 do { \ 66 ets_printf(TARGET " [DBG] " _fmt "\n\r", ##__VA_ARGS__); \ 67 } while (0) 68 #else 69 #define MCUBOOT_LOG_DBG(_fmt, ...) 70 #endif 71 72 #define MCUBOOT_LOG_MODULE_DECLARE(...) 73 #define MCUBOOT_LOG_MODULE_REGISTER(...) 74