Skip to content

Commit d5520f2

Browse files
pdgendtcarlescufi
authored andcommitted
debug: coredump: flash backend: fix header if stream erase
If CONFIG_STREAM_FLASH_ERASE is set, a page erase is done before writing the coredump header to the flash. If the flash page erase size is larger than the flash write size this results in erasing part of the coredump data. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 1dc74d7 commit d5520f2

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

subsys/debug/coredump/coredump_backend_flash_partition.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ static void coredump_flash_backend_start(void)
353353
static void coredump_flash_backend_end(void)
354354
{
355355
int ret;
356-
const struct device *flash_dev;
357356

358357
struct flash_hdr_t hdr = {
359358
.id = {'C', 'D'},
@@ -375,22 +374,10 @@ static void coredump_flash_backend_end(void)
375374
hdr.error = backend_ctx.error;
376375
hdr.flags = 0;
377376

378-
flash_dev = flash_area_get_device(backend_ctx.flash_area);
379-
380-
/* Need to re-init context to write at beginning of flash */
381-
ret = stream_flash_init(&backend_ctx.stream_ctx, flash_dev,
382-
stream_flash_buf,
383-
sizeof(stream_flash_buf),
384-
backend_ctx.flash_area->fa_off,
385-
backend_ctx.flash_area->fa_size, NULL);
386-
if (ret == 0) {
387-
ret = stream_flash_buffered_write(&backend_ctx.stream_ctx,
388-
(void *)&hdr, sizeof(hdr),
389-
true);
390-
if (ret != 0) {
391-
LOG_ERR("Cannot write coredump header!");
392-
backend_ctx.error = ret;
393-
}
377+
ret = flash_area_write(backend_ctx.flash_area, 0, (void *)&hdr, sizeof(hdr));
378+
if (ret != 0) {
379+
LOG_ERR("Cannot write coredump header!");
380+
backend_ctx.error = ret;
394381
}
395382

396383
if (backend_ctx.error != 0) {

0 commit comments

Comments
 (0)