Skip to content

Commit

Permalink
mtd/nvs: Trigger recovery process in nvs_startup
Browse files Browse the repository at this point in the history
when mtd driver return -EBADMSG

Signed-off-by: Xiang Xiao <[email protected]>
  • Loading branch information
xiaoxiang781216 committed Oct 12, 2024
1 parent 38e474b commit 08829bd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions drivers/mtd/mtd_config_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,25 @@ static int nvs_flash_rd(FAR struct nvs_fs *fs, uint32_t addr,
offset += addr & ADDR_OFFS_MASK;

ret = MTD_READ(fs->mtd, offset, len, data);
if (ret < 0)
if (ret == -EBADMSG)
{
return ret;
/* ECC fail first time
* try again to avoid transient electronic interference
*/

ret = MTD_READ(fs->mtd, offset, len, data);
if (ret == -EBADMSG)
{
/* ECC fail second time
* fill ~erasestate to trigger recovery process
*/

memset(data, ~fs->erasestate, len);
ret = 0;
}
}

return OK;
return ret < 0 ? ret : 0;
}

/****************************************************************************
Expand Down

0 comments on commit 08829bd

Please sign in to comment.