coredump: simplify the implementation of esp_core_dump_image_erase function

Closes https://github.com/espressif/esp-idf/pull/6949
This commit is contained in:
Omar Chebib 2021-06-21 11:14:12 +08:00
parent 352dc6cf83
commit f810d51327

View File

@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <assert.h>
#include "esp_core_dump.h"
#include "esp_partition.h"
#include "esp_log.h"
#include "esp_core_dump_types.h"
@ -438,6 +436,11 @@ esp_err_t esp_core_dump_image_check(void)
esp_err_t esp_core_dump_image_erase(void)
{
/* If flash is encrypted, we can only write blocks of 16 bytes, let's always
* write a 16-byte buffer. */
uint32_t helper[4] = { BLANK_COREDUMP_SIZE };
_Static_assert(sizeof(helper) % 16 == 0, "esp_partition_write() needs multiple of 16 bytes long buffers");
/* Find the partition that could potentially contain a (previous) core dump. */
const esp_partition_t *core_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
ESP_PARTITION_SUBTYPE_DATA_COREDUMP,
@ -458,21 +461,7 @@ esp_err_t esp_core_dump_image_erase(void)
return err;
}
// helper to create (multiple of) 16 byte long write buffers
struct __attribute__((__packed__)) {
uint32_t size;
char buf[16-sizeof(uint32_t)];
} helper;
_Static_assert(sizeof(helper) % 16 == 0, "esp_partition_write() needs multiple of 16 byte long buffers");
// Mark core dump as deleted by setting field size
helper.size = BLANK_COREDUMP_SIZE;
// fill the remaining bytes
memset(&helper.buf, '\0', sizeof(helper.buf));
err = esp_partition_write(core_part, 0, &helper, sizeof(helper));
err = esp_partition_write(core_part, 0, helper, sizeof(helper));
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to write core dump partition size (%d)!", err);
}