From 0d97c63885959aec7b7ff189c6d501dacfef9892 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Tue, 2 Sep 2025 16:24:13 +0300 Subject: [PATCH] change(coredump): make conditional build in cmake based on config options --- components/espcoredump/CMakeLists.txt | 62 +++++++++++-------- .../espcoredump/include/esp_core_dump.h | 3 +- .../port/riscv/esp_core_dump_summary_port.h | 4 -- .../port/xtensa/esp_core_dump_summary_port.h | 4 -- components/espcoredump/src/core_dump_common.c | 4 -- components/espcoredump/src/core_dump_elf.c | 4 -- components/espcoredump/src/core_dump_flash.c | 4 -- components/espcoredump/src/core_dump_init.c | 4 -- components/espcoredump/src/core_dump_sha.c | 4 -- components/espcoredump/src/core_dump_uart.c | 4 -- .../src/port/riscv/core_dump_port.c | 4 -- .../src/port/xtensa/core_dump_port.c | 4 -- .../espcoredump/test_apps/sdkconfig.defaults | 1 + tools/test_apps/system/panic/CMakeLists.txt | 18 ++++-- .../test_apps/system/panic/main/test_panic.c | 2 + 15 files changed, 55 insertions(+), 71 deletions(-) diff --git a/components/espcoredump/CMakeLists.txt b/components/espcoredump/CMakeLists.txt index 892ed2ca17..98bd9c5f1b 100644 --- a/components/espcoredump/CMakeLists.txt +++ b/components/espcoredump/CMakeLists.txt @@ -4,36 +4,46 @@ if(${target} STREQUAL "linux") return() # This component is not supported by the POSIX/Linux simulator endif() -set(srcs "src/core_dump_init.c" - "src/core_dump_common.c" - "src/core_dump_flash.c" - "src/core_dump_uart.c" - "src/core_dump_elf.c" - "src/core_dump_sha.c") +set(srcs "") +set(includes "") +set(priv_includes "") +set(priv_requires + esp_partition spi_flash bootloader_support mbedtls esp_rom soc esp_system esp_driver_gpio esp_app_format) -set(includes "include") -set(priv_includes "include_core_dump") +if(CONFIG_ESP_COREDUMP_ENABLE) + list(APPEND srcs "src/core_dump_init.c" + "src/core_dump_common.c" + "src/core_dump_elf.c" + "src/core_dump_sha.c") -idf_build_get_property(target IDF_TARGET) + if(CONFIG_ESP_COREDUMP_ENABLE_TO_UART) + list(APPEND srcs "src/core_dump_uart.c") + elseif(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH) + list(APPEND srcs "src/core_dump_flash.c") + endif() -if(CONFIG_IDF_TARGET_ARCH_XTENSA) - list(APPEND srcs "src/port/xtensa/core_dump_port.c") - list(APPEND includes "include/port/xtensa") - list(APPEND priv_includes "include_core_dump/port/xtensa") -elseif(CONFIG_IDF_TARGET_ARCH_RISCV) - list(APPEND srcs "src/port/riscv/core_dump_port.c") - list(APPEND includes "include/port/riscv") - list(APPEND priv_includes "include_core_dump/port/riscv") -endif() + list(APPEND includes "include") + list(APPEND priv_includes "include_core_dump") -idf_component_register(SRCS ${srcs} - INCLUDE_DIRS ${includes} - PRIV_INCLUDE_DIRS ${priv_includes} - LDFRAGMENTS linker.lf - PRIV_REQUIRES esp_partition spi_flash bootloader_support mbedtls esp_rom soc esp_system - esp_driver_gpio - ) + if(CONFIG_IDF_TARGET_ARCH_XTENSA) + list(APPEND srcs "src/port/xtensa/core_dump_port.c") + list(APPEND includes "include/port/xtensa") + list(APPEND priv_includes "include_core_dump/port/xtensa") + elseif(CONFIG_IDF_TARGET_ARCH_RISCV) + list(APPEND srcs "src/port/riscv/core_dump_port.c") + list(APPEND includes "include/port/riscv") + list(APPEND priv_includes "include_core_dump/port/riscv") + endif() + + idf_component_register(SRCS ${srcs} + INCLUDE_DIRS ${includes} + PRIV_INCLUDE_DIRS ${priv_includes} + LDFRAGMENTS linker.lf + PRIV_REQUIRES ${priv_requires} + ) # make sure 'core_dump_init' object file is considered by the linker target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_system_include_coredump_init") -target_link_libraries(${COMPONENT_LIB} PRIVATE idf::esp_app_format) +else() + idf_component_register(PRIV_REQUIRES ${priv_requires}) +endif() diff --git a/components/espcoredump/include/esp_core_dump.h b/components/espcoredump/include/esp_core_dump.h index 454651d871..67e6b3ee2c 100644 --- a/components/espcoredump/include/esp_core_dump.h +++ b/components/espcoredump/include/esp_core_dump.h @@ -10,7 +10,6 @@ #include #include "esp_err.h" #include "esp_private/panic_internal.h" -#include "esp_core_dump_summary_port.h" #ifdef __cplusplus extern "C" { @@ -20,6 +19,8 @@ extern "C" { #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH +#include "esp_core_dump_summary_port.h" + /** * @brief Core dump summary, Most meaningful contents of the core dump * are accommodated in this structure diff --git a/components/espcoredump/include/port/riscv/esp_core_dump_summary_port.h b/components/espcoredump/include/port/riscv/esp_core_dump_summary_port.h index de935f1ef4..212ed7da51 100644 --- a/components/espcoredump/include/port/riscv/esp_core_dump_summary_port.h +++ b/components/espcoredump/include/port/riscv/esp_core_dump_summary_port.h @@ -12,8 +12,6 @@ extern "C" { #endif -#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH - /** * @brief Backtrace information * @@ -40,8 +38,6 @@ typedef struct { uint32_t exc_a[8]; /* A0-A7 registers when the exception caused */ } esp_core_dump_summary_extra_info_t; -#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ - #ifdef __cplusplus } #endif diff --git a/components/espcoredump/include/port/xtensa/esp_core_dump_summary_port.h b/components/espcoredump/include/port/xtensa/esp_core_dump_summary_port.h index 0bc67650bc..787910aea5 100644 --- a/components/espcoredump/include/port/xtensa/esp_core_dump_summary_port.h +++ b/components/espcoredump/include/port/xtensa/esp_core_dump_summary_port.h @@ -13,8 +13,6 @@ extern "C" { #endif -#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH - #define EPCx_REGISTER_COUNT XCHAL_NUM_INTLEVELS /** @@ -39,8 +37,6 @@ typedef struct { uint8_t epcx_reg_bits; /*!< Bit mask of available EPCx registers */ } esp_core_dump_summary_extra_info_t; -#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ - #ifdef __cplusplus } #endif diff --git a/components/espcoredump/src/core_dump_common.c b/components/espcoredump/src/core_dump_common.c index 5f3b833a32..308220cfa1 100644 --- a/components/espcoredump/src/core_dump_common.c +++ b/components/espcoredump/src/core_dump_common.c @@ -5,8 +5,6 @@ */ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE - #include #include #include "soc/soc_memory_layout.h" @@ -345,5 +343,3 @@ void esp_core_dump_write(panic_info_t *info) esp_core_dump_write_internal(info); esp_core_dump_print_write_end(); } - -#endif // CONFIG_ESP_COREDUMP_ENABLE diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index 68e43b93fe..32ca0047ec 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -5,8 +5,6 @@ */ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE - #include #include "esp_attr.h" #include "esp_partition.h" @@ -1061,5 +1059,3 @@ esp_err_t esp_core_dump_get_summary(esp_core_dump_summary_t *summary) } #endif // CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH - -#endif // CONFIG_ESP_COREDUMP_ENABLE diff --git a/components/espcoredump/src/core_dump_flash.c b/components/espcoredump/src/core_dump_flash.c index 4d54842b81..2873b48a19 100644 --- a/components/espcoredump/src/core_dump_flash.c +++ b/components/espcoredump/src/core_dump_flash.c @@ -5,8 +5,6 @@ */ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH - #include #include "esp_partition.h" #include "esp_log.h" @@ -522,5 +520,3 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size) return ESP_OK; } - -#endif // CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH diff --git a/components/espcoredump/src/core_dump_init.c b/components/espcoredump/src/core_dump_init.c index 8b0932b3b9..79f473a165 100644 --- a/components/espcoredump/src/core_dump_init.c +++ b/components/espcoredump/src/core_dump_init.c @@ -5,8 +5,6 @@ */ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE - #include "esp_private/startup_internal.h" #include "esp_core_dump.h" @@ -20,5 +18,3 @@ ESP_SYSTEM_INIT_FN(init_coredump, SECONDARY, BIT(0), 130) esp_core_dump_init(); return ESP_OK; } - -#endif /* CONFIG_ESP_COREDUMP_ENABLE */ diff --git a/components/espcoredump/src/core_dump_sha.c b/components/espcoredump/src/core_dump_sha.c index fc032fb5c1..e77fd44745 100644 --- a/components/espcoredump/src/core_dump_sha.c +++ b/components/espcoredump/src/core_dump_sha.c @@ -5,8 +5,6 @@ */ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE - #include #include "esp_core_dump_types.h" @@ -123,5 +121,3 @@ static uint32_t core_dump_sha_finish(core_dump_checksum_ctx cks_ctx, core_dump_c return core_dump_sha_size(); } - -#endif // CONFIG_ESP_COREDUMP_ENABLE diff --git a/components/espcoredump/src/core_dump_uart.c b/components/espcoredump/src/core_dump_uart.c index d6e98f0b14..94af38761e 100644 --- a/components/espcoredump/src/core_dump_uart.c +++ b/components/espcoredump/src/core_dump_uart.c @@ -5,8 +5,6 @@ */ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE_TO_UART - #include #include "soc/uart_reg.h" #include "soc/gpio_periph.h" @@ -178,5 +176,3 @@ void esp_core_dump_init(void) { ESP_COREDUMP_LOGI("Init core dump to UART"); } - -#endif // CONFIG_ESP_COREDUMP_ENABLE_TO_UART diff --git a/components/espcoredump/src/port/riscv/core_dump_port.c b/components/espcoredump/src/port/riscv/core_dump_port.c index 395a2a3fcc..84cfca9a67 100644 --- a/components/espcoredump/src/port/riscv/core_dump_port.c +++ b/components/espcoredump/src/port/riscv/core_dump_port.c @@ -11,8 +11,6 @@ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE - #include #include #include "soc/soc_memory_layout.h" @@ -448,5 +446,3 @@ void esp_core_dump_summary_parse_backtrace_info(esp_core_dump_bt_info_t *bt_info } #endif /* #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ - -#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ diff --git a/components/espcoredump/src/port/xtensa/core_dump_port.c b/components/espcoredump/src/port/xtensa/core_dump_port.c index 2030a271fa..4b9699b0c8 100644 --- a/components/espcoredump/src/port/xtensa/core_dump_port.c +++ b/components/espcoredump/src/port/xtensa/core_dump_port.c @@ -11,8 +11,6 @@ #include "sdkconfig.h" -#if CONFIG_ESP_COREDUMP_ENABLE - #include #include #include "soc/soc_memory_layout.h" @@ -565,6 +563,4 @@ void esp_core_dump_summary_parse_backtrace_info(esp_core_dump_bt_info_t *bt_info bt_info->corrupted = corrupted; } -#endif /* #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ - #endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ diff --git a/components/espcoredump/test_apps/sdkconfig.defaults b/components/espcoredump/test_apps/sdkconfig.defaults index 7b569fa075..247d7f7915 100644 --- a/components/espcoredump/test_apps/sdkconfig.defaults +++ b/components/espcoredump/test_apps/sdkconfig.defaults @@ -1 +1,2 @@ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n +CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y diff --git a/tools/test_apps/system/panic/CMakeLists.txt b/tools/test_apps/system/panic/CMakeLists.txt index 274b36a93b..5eced74c45 100644 --- a/tools/test_apps/system/panic/CMakeLists.txt +++ b/tools/test_apps/system/panic/CMakeLists.txt @@ -2,7 +2,12 @@ # in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.22) -set(COMPONENTS main espcoredump esp_gdbstub) +set(COMPONENTS main esp_gdbstub) + +if(CONFIG_ESP_COREDUMP_ENABLE) + list(APPEND COMPONENTS espcoredump) +endif() + include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(test_panic) @@ -32,11 +37,16 @@ if(NOT CONFIG_TEST_MEMPROT AND NOT CONFIG_ESP_COREDUMP_CAPTURE_DRAM) # Only enable UBSAN for a few components related to the panic test, # due to RAM size limitations. - set(ubsan_components main espcoredump esp_system spi_flash + set(ubsan_components main esp_system spi_flash esp_common esp_hw_support soc hal freertos) + + if(CONFIG_ESP_COREDUMP_ENABLE AND NOT CONFIG_IDF_TARGET_ESP32S2) + list(APPEND ubsan_components espcoredump) + endif() + if(CONFIG_IDF_TARGET_ESP32S2) - # due to the ram limitation, coredump and freertos are removed from esp32s2 built - list(REMOVE_ITEM ubsan_components espcoredump freertos) + # due to the ram limitation, freertos is removed from esp32s2 built + list(REMOVE_ITEM ubsan_components freertos) endif() foreach(component IN LISTS ubsan_components) idf_component_get_property(lib ${component} COMPONENT_LIB) diff --git a/tools/test_apps/system/panic/main/test_panic.c b/tools/test_apps/system/panic/main/test_panic.c index 53d78cc826..d3fe573b85 100644 --- a/tools/test_apps/system/panic/main/test_panic.c +++ b/tools/test_apps/system/panic/main/test_panic.c @@ -13,7 +13,9 @@ #include "esp_flash.h" #include "esp_system.h" #include "spi_flash_mmap.h" +#if CONFIG_ESP_COREDUMP_ENABLE #include "esp_core_dump.h" +#endif #include "esp_private/cache_utils.h" #include "esp_memory_utils.h"