From 50ab1bff4ba9909e3b54dd1d47d769b1a39c6832 Mon Sep 17 00:00:00 2001 From: Erhan Kurubas Date: Sat, 2 Aug 2025 08:27:27 +0300 Subject: [PATCH] fix(coredump): do not build sources when coredump is not enabled --- components/espcoredump/include/esp_core_dump.h | 3 +-- components/espcoredump/src/core_dump_common.c | 11 ++++++----- components/espcoredump/src/core_dump_elf.c | 7 ++++++- components/espcoredump/src/core_dump_flash.c | 12 +++++++----- components/espcoredump/src/core_dump_sha.c | 7 +++++-- components/espcoredump/src/core_dump_uart.c | 11 +++++++---- .../espcoredump/src/port/riscv/core_dump_port.c | 8 +++++--- .../espcoredump/src/port/xtensa/core_dump_port.c | 8 +++++--- 8 files changed, 42 insertions(+), 25 deletions(-) diff --git a/components/espcoredump/include/esp_core_dump.h b/components/espcoredump/include/esp_core_dump.h index 4c741d282f..454651d871 100644 --- a/components/espcoredump/include/esp_core_dump.h +++ b/components/espcoredump/include/esp_core_dump.h @@ -80,6 +80,7 @@ void esp_core_dump_init(void); */ void esp_core_dump_write(panic_info_t *info); +#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH /** * @brief Check integrity of coredump data in flash. * This function reads the coredump data while calculating their checksum. If it @@ -113,8 +114,6 @@ esp_err_t esp_core_dump_image_get(size_t* out_addr, size_t *out_size); */ esp_err_t esp_core_dump_image_erase(void); -#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH - /** * @brief Get panic reason from the core dump. * diff --git a/components/espcoredump/src/core_dump_common.c b/components/espcoredump/src/core_dump_common.c index 13fc8a78d5..5f3b833a32 100644 --- a/components/espcoredump/src/core_dump_common.c +++ b/components/espcoredump/src/core_dump_common.c @@ -1,11 +1,14 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" + +#if CONFIG_ESP_COREDUMP_ENABLE + #include #include -#include "sdkconfig.h" #include "soc/soc_memory_layout.h" #include "freertos/FreeRTOS.h" #include "esp_private/freertos_debug.h" @@ -18,8 +21,6 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_common"; -#if CONFIG_ESP_COREDUMP_ENABLE - #define COREDUMP_GET_MEMORY_SIZE(end, start) (end - start) /** @@ -345,4 +346,4 @@ void esp_core_dump_write(panic_info_t *info) esp_core_dump_print_write_end(); } -#endif +#endif // CONFIG_ESP_COREDUMP_ENABLE diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index 06e4a4cfac..d9a3b57e67 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -3,11 +3,14 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" + +#if CONFIG_ESP_COREDUMP_ENABLE + #include #include "esp_attr.h" #include "esp_partition.h" #include "esp_flash_encrypt.h" -#include "sdkconfig.h" #include "core_dump_checksum.h" #include "esp_core_dump_port.h" #include "esp_core_dump_port_impl.h" @@ -1021,3 +1024,5 @@ 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 03636fe53b..4d54842b81 100644 --- a/components/espcoredump/src/core_dump_flash.c +++ b/components/espcoredump/src/core_dump_flash.c @@ -1,8 +1,12 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" + +#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH + #include #include "esp_partition.h" #include "esp_log.h" @@ -18,8 +22,6 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_flash"; -#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH - typedef struct _core_dump_partition_t { /* Core dump partition start. */ uint32_t start; @@ -398,8 +400,6 @@ esp_err_t esp_core_dump_image_check(void) return ESP_OK; } -#endif - esp_err_t esp_core_dump_image_erase(void) { /* If flash is encrypted, we can only write blocks of 16 bytes, let's always @@ -522,3 +522,5 @@ 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_sha.c b/components/espcoredump/src/core_dump_sha.c index 6be47081ae..fc032fb5c1 100644 --- a/components/espcoredump/src/core_dump_sha.c +++ b/components/espcoredump/src/core_dump_sha.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ - #include "sdkconfig.h" +#if CONFIG_ESP_COREDUMP_ENABLE + #include #include "esp_core_dump_types.h" @@ -122,3 +123,5 @@ 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 d3ab4feb58..d6e98f0b14 100644 --- a/components/espcoredump/src/core_dump_uart.c +++ b/components/espcoredump/src/core_dump_uart.c @@ -1,8 +1,12 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "sdkconfig.h" + +#if CONFIG_ESP_COREDUMP_ENABLE_TO_UART + #include #include "soc/uart_reg.h" #include "soc/gpio_periph.h" @@ -16,8 +20,6 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_uart"; -#if CONFIG_ESP_COREDUMP_ENABLE_TO_UART - void esp_core_dump_print_write_start(void) __attribute__((alias("esp_core_dump_uart_print_write_start"))); void esp_core_dump_print_write_end(void) __attribute__((alias("esp_core_dump_uart_print_write_end"))); esp_err_t esp_core_dump_write_init(void) __attribute__((alias("esp_core_dump_uart_hw_init"))); @@ -176,4 +178,5 @@ void esp_core_dump_init(void) { ESP_COREDUMP_LOGI("Init core dump to UART"); } -#endif + +#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 5473ee6d6d..395a2a3fcc 100644 --- a/components/espcoredump/src/port/riscv/core_dump_port.c +++ b/components/espcoredump/src/port/riscv/core_dump_port.c @@ -9,6 +9,10 @@ * @brief Core dump port implementation for RISC-V based boards. */ +#include "sdkconfig.h" + +#if CONFIG_ESP_COREDUMP_ENABLE + #include #include #include "soc/soc_memory_layout.h" @@ -29,8 +33,6 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_port"; #define COREDUMP_FAKE_STACK_START 0x20000000U #define COREDUMP_FAKE_STACK_LIMIT 0x30000000U -#if CONFIG_ESP_COREDUMP_ENABLE - #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) < (b) ? (b) : (a)) @@ -447,4 +449,4 @@ 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 +#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 e7eadfcbd0..2030a271fa 100644 --- a/components/espcoredump/src/port/xtensa/core_dump_port.c +++ b/components/espcoredump/src/port/xtensa/core_dump_port.c @@ -9,6 +9,10 @@ * @brief Core dump port implementation for Xtensa based boards. */ +#include "sdkconfig.h" + +#if CONFIG_ESP_COREDUMP_ENABLE + #include #include #include "soc/soc_memory_layout.h" @@ -121,8 +125,6 @@ typedef struct { uint32_t reserved; } __attribute__((packed)) xtensa_elf_reg_dump_t; -#if CONFIG_ESP_COREDUMP_ENABLE - static XtExcFrame s_fake_stack_frame = { .pc = (UBaseType_t) COREDUMP_FAKE_STACK_START, // task entrypoint fake_ptr .a0 = (UBaseType_t) 0, // to terminate GDB backtrace @@ -565,4 +567,4 @@ 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 +#endif /* CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH */