From e7d5fee856fee3bb0b3882255bbe0b8a22b6ff35 Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Thu, 2 Nov 2023 17:05:42 +0800 Subject: [PATCH] change(espcoredump): save RAM space by placing constants in flash All the log messages of espcoredump component used to be in DRAM, which would lower the available RAM space for the user application. Since the cache is always enabled after an exception, constants can be put in flash. --- .../include_core_dump/esp_core_dump_types.h | 9 +++++++-- components/espcoredump/linker.lf | 12 +++++++----- components/espcoredump/src/core_dump_binary.c | 2 +- components/espcoredump/src/core_dump_checksum.c | 16 ++++++++-------- components/espcoredump/src/core_dump_common.c | 2 +- components/espcoredump/src/core_dump_elf.c | 2 +- components/espcoredump/src/core_dump_flash.c | 2 +- components/espcoredump/src/core_dump_uart.c | 14 +++++++------- .../espcoredump/src/port/riscv/core_dump_port.c | 2 +- .../espcoredump/src/port/xtensa/core_dump_port.c | 2 +- 10 files changed, 35 insertions(+), 28 deletions(-) diff --git a/components/espcoredump/include_core_dump/esp_core_dump_types.h b/components/espcoredump/include_core_dump/esp_core_dump_types.h index 869e47c5ea..bafcd7ebd8 100644 --- a/components/espcoredump/include_core_dump/esp_core_dump_types.h +++ b/components/espcoredump/include_core_dump/esp_core_dump_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -19,7 +19,7 @@ extern "C" { #include "core_dump_checksum.h" #if CONFIG_ESP_COREDUMP_LOGS -#define ESP_COREDUMP_LOG( level, format, ... ) if (LOG_LOCAL_LEVEL >= level) { esp_rom_printf(DRAM_STR(format), esp_log_early_timestamp(), (const char *)TAG, ##__VA_ARGS__); } +#define ESP_COREDUMP_LOG( level, format, ... ) if (LOG_LOCAL_LEVEL >= level) { esp_rom_printf((format), esp_log_early_timestamp(), (const char *)TAG, ##__VA_ARGS__); } #else #define ESP_COREDUMP_LOG( level, format, ... ) // dummy define doing nothing #endif @@ -30,6 +30,11 @@ extern "C" { #define ESP_COREDUMP_LOGD( format, ... ) ESP_COREDUMP_LOG(ESP_LOG_DEBUG, LOG_FORMAT(D, format), ##__VA_ARGS__) #define ESP_COREDUMP_LOGV( format, ... ) ESP_COREDUMP_LOG(ESP_LOG_VERBOSE, LOG_FORMAT(V, format), ##__VA_ARGS__) +/** + * @brief Always print the given message, regardless of the log level + */ +#define ESP_COREDUMP_PRINT( format, ... ) do { esp_rom_printf((format), ##__VA_ARGS__); } while(0) + /** * @brief Assertion to be verified in a release context. Cannot be muted. */ diff --git a/components/espcoredump/linker.lf b/components/espcoredump/linker.lf index fe978a7b6a..d51f4b3636 100644 --- a/components/espcoredump/linker.lf +++ b/components/espcoredump/linker.lf @@ -37,11 +37,13 @@ entries: archive: libespcoredump.a entries: if ESP_PANIC_HANDLER_IRAM = y: - core_dump_uart (noflash_text) - core_dump_flash (noflash_text) - core_dump_common (noflash_text) - core_dump_port (noflash_text) - core_dump_elf (noflash_text) + core_dump_uart (noflash) + core_dump_flash (noflash) + core_dump_common (noflash) + core_dump_port (noflash) + core_dump_elf (noflash) + core_dump_checksum (noflash) + core_dump_binary (noflash) else: * (default) diff --git a/components/espcoredump/src/core_dump_binary.c b/components/espcoredump/src/core_dump_binary.c index d3de0e6673..8c1dea5f04 100644 --- a/components/espcoredump/src/core_dump_binary.c +++ b/components/espcoredump/src/core_dump_binary.c @@ -13,7 +13,7 @@ #if CONFIG_ESP_COREDUMP_DATA_FORMAT_BIN -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_binary"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_binary"; static esp_err_t esp_core_dump_save_task(core_dump_write_config_t *write_cfg, diff --git a/components/espcoredump/src/core_dump_checksum.c b/components/espcoredump/src/core_dump_checksum.c index b29d909fcf..982efea0b0 100644 --- a/components/espcoredump/src/core_dump_checksum.c +++ b/components/espcoredump/src/core_dump_checksum.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -26,7 +26,7 @@ #if CONFIG_ESP_COREDUMP_ENABLE -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_checksum"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_checksum"; #define COREDUMP_SHA256_LEN 32 @@ -147,13 +147,13 @@ static void esp_core_dump_print_sha256(const char* msg, const uint8_t* sha_outpu /* As this function is only called by `esp_core_dump_print_checksum`, we * have the guarantee that sha_output is not NULL. */ if (msg != NULL) { - esp_rom_printf(DRAM_STR("%s='"), msg); + ESP_COREDUMP_PRINT("%s='", msg); } for (int i = 0; i < COREDUMP_SHA256_LEN; i++) { - esp_rom_printf(DRAM_STR("%02x"), sha_output[i]); + ESP_COREDUMP_PRINT("%02x", sha_output[i]); } - esp_rom_printf(DRAM_STR("'\r\n")); + ESP_COREDUMP_PRINT("'\r\n"); } #endif @@ -170,10 +170,10 @@ void esp_core_dump_print_checksum(const char* msg, core_dump_checksum_bytes chec #if CONFIG_ESP_COREDUMP_CHECKSUM_CRC32 if (msg != NULL) { - esp_rom_printf(DRAM_STR("%s='"), msg); + ESP_COREDUMP_PRINT("%s='", msg); } - esp_rom_printf(DRAM_STR("%08x"), *((const uint32_t*) checksum)); - esp_rom_printf(DRAM_STR("'\r\n")); + ESP_COREDUMP_PRINT("%08x", *((const uint32_t*) checksum)); + ESP_COREDUMP_PRINT("'\r\n"); #elif CONFIG_ESP_COREDUMP_CHECKSUM_SHA256 esp_core_dump_print_sha256(msg, (const uint8_t*) checksum); #endif diff --git a/components/espcoredump/src/core_dump_common.c b/components/espcoredump/src/core_dump_common.c index 028bdc7cef..cf1db1be22 100644 --- a/components/espcoredump/src/core_dump_common.c +++ b/components/espcoredump/src/core_dump_common.c @@ -15,7 +15,7 @@ #include "core_dump_elf.h" #include "core_dump_binary.h" -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_common"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_common"; #if CONFIG_ESP_COREDUMP_ENABLE diff --git a/components/espcoredump/src/core_dump_elf.c b/components/espcoredump/src/core_dump_elf.c index 6d14a93472..5fdf0dc2f2 100644 --- a/components/espcoredump/src/core_dump_elf.c +++ b/components/espcoredump/src/core_dump_elf.c @@ -71,7 +71,7 @@ typedef struct uint8_t app_elf_sha256[ELF_APP_SHA256_SIZE]; // sha256 of elf file } core_dump_elf_version_info_t; -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_elf"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_elf"; // Main ELF handle type typedef struct _core_dump_elf_t diff --git a/components/espcoredump/src/core_dump_flash.c b/components/espcoredump/src/core_dump_flash.c index 0b39a3f6dd..89e6a728f1 100644 --- a/components/espcoredump/src/core_dump_flash.c +++ b/components/espcoredump/src/core_dump_flash.c @@ -15,7 +15,7 @@ #define BLANK_COREDUMP_SIZE 0xFFFFFFFF -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_flash"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_flash"; #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH diff --git a/components/espcoredump/src/core_dump_uart.c b/components/espcoredump/src/core_dump_uart.c index 0e355e3c96..b9a549e735 100644 --- a/components/espcoredump/src/core_dump_uart.c +++ b/components/espcoredump/src/core_dump_uart.c @@ -13,7 +13,7 @@ #include "esp_core_dump_common.h" #include "esp_rom_sys.h" -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_uart"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_uart"; #if CONFIG_ESP_COREDUMP_ENABLE_TO_UART @@ -22,7 +22,7 @@ const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_uart" int esp_clk_cpu_freq(void); static void esp_core_dump_b64_encode(const uint8_t *src, uint32_t src_len, uint8_t *dst) { - const static DRAM_ATTR char b64[] = + const static char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int i, j, a, b, c; @@ -53,7 +53,7 @@ static esp_err_t esp_core_dump_uart_write_start(core_dump_write_data_t *priv) ESP_COREDUMP_ASSERT(priv != NULL); esp_core_dump_checksum_init(&wr_data->checksum_ctx); - esp_rom_printf(DRAM_STR("================= CORE DUMP START =================\r\n")); + ESP_COREDUMP_PRINT("================= CORE DUMP START =================\r\n"); return err; } @@ -74,12 +74,12 @@ static esp_err_t esp_core_dump_uart_write_end(core_dump_write_data_t *priv) size_t cs_len = esp_core_dump_checksum_finish(wr_data->checksum_ctx, &cs_addr); wr_data->off += cs_len; esp_core_dump_b64_encode((const uint8_t *)cs_addr, cs_len, (uint8_t*)&buf[0]); - esp_rom_printf(DRAM_STR("%s\r\n"), buf); + ESP_COREDUMP_PRINT("%s\r\n", buf); } - esp_rom_printf(DRAM_STR("================= CORE DUMP END =================\r\n")); + ESP_COREDUMP_PRINT("================= CORE DUMP END =================\r\n"); if (cs_addr) { - esp_core_dump_print_checksum(DRAM_STR("Coredump checksum"), cs_addr); + esp_core_dump_print_checksum("Coredump checksum", cs_addr); } return err; @@ -103,7 +103,7 @@ static esp_err_t esp_core_dump_uart_write_data(core_dump_write_data_t *priv, voi memcpy(tmp, addr, len); esp_core_dump_b64_encode((const uint8_t *)tmp, len, (uint8_t *)buf); addr += len; - esp_rom_printf(DRAM_STR("%s\r\n"), buf); + ESP_COREDUMP_PRINT("%s\r\n", buf); } if (wr_data) { diff --git a/components/espcoredump/src/port/riscv/core_dump_port.c b/components/espcoredump/src/port/riscv/core_dump_port.c index 9f7568e132..e426c36124 100644 --- a/components/espcoredump/src/port/riscv/core_dump_port.c +++ b/components/espcoredump/src/port/riscv/core_dump_port.c @@ -20,7 +20,7 @@ #include "esp_core_dump_port.h" /* TAG used for logs */ -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_port"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_port"; /* Code associated to RISC-V in ELF format */ #define COREDUMP_EM_RISCV 0xF3 diff --git a/components/espcoredump/src/port/xtensa/core_dump_port.c b/components/espcoredump/src/port/xtensa/core_dump_port.c index 6095fbbda5..971da1b268 100644 --- a/components/espcoredump/src/port/xtensa/core_dump_port.c +++ b/components/espcoredump/src/port/xtensa/core_dump_port.c @@ -21,7 +21,7 @@ #include "esp_debug_helpers.h" #include "esp_cpu_utils.h" -const static DRAM_ATTR char TAG[] __attribute__((unused)) = "esp_core_dump_port"; +const static char TAG[] __attribute__((unused)) = "esp_core_dump_port"; #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) < (b) ? (b) : (a))