change(coredump): make conditional build in cmake based on config options

This commit is contained in:
Erhan Kurubas
2025-09-02 16:24:13 +03:00
committed by BOT
parent aae5071dff
commit 0d97c63885
15 changed files with 55 additions and 71 deletions

View File

@@ -4,36 +4,46 @@ if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator return() # This component is not supported by the POSIX/Linux simulator
endif() endif()
set(srcs "src/core_dump_init.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)
if(CONFIG_ESP_COREDUMP_ENABLE)
list(APPEND srcs "src/core_dump_init.c"
"src/core_dump_common.c" "src/core_dump_common.c"
"src/core_dump_flash.c"
"src/core_dump_uart.c"
"src/core_dump_elf.c" "src/core_dump_elf.c"
"src/core_dump_sha.c") "src/core_dump_sha.c")
set(includes "include") if(CONFIG_ESP_COREDUMP_ENABLE_TO_UART)
set(priv_includes "include_core_dump") list(APPEND srcs "src/core_dump_uart.c")
elseif(CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH)
list(APPEND srcs "src/core_dump_flash.c")
endif()
idf_build_get_property(target IDF_TARGET) list(APPEND includes "include")
list(APPEND priv_includes "include_core_dump")
if(CONFIG_IDF_TARGET_ARCH_XTENSA) if(CONFIG_IDF_TARGET_ARCH_XTENSA)
list(APPEND srcs "src/port/xtensa/core_dump_port.c") list(APPEND srcs "src/port/xtensa/core_dump_port.c")
list(APPEND includes "include/port/xtensa") list(APPEND includes "include/port/xtensa")
list(APPEND priv_includes "include_core_dump/port/xtensa") list(APPEND priv_includes "include_core_dump/port/xtensa")
elseif(CONFIG_IDF_TARGET_ARCH_RISCV) elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
list(APPEND srcs "src/port/riscv/core_dump_port.c") list(APPEND srcs "src/port/riscv/core_dump_port.c")
list(APPEND includes "include/port/riscv") list(APPEND includes "include/port/riscv")
list(APPEND priv_includes "include_core_dump/port/riscv") list(APPEND priv_includes "include_core_dump/port/riscv")
endif() endif()
idf_component_register(SRCS ${srcs} idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${includes} INCLUDE_DIRS ${includes}
PRIV_INCLUDE_DIRS ${priv_includes} PRIV_INCLUDE_DIRS ${priv_includes}
LDFRAGMENTS linker.lf LDFRAGMENTS linker.lf
PRIV_REQUIRES esp_partition spi_flash bootloader_support mbedtls esp_rom soc esp_system PRIV_REQUIRES ${priv_requires}
esp_driver_gpio
) )
# make sure 'core_dump_init' object file is considered by the linker # 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} 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()

View File

@@ -10,7 +10,6 @@
#include <stddef.h> #include <stddef.h>
#include "esp_err.h" #include "esp_err.h"
#include "esp_private/panic_internal.h" #include "esp_private/panic_internal.h"
#include "esp_core_dump_summary_port.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -20,6 +19,8 @@ extern "C" {
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH #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 * @brief Core dump summary, Most meaningful contents of the core dump
* are accommodated in this structure * are accommodated in this structure

View File

@@ -12,8 +12,6 @@ extern "C"
{ {
#endif #endif
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH
/** /**
* @brief Backtrace information * @brief Backtrace information
* *
@@ -40,8 +38,6 @@ typedef struct {
uint32_t exc_a[8]; /* A0-A7 registers when the exception caused */ uint32_t exc_a[8]; /* A0-A7 registers when the exception caused */
} esp_core_dump_summary_extra_info_t; } esp_core_dump_summary_extra_info_t;
#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -13,8 +13,6 @@ extern "C"
{ {
#endif #endif
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH
#define EPCx_REGISTER_COUNT XCHAL_NUM_INTLEVELS #define EPCx_REGISTER_COUNT XCHAL_NUM_INTLEVELS
/** /**
@@ -39,8 +37,6 @@ typedef struct {
uint8_t epcx_reg_bits; /*!< Bit mask of available EPCx registers */ uint8_t epcx_reg_bits; /*!< Bit mask of available EPCx registers */
} esp_core_dump_summary_extra_info_t; } esp_core_dump_summary_extra_info_t;
#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -5,8 +5,6 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include "soc/soc_memory_layout.h" #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_write_internal(info);
esp_core_dump_print_write_end(); esp_core_dump_print_write_end();
} }
#endif // CONFIG_ESP_COREDUMP_ENABLE

View File

@@ -5,8 +5,6 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include <string.h> #include <string.h>
#include "esp_attr.h" #include "esp_attr.h"
#include "esp_partition.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_TO_FLASH
#endif // CONFIG_ESP_COREDUMP_ENABLE

View File

@@ -5,8 +5,6 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH
#include <string.h> #include <string.h>
#include "esp_partition.h" #include "esp_partition.h"
#include "esp_log.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; return ESP_OK;
} }
#endif // CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH

View File

@@ -5,8 +5,6 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include "esp_private/startup_internal.h" #include "esp_private/startup_internal.h"
#include "esp_core_dump.h" #include "esp_core_dump.h"
@@ -20,5 +18,3 @@ ESP_SYSTEM_INIT_FN(init_coredump, SECONDARY, BIT(0), 130)
esp_core_dump_init(); esp_core_dump_init();
return ESP_OK; return ESP_OK;
} }
#endif /* CONFIG_ESP_COREDUMP_ENABLE */

View File

@@ -5,8 +5,6 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include <string.h> #include <string.h>
#include "esp_core_dump_types.h" #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(); return core_dump_sha_size();
} }
#endif // CONFIG_ESP_COREDUMP_ENABLE

View File

@@ -5,8 +5,6 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE_TO_UART
#include <string.h> #include <string.h>
#include "soc/uart_reg.h" #include "soc/uart_reg.h"
#include "soc/gpio_periph.h" #include "soc/gpio_periph.h"
@@ -178,5 +176,3 @@ void esp_core_dump_init(void)
{ {
ESP_COREDUMP_LOGI("Init core dump to UART"); ESP_COREDUMP_LOGI("Init core dump to UART");
} }
#endif // CONFIG_ESP_COREDUMP_ENABLE_TO_UART

View File

@@ -11,8 +11,6 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include "soc/soc_memory_layout.h" #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 /* #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */
#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */

View File

@@ -11,8 +11,6 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include "soc/soc_memory_layout.h" #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; bt_info->corrupted = corrupted;
} }
#endif /* #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */
#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */ #endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */

View File

@@ -1 +1,2 @@
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y

View File

@@ -2,7 +2,12 @@
# in this exact order for cmake to work correctly # in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.22) 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) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(test_panic) 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, # Only enable UBSAN for a few components related to the panic test,
# due to RAM size limitations. # 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) 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) if(CONFIG_IDF_TARGET_ESP32S2)
# due to the ram limitation, coredump and freertos are removed from esp32s2 built # due to the ram limitation, freertos is removed from esp32s2 built
list(REMOVE_ITEM ubsan_components espcoredump freertos) list(REMOVE_ITEM ubsan_components freertos)
endif() endif()
foreach(component IN LISTS ubsan_components) foreach(component IN LISTS ubsan_components)
idf_component_get_property(lib ${component} COMPONENT_LIB) idf_component_get_property(lib ${component} COMPONENT_LIB)

View File

@@ -13,7 +13,9 @@
#include "esp_flash.h" #include "esp_flash.h"
#include "esp_system.h" #include "esp_system.h"
#include "spi_flash_mmap.h" #include "spi_flash_mmap.h"
#if CONFIG_ESP_COREDUMP_ENABLE
#include "esp_core_dump.h" #include "esp_core_dump.h"
#endif
#include "esp_private/cache_utils.h" #include "esp_private/cache_utils.h"
#include "esp_memory_utils.h" #include "esp_memory_utils.h"