From 575bc83a648c2b5d5a7aeac4dc53c21508a908ad Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 24 Apr 2013 03:16:21 -0700 Subject: [PATCH] Make elog_shrink not depend on having seperate memory/flash descriptors. The way elog_shrink currently works is that it completely clears the data in the flash/flash descriptor and then recreates it using the part of the log it's going to keep as stored in the memory descriptor. That scheme depends on there being to independent copies of the log. This change reworks elog_shrink so that it moves the data it wants to keep within a single descriptor and then propogates it to the other and to flash intact. This way, when one of the descriptors goes away, all we have to do is remove the code that would update it. BUG=chrome-os-partner:16132 TEST=Built and booted into ChromeOS on Link. Ran mosys eventlog list. Added 2000 events to the log and ran mosys eventlog list again. Echoed a 1 into /sys/firmware/gsmi/clear_eventlog and ran mosys eventlog list. BRANCH=None Change-Id: I50d77a4f00ea3c6b3e0ec8996dab1a3b31580205 Signed-off-by: Gabe Black Reviewed-on: https://gerrit.chromium.org/gerrit/49305 Reviewed-by: Duncan Laurie Commit-Queue: Gabe Black Tested-by: Gabe Black --- src/drivers/elog/elog.c | 25 ++++++++++++------------- src/lib/Makefile.inc | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/drivers/elog/elog.c b/src/drivers/elog/elog.c index 7b12e20fa7..3318d518a6 100644 --- a/src/drivers/elog/elog.c +++ b/src/drivers/elog/elog.c @@ -621,9 +621,11 @@ static int elog_flash_area_bootstrap(void) static int elog_shrink(void) { struct elog_descriptor *mem = elog_get_mem(); + struct elog_descriptor *flash = elog_get_flash(); struct event_header *event; u16 discard_count = 0; u16 offset = 0; + u16 new_size = 0; elog_debug("elog_shrink()\n"); @@ -645,25 +647,22 @@ static int elog_shrink(void) discard_count++; } - /* Erase flash area */ - elog_flash_erase_area(); + new_size = mem->next_event_offset - offset; + memmove(&mem->data[0], &mem->data[offset], new_size); + memset(&mem->data[new_size], ELOG_TYPE_EOL, mem->data_size - new_size); + elog_reinit_descriptor(mem); + + elog_flash_erase(flash->backing_store, flash->total_size); /* Ensure the area was successfully erased */ - if (elog_get_flash()->next_event_offset >= CONFIG_ELOG_FULL_THRESHOLD) { + if (mem->next_event_offset >= CONFIG_ELOG_FULL_THRESHOLD) { printk(BIOS_ERR, "ELOG: Flash area was not erased!\n"); return -1; } - /* Write new flash area */ - elog_prepare_empty(elog_get_flash(), - (u8*)elog_get_event_base(mem, offset), - mem->next_event_offset - offset); - - /* Update memory area from flash */ - if (elog_sync_flash_to_mem() < 0) { - printk(BIOS_ERR, "Unable to update memory area from flash\n"); - return -1; - } + elog_flash_write(flash->backing_store, mem->backing_store, + mem->total_size); + elog_reinit_descriptor(flash); /* Add clear event */ elog_add_event_word(ELOG_TYPE_LOG_CLEAR, offset); diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc index 13871823d9..729cc43a0c 100644 --- a/src/lib/Makefile.inc +++ b/src/lib/Makefile.inc @@ -108,7 +108,7 @@ endif ifneq ($(CONFIG_HAVE_ARCH_MEMCPY),y) smm-y += memcpy.c endif -smm-y += cbfs.c memcmp.c +smm-y += cbfs.c memmove.c memcmp.c smm-$(CONFIG_CONSOLE_SERIAL8250) += uart8250.c smm-$(CONFIG_CONSOLE_SERIAL8250MEM) += uart8250mem.c smm-$(CONFIG_USBDEBUG) += usbdebug.c