diff options
author | Aaron Durbin <adurbin@chromium.org> | 2016-08-03 22:21:29 -0500 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2016-08-08 19:09:16 +0200 |
commit | 052a9955678eb514067efb5ccc4de907faa248e1 (patch) | |
tree | 7ccdbbf7497fbc19097ca52c7f0e6d8aed2206be /src/drivers/elog | |
parent | e25d3ff9bd63cb7123461b266b42af664e81025d (diff) |
drivers/elog: perform writes in terms of offsets
Instead of taking pointers and back-calculating the
proper offset perform writes in terms of the offsets
within the elog region in flash.
BUG=chrome-os-partner:55932
Change-Id: I5fd65423f5a6e03825c788bc36417f509b58f64d
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/16095
Reviewed-by: Furquan Shaikh <furquan@google.com>
Tested-by: build bot (Jenkins)
Diffstat (limited to 'src/drivers/elog')
-rw-r--r-- | src/drivers/elog/elog.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index b78eee06ab..30578ce929 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -201,19 +201,21 @@ static int elog_is_event_valid(u32 offset) } /* - * Write 'size' bytes of data pointed to by 'address' in the flash backing - * store into flash. This will not erase the flash and it assumes the flash - * area has been erased appropriately. + * Write 'size' bytes of data from provided 'offset' in the mirrored elog to + * the flash backing store. This will not erase the flash and it assumes the + * flash area has been erased appropriately. */ -static void elog_flash_write(void *address, u32 size) +static void elog_flash_write(size_t offset, size_t size) { - u32 offset; + void *address; - if (!address || !size || !elog_spi) + if (!size || !elog_spi) return; - offset = flash_base; - offset += (u8 *)address - (u8 *)elog_area; + address = offset + (u8 *)elog_area; + + /* Ensure offset is absolute. */ + offset += flash_base; elog_debug("elog_flash_write(address=0x%p offset=0x%08x size=%u)\n", address, offset, size); @@ -222,6 +224,16 @@ static void elog_flash_write(void *address, u32 size) elog_spi->write(elog_spi, offset, size, address); } +static void elog_append_event(size_t offset, size_t event_size) +{ + /* + * Events are appended relative to the end of the header. Update + * offset to include the header size. + */ + offset += sizeof(struct elog_header); + elog_flash_write(offset, event_size); +} + /* * Erase the first block specified in the address. * Only handles flash area within a single flash block. @@ -329,7 +341,7 @@ static void elog_prepare_empty(void) header->header_size = sizeof(struct elog_header); header->reserved[0] = ELOG_TYPE_EOL; header->reserved[1] = ELOG_TYPE_EOL; - elog_flash_write(elog_area, header->header_size); + elog_flash_write(0, header->header_size); elog_scan_flash(); } @@ -367,7 +379,7 @@ static int elog_shrink(void) memset(&elog_area->data[new_size], ELOG_TYPE_EOL, log_size - new_size); elog_flash_erase(); - elog_flash_write(elog_area, total_size); + elog_flash_write(0, total_size); elog_scan_flash(); /* Ensure the area was successfully erased */ @@ -669,7 +681,7 @@ void elog_add_event_raw(u8 event_type, void *data, u8 data_size) /* Update the ELOG state */ event_count++; - elog_flash_write((void *)event, event_size); + elog_append_event(next_event_offset, event_size); next_event_offset += event_size; |