diff options
Diffstat (limited to 'common/nvmem.c')
-rw-r--r-- | common/nvmem.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/common/nvmem.c b/common/nvmem.c index ffdb78bb2d..a93852191c 100644 --- a/common/nvmem.c +++ b/common/nvmem.c @@ -45,6 +45,9 @@ struct nvmem_cache { struct nvmem_cache cache; +static uint8_t commits_enabled; +static uint8_t commits_skipped; + /* NvMem error state */ static int nvmem_error_state; /* Flag to track if an Nv write/move is not completed */ @@ -375,6 +378,9 @@ int nvmem_init(void) } CPRINTS("Active NVram partition set to %d", nvmem_act_partition); + commits_enabled = 1; + commits_skipped = 0; + return EC_SUCCESS; } @@ -510,6 +516,26 @@ int nvmem_move(uint32_t src_offset, uint32_t dest_offset, uint32_t size, return EC_SUCCESS; } +void nvmem_enable_commits(void) +{ + if (commits_enabled) + return; + + commits_enabled = 1; + if (!commits_skipped) + return; + + CPRINTS("Committing NVMEM changes."); + nvmem_commit(); + commits_skipped = 0; +} + +void nvmem_disable_commits(void) +{ + commits_enabled = 0; + commits_skipped = 0; +} + int nvmem_commit(void) { int nvmem_offset; @@ -517,6 +543,12 @@ int nvmem_commit(void) uint16_t version; struct nvmem_partition *p_part; + if (!commits_enabled) { + commits_skipped = 1; + CPRINTS("Skipping commit"); + return EC_SUCCESS; + } + /* Ensure that all writes/moves prior to commit call succeeded */ if (nvmem_write_error) { CPRINTS("NvMem: Write Error, commit abandoned"); |