From e929a75fbe51eb7bcc48d18f6bfbda11b39a8373 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Mon, 16 Aug 2021 10:45:42 -0700 Subject: elog: move functionality to commonlib/bsd This commit moves some drivers/elog/ functionality to commonlib/bsd since they will be called from util/cbfstool/. In particular: * elog_fill_timestamp(), elog_update_checksum(), elog_checksum_event() were moved to commonlib/bsd/elog * elog_fill_timestamp() receives the time parameters and updates the event based on the "time" arguments. The original elog_*() functions were written by Duncan Laurie (see CB:1311) and he gave permission to re-license the code to BSD. BUG=b:172210863 Change-Id: I67d5ad6e7c4d486b3d4ebb25be77998173cee5a9 Signed-off-by: Ricardo Quesada Reviewed-on: https://review.coreboot.org/c/coreboot/+/56985 Tested-by: build bot (Jenkins) Reviewed-by: Jack Rosenthal Reviewed-by: Furquan Shaikh --- src/commonlib/bsd/elog.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src/commonlib/bsd/elog.c') diff --git a/src/commonlib/bsd/elog.c b/src/commonlib/bsd/elog.c index 6c927aaf22..a5e644c4af 100644 --- a/src/commonlib/bsd/elog.c +++ b/src/commonlib/bsd/elog.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include @@ -40,7 +41,48 @@ const struct event_header *elog_get_next_event(const struct event_header *event) /* return the data associated to the event_header. */ const void *event_get_data(const struct event_header *event) { - // Pointing to the next event returns the data, since data is the first field - // right after the header. + /* + * Pointing to the next event returns the data, since data is the first + * field right after the header. + */ return (const void *)(&event[1]); } + +/* Populate timestamp in event header with given time. */ +void elog_fill_timestamp(struct event_header *event, uint8_t sec, uint8_t min, + uint8_t hour, uint8_t mday, uint8_t mon, uint8_t year) +{ + event->second = bin2bcd(sec); + event->minute = bin2bcd(min); + event->hour = bin2bcd(hour); + event->day = bin2bcd(mday); + event->month = bin2bcd(mon); + event->year = bin2bcd(year % 100); + + /* Basic check of expected ranges. */ + if (event->month > 0x12 || event->day > 0x31 || event->hour > 0x23 || + event->minute > 0x59 || event->second > 0x59) { + event->year = 0; + event->month = 0; + event->day = 0; + event->hour = 0; + event->minute = 0; + event->second = 0; + } +} + +void elog_update_checksum(struct event_header *event, uint8_t checksum) +{ + uint8_t *event_data = (uint8_t *)event; + event_data[event->length - 1] = checksum; +} + +uint8_t elog_checksum_event(const struct event_header *event) +{ + uint8_t index, checksum = 0; + const uint8_t *data = (const uint8_t *)event; + + for (index = 0; index < event->length; index++) + checksum += data[index]; + return checksum; +} -- cgit v1.2.3