summaryrefslogtreecommitdiff
path: root/common/nvmem_vars.c
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-01-08 16:13:08 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-09 23:47:07 -0800
commit618b127c4903a171731730b4b53472f8c645e543 (patch)
tree2fb79e89acc095d2460c215d2a562d0f00e749f6 /common/nvmem_vars.c
parent8734b70ff56e48900e4aaa68c1c56e84d60ce2ac (diff)
downloadchrome-ec-618b127c4903a171731730b4b53472f8c645e543.tar.gz
nvmem_vars: use dynamic memory allocation
To avoid SRAM footprint, let's use dynamic memory allocation in nvram_vars. No one is using this module yet, but the cr50 use case is coming up. BRANCH=none BUG=chrome-os-partner:61107 TEST=make buildall -j passes Change-Id: I21534430217ad387a3787fcc127da596a1b48e03 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/426088 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/nvmem_vars.c')
-rw-r--r--common/nvmem_vars.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/common/nvmem_vars.c b/common/nvmem_vars.c
index 92da5d2981..f67a2053db 100644
--- a/common/nvmem_vars.c
+++ b/common/nvmem_vars.c
@@ -8,23 +8,20 @@
#include "nvmem.h"
#include "nvmem_vars.h"
#include "printf.h"
+#include "shared_mem.h"
#include "util.h"
/****************************************************************************/
-/* Obtain/release a RAM copy of the persistent variable store */
+/* Pointer to the RAM copy of the persistent variable store */
-/*
- * NOTE: It would be nice to allocate this at need, but shared memory is
- * currently all or nothing and it's used elsewhere when writing to flash, so
- * we have to allocate it statically until/unless that changes.
- */
-static uint8_t rbuf[CONFIG_FLASH_NVMEM_VARS_USER_SIZE];
-static int rbuf_in_use;
+test_mockable_static uint8_t *rbuf;
test_mockable_static
void release_local_copy(void)
{
- rbuf_in_use = 0;
+ if (rbuf)
+ shared_mem_release(rbuf);
+ rbuf = NULL;
}
test_mockable_static
@@ -32,15 +29,18 @@ int get_local_copy(void)
{
int rv;
- if (rbuf_in_use)
+ if (rbuf)
return EC_SUCCESS;
- rbuf_in_use = 1;
+ rv = shared_mem_acquire(CONFIG_FLASH_NVMEM_VARS_USER_SIZE,
+ (char **)&rbuf);
- rv = nvmem_read(0, CONFIG_FLASH_NVMEM_VARS_USER_SIZE,
- rbuf, CONFIG_FLASH_NVMEM_VARS_USER_NUM);
- if (rv)
- release_local_copy();
+ if (rv == EC_SUCCESS) {
+ rv = nvmem_read(0, CONFIG_FLASH_NVMEM_VARS_USER_SIZE,
+ rbuf, CONFIG_FLASH_NVMEM_VARS_USER_NUM);
+ if (rv != EC_SUCCESS)
+ release_local_copy();
+ }
return rv;
}
@@ -320,7 +320,7 @@ int writevars(void)
{
int rv;
- if (!rbuf_in_use)
+ if (!rbuf)
return EC_SUCCESS;
rv = nvmem_write(0, CONFIG_FLASH_NVMEM_VARS_USER_SIZE,