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)
This commit is contained in:
Aaron Durbin 2016-08-03 22:21:29 -05:00 committed by Martin Roth
parent e25d3ff9bd
commit 052a995567
1 changed files with 23 additions and 11 deletions

View File

@ -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;