aboutsummaryrefslogtreecommitdiff
path: root/util/cbfstool/eventlog.c
diff options
context:
space:
mode:
authorRicardo Quesada <ricardoq@google.com>2021-08-16 11:25:52 -0700
committerFurquan Shaikh <furquan@google.com>2021-09-10 22:53:05 +0000
commit49a96a94634ca146969293c8f1ac12dba6bbd231 (patch)
tree35acd79010065000d84745fea713bb329b145127 /util/cbfstool/eventlog.c
parent6db0f04fa24d3532b6c6f1069001a166764ac1db (diff)
elogtool: add "clear" command
Adds "clear" command to cbfsutil/elogtool tool. "clear" clears the RW_ELOG region by using either: * flashrom if no file is provided * or using file write if an input file is provided. The region is filled with ELOG_TYPE_EOL. And a ELOG_TYPE_LOG_CLEAR event is inserted. Additionally, it does a minor cleanup to command "list", like: * use buffer_end() * add "list" to the cmds struct * and make elog_read() very similar to elog_write() Usage: $ elogtool clear BUG=b:172210863 TEST=elogtool clear && elogtool list elogtool clear -f invalid.raw elogtool clear -f valid.raw Change-Id: Ia28a6eb34c82103ab078a0841b022e2e5e430585 Signed-off-by: Ricardo Quesada <ricardoq@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/56883 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'util/cbfstool/eventlog.c')
-rw-r--r--util/cbfstool/eventlog.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/util/cbfstool/eventlog.c b/util/cbfstool/eventlog.c
index 2d99f9237a..8b03686ecd 100644
--- a/util/cbfstool/eventlog.c
+++ b/util/cbfstool/eventlog.c
@@ -11,6 +11,7 @@
#include <commonlib/bsd/elog.h>
#include <vb2_api.h>
+#include "common.h"
#include "valstr.h"
#define PATH_PCI_BUS_SHIFT 8
@@ -634,3 +635,42 @@ void eventlog_print_event(const struct event_header *event, int count)
eventlog_printf_ignore_separator_once = 1;
eventlog_printf("\n");
}
+
+/*
+ * Initializes the eventlog header with the given type and data,
+ * and calculates the checksum.
+ * buffer_get() points to the event to be initialized.
+ * On success it returns 1, otherwise 0.
+ */
+int eventlog_init_event(const struct buffer *buf, uint8_t type,
+ const void *data, int data_size)
+{
+ struct event_header *event;
+ time_t secs = time(NULL);
+ struct tm tm;
+
+ /* Must have at least size for data + checksum byte */
+ if (buffer_size(buf) < (size_t)data_size + 1)
+ return 0;
+
+ event = buffer_get(buf);
+
+ event->type = type;
+ gmtime_r(&secs, &tm);
+ elog_fill_timestamp(event, tm.tm_sec, tm.tm_min, tm.tm_hour,
+ tm.tm_mday, tm.tm_mon, tm.tm_year);
+
+ if (data && data_size) {
+ uint32_t *ptr = (uint32_t *)&event[1];
+ memcpy(ptr, data, data_size);
+ }
+
+ /* Header + data + checksum */
+ event->length = sizeof(*event) + data_size + 1;
+
+ /* Zero the checksum byte and then compute checksum */
+ elog_update_checksum(event, 0);
+ elog_update_checksum(event, -(elog_checksum_event(event)));
+
+ return 1;
+}