mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge 3810de6812
into 46acfdce96
This commit is contained in:
commit
1056472a1b
@ -155,12 +155,10 @@ static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* wr_data,
|
||||
uint32_t wr_sz = 0;
|
||||
|
||||
/* Make sure that the partition is large enough to hold the data. */
|
||||
ESP_COREDUMP_ASSERT((wr_data->off + data_size) < s_core_flash_config.partition.size);
|
||||
ESP_COREDUMP_ASSERT((wr_data->off + wr_data->cached_bytes + data_size) < s_core_flash_config.partition.size);
|
||||
|
||||
if (wr_data->cached_bytes) {
|
||||
/* Some bytes are in the cache, let's continue filling the cache
|
||||
* with the data received as parameter. Let's calculate the maximum
|
||||
* amount of bytes we can still fill the cache with. */
|
||||
while (data_size > 0) {
|
||||
/* Calculate the maximum amount of bytes we can still fill the cache with. */
|
||||
if ((COREDUMP_CACHE_SIZE - wr_data->cached_bytes) > data_size) {
|
||||
wr_sz = data_size;
|
||||
} else {
|
||||
@ -168,7 +166,7 @@ static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* wr_data,
|
||||
}
|
||||
|
||||
/* Append wr_sz bytes from data parameter to the cache. */
|
||||
memcpy(&wr_data->cached_data[wr_data->cached_bytes], data, wr_sz);
|
||||
memcpy(&wr_data->cached_data[wr_data->cached_bytes], data + written, wr_sz);
|
||||
wr_data->cached_bytes += wr_sz;
|
||||
|
||||
if (wr_data->cached_bytes == COREDUMP_CACHE_SIZE) {
|
||||
@ -196,47 +194,6 @@ static esp_err_t esp_core_dump_flash_write_data(core_dump_write_data_t* wr_data,
|
||||
data_size -= wr_sz;
|
||||
}
|
||||
|
||||
/* Figure out how many bytes we can write onto the flash directly, without
|
||||
* using the cache. In our case the cache size is a multiple of the flash's
|
||||
* minimum writing block size, so we will use it for our calculation.
|
||||
* For example, if COREDUMP_CACHE_SIZE equals 32, here are interesting
|
||||
* values:
|
||||
* +---------+-----------------------+
|
||||
* | | data_size |
|
||||
* +---------+---+----+----+----+----+
|
||||
* | | 0 | 31 | 32 | 40 | 64 |
|
||||
* +---------+---+----+----+----+----+
|
||||
* | (blocks | 0 | 0 | 1 | 1 | 2) |
|
||||
* +---------+---+----+----+----+----+
|
||||
* | wr_sz | 0 | 0 | 32 | 32 | 64 |
|
||||
* +---------+---+----+----+----+----+
|
||||
*/
|
||||
wr_sz = (data_size / COREDUMP_CACHE_SIZE) * COREDUMP_CACHE_SIZE;
|
||||
if (wr_sz) {
|
||||
/* Write the contiguous amount of bytes to the flash,
|
||||
* without using the cache */
|
||||
err = esp_core_dump_flash_custom_write(s_core_flash_config.partition.start + wr_data->off, data + written, wr_sz);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_COREDUMP_LOGE("Failed to write data to flash (%d)!", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Update the checksum with the newly written bytes */
|
||||
esp_core_dump_checksum_update(&wr_data->checksum_ctx, data + written, wr_sz);
|
||||
wr_data->off += wr_sz;
|
||||
written += wr_sz;
|
||||
data_size -= wr_sz;
|
||||
}
|
||||
|
||||
if (data_size > 0) {
|
||||
/* There still some bytes from the data parameter that need to be sent,
|
||||
* append it to cache in order to write them later. (i.e. when there
|
||||
* will be enough bytes to fill the cache) */
|
||||
memcpy(&wr_data->cached_data, data + written, data_size);
|
||||
wr_data->cached_bytes = data_size;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user