refactor(espcoredump): keep checksum context in coredump stack

This commit is contained in:
Erhan Kurubas
2024-02-23 16:55:51 +01:00
parent 9e5c30baff
commit 0077c1234f
8 changed files with 65 additions and 63 deletions

View File

@@ -55,31 +55,31 @@ uint32_t esp_core_dump_elf_version(void);
/**
* @brief Initialize checksum calculation for the given context.
*
* @param wr_data Core dump checksum context to fill.
* @param ctx Core dump checksum context to fill.
*/
void esp_core_dump_checksum_init(void ** wr_data);
void esp_core_dump_checksum_init(void *ctx);
/**
* @brief Update checksum calculation by integrating the given data in the context.
*
* @param wr_data Core dump checksum context.
* @param ctx Core dump checksum context.
* @param data Pointer to the data to integrate in the checksum calculation.
* This is usually the new data to write (or already written) on
* the flash.
*/
void esp_core_dump_checksum_update(void* wr_data, void* data, size_t data_len);
void esp_core_dump_checksum_update(void *ctx, void *data, size_t data_len);
/**
* @brief Terminate and return checksum calculated for the given context.
*
* @param wr_data Core dump checksum context.
* @param ctx Core dump checksum context.
* @param chs_ptr Pointer used to return the checksum calculated. It can be
* NULL, in this case, it will be ignored but the correct size
* of the checksum will be returned.
*
* @return The size, in bytes, of the checksum.
*/
uint32_t esp_core_dump_checksum_finish(void* wr_data, core_dump_checksum_bytes* chs_ptr);
uint32_t esp_core_dump_checksum_finish(void *ctx, core_dump_checksum_bytes *chs_ptr);
/**
* @brief Return the size of the checksums.

View File

@@ -91,6 +91,39 @@ extern "C" {
#error "Coredump cache size must be a multiple of 16"
#endif
typedef uint32_t core_dump_crc_t;
#if CONFIG_ESP_COREDUMP_CHECKSUM_CRC32
typedef struct {
core_dump_crc_t crc;
uint32_t total_bytes_checksum; /* Number of bytes used to calculate the checksum */
} core_dump_crc_ctx_t;
typedef core_dump_crc_ctx_t checksum_ctx_t;
#else
#if CONFIG_IDF_TARGET_ESP32
#include "mbedtls/sha256.h" /* mbedtls_sha256_context */
typedef mbedtls_sha256_context sha256_ctx_t;
#else
#include "hal/sha_types.h" /* SHA_CTX */
typedef SHA_CTX sha256_ctx_t;
#endif
#define COREDUMP_SHA256_LEN 32
typedef struct {
sha256_ctx_t ctx;
uint8_t result[COREDUMP_SHA256_LEN];
uint32_t total_bytes_checksum; /* Number of bytes used to calculate the checksum */
} core_dump_sha_ctx_t;
typedef core_dump_sha_ctx_t checksum_ctx_t;
#endif
/**
* @brief Chip ID associated to this implementation.
*/
@@ -101,7 +134,7 @@ typedef struct _core_dump_write_data_t
uint32_t off; /*!< Current offset of data being written */
uint8_t cached_data[COREDUMP_CACHE_SIZE]; /*!< Cache used to write to flash */
uint8_t cached_bytes; /*!< Number of bytes filled in the cached */
void *checksum_ctx; /*!< Checksum context */
checksum_ctx_t checksum_ctx; /*!< Checksum context */
} core_dump_write_data_t;
/**