Skip to content

Commit

Permalink
Merge branch 'staging/espcoredump_move_strings_flash' into 'master'
Browse files Browse the repository at this point in the history
change(espcoredump): save RAM space by placing constants in flash

See merge request espressif/esp-idf!26872
  • Loading branch information
o-marshmallow committed Nov 3, 2023
2 parents 0eae131 + 8ac4b48 commit ff2a492
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down
12 changes: 7 additions & 5 deletions components/espcoredump/linker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion components/espcoredump/src/core_dump_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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,
Expand Down
16 changes: 8 additions & 8 deletions components/espcoredump/src/core_dump_checksum.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/espcoredump/src/core_dump_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion components/espcoredump/src/core_dump_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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
Expand Down
2 changes: 1 addition & 1 deletion components/espcoredump/src/core_dump_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions components/espcoredump/src/core_dump_uart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -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

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion components/espcoredump/src/port/riscv/core_dump_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/espcoredump/src/port/xtensa/core_dump_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ff2a492

Please sign in to comment.