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 <ricardoq@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/56985 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
parent
778380ac74
commit
e929a75fbe
|
@ -1,5 +1,6 @@
|
||||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||||
|
|
||||||
|
#include <commonlib/bsd/bcd.h>
|
||||||
#include <commonlib/bsd/elog.h>
|
#include <commonlib/bsd/elog.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
@ -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. */
|
/* return the data associated to the event_header. */
|
||||||
const void *event_get_data(const struct event_header *event)
|
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]);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -313,5 +313,11 @@ struct elog_event_extended_event {
|
||||||
enum cb_err elog_verify_header(const struct elog_header *header);
|
enum cb_err elog_verify_header(const struct elog_header *header);
|
||||||
const struct event_header *elog_get_next_event(const struct event_header *event);
|
const struct event_header *elog_get_next_event(const struct event_header *event);
|
||||||
const void *event_get_data(const struct event_header *event);
|
const void *event_get_data(const struct event_header *event);
|
||||||
|
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);
|
||||||
|
/* Update the checksum at the last byte. */
|
||||||
|
void elog_update_checksum(struct event_header *event, uint8_t checksum);
|
||||||
|
/* Simple byte checksum for events. */
|
||||||
|
uint8_t elog_checksum_event(const struct event_header *event);
|
||||||
|
|
||||||
#endif /* _COMMONLIB_BSD_ELOG_H_ */
|
#endif /* _COMMONLIB_BSD_ELOG_H_ */
|
||||||
|
|
|
@ -181,28 +181,6 @@ static void elog_debug_dump_buffer(const char *msg)
|
||||||
rdev_munmap(rdev, buffer);
|
rdev_munmap(rdev, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Update the checksum at the last byte
|
|
||||||
*/
|
|
||||||
static void elog_update_checksum(struct event_header *event, u8 checksum)
|
|
||||||
{
|
|
||||||
u8 *event_data = (u8 *)event;
|
|
||||||
event_data[event->length - 1] = checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Simple byte checksum for events
|
|
||||||
*/
|
|
||||||
static u8 elog_checksum_event(struct event_header *event)
|
|
||||||
{
|
|
||||||
u8 index, checksum = 0;
|
|
||||||
u8 *data = (u8 *)event;
|
|
||||||
|
|
||||||
for (index = 0; index < event->length; index++)
|
|
||||||
checksum += data[index];
|
|
||||||
return checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if mirrored buffer is filled with ELOG_TYPE_EOL byte from the
|
* Check if mirrored buffer is filled with ELOG_TYPE_EOL byte from the
|
||||||
* provided offset to the end of the mirrored buffer.
|
* provided offset to the end of the mirrored buffer.
|
||||||
|
@ -806,42 +784,13 @@ int elog_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Populate timestamp in event header with current time
|
|
||||||
*/
|
|
||||||
static void elog_fill_timestamp(struct event_header *event)
|
|
||||||
{
|
|
||||||
#if CONFIG(RTC)
|
|
||||||
struct rtc_time time;
|
|
||||||
|
|
||||||
rtc_get(&time);
|
|
||||||
event->second = bin2bcd(time.sec);
|
|
||||||
event->minute = bin2bcd(time.min);
|
|
||||||
event->hour = bin2bcd(time.hour);
|
|
||||||
event->day = bin2bcd(time.mday);
|
|
||||||
event->month = bin2bcd(time.mon);
|
|
||||||
event->year = bin2bcd(time.year % 100);
|
|
||||||
|
|
||||||
/* Basic sanity check of expected ranges */
|
|
||||||
if (event->month > 0x12 || event->day > 0x31 || event->hour > 0x23 ||
|
|
||||||
event->minute > 0x59 || event->second > 0x59)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
event->year = 0;
|
|
||||||
event->month = 0;
|
|
||||||
event->day = 0;
|
|
||||||
event->hour = 0;
|
|
||||||
event->minute = 0;
|
|
||||||
event->second = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add an event to the log
|
* Add an event to the log
|
||||||
*/
|
*/
|
||||||
int elog_add_event_raw(u8 event_type, void *data, u8 data_size)
|
int elog_add_event_raw(u8 event_type, void *data, u8 data_size)
|
||||||
{
|
{
|
||||||
struct event_header *event;
|
struct event_header *event;
|
||||||
|
struct rtc_time time = { 0 };
|
||||||
u8 event_size;
|
u8 event_size;
|
||||||
|
|
||||||
elog_debug("%s(type=%X)\n", __func__, event_type);
|
elog_debug("%s(type=%X)\n", __func__, event_type);
|
||||||
|
@ -869,7 +818,11 @@ int elog_add_event_raw(u8 event_type, void *data, u8 data_size)
|
||||||
/* Fill out event data */
|
/* Fill out event data */
|
||||||
event->type = event_type;
|
event->type = event_type;
|
||||||
event->length = event_size;
|
event->length = event_size;
|
||||||
elog_fill_timestamp(event);
|
if (CONFIG(RTC))
|
||||||
|
rtc_get(&time);
|
||||||
|
|
||||||
|
elog_fill_timestamp(event, time.sec, time.min, time.hour,
|
||||||
|
time.mday, time.mon, time.year);
|
||||||
|
|
||||||
if (data_size)
|
if (data_size)
|
||||||
memcpy(&event[1], data, data_size);
|
memcpy(&event[1], data, data_size);
|
||||||
|
|
Loading…
Reference in New Issue