diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2016-12-26 21:42:32 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-12-28 21:49:39 -0800 |
commit | 400d4ecaed9a6bdf8fdb7ec0606377bb0500fe33 (patch) | |
tree | 09ca88aeb3248aa53a5e8c773879adc4c2c0eadf /chip/host/system.c | |
parent | d12ba2aa8ecfdac4478c20391283dc4457c97445 (diff) | |
download | chrome-ec-400d4ecaed9a6bdf8fdb7ec0606377bb0500fe33.tar.gz |
fix memory size calculations in host/test mode
The common/system.c:system_usable_ram_end() function is used to
determine how much room there is available for shared memory. This
assumes that the jdata container is located at the top of SRAM right
below the panic data buffer.
This correct for embedded mode, but when building for host, panic
structure is allocated in a different memory block, not necessarily
adjacent to the __shared_mem_buf array. This leads to incorrect
calculations of the available shared memory amount.
Let's make sure the two memory blocks are adjacent, this way the
available memory calculations are accurate.
BRANCH=none
BUG=none
TEST=verified that
make runtests -j
succeeds, including the new test for malloc/free from shared memory
(coming up in the next patch).
Change-Id: I1fdba0512ac5a85b113a8284216c8b00f1564a94
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/424176
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/host/system.c')
-rw-r--r-- | chip/host/system.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/chip/host/system.c b/chip/host/system.c index 757d00fc51..194a9565ab 100644 --- a/chip/host/system.c +++ b/chip/host/system.c @@ -17,10 +17,10 @@ #include "util.h" #define SHARED_MEM_SIZE 0x2000 /* bytes */ -uint8_t __shared_mem_buf[SHARED_MEM_SIZE]; - #define RAM_DATA_SIZE (sizeof(struct panic_data) + 512) /* bytes */ -static char __ram_data[RAM_DATA_SIZE]; +uint8_t __shared_mem_buf[SHARED_MEM_SIZE + RAM_DATA_SIZE]; + +static char *__ram_data = __shared_mem_buf + SHARED_MEM_SIZE; static enum system_image_copy_t __running_copy; @@ -31,7 +31,7 @@ static void ramdata_set_persistent(void) ASSERT(f != NULL); - sz = fwrite(__ram_data, sizeof(__ram_data), 1, f); + sz = fwrite(__ram_data, RAM_DATA_SIZE, 1, f); ASSERT(sz == 1); release_persistent_storage(f); @@ -44,11 +44,11 @@ static void ramdata_get_persistent(void) if (f == NULL) { fprintf(stderr, "No RAM data found. Initializing to 0x00.\n"); - memset(__ram_data, 0, sizeof(__ram_data)); + memset(__ram_data, 0, RAM_DATA_SIZE); return; } - fread(__ram_data, sizeof(__ram_data), 1, f); + fread(__ram_data, RAM_DATA_SIZE, 1, f); release_persistent_storage(f); |