soc/intel: Remove blank lines before '}' and after '{'
[coreboot2.git] / src / commonlib / bsd / elog.c
blob8151d706988bc0b9ea0edc16f38b85926ae53ae9
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <commonlib/bsd/bcd.h>
4 #include <commonlib/bsd/elog.h>
5 #include <stddef.h>
7 /*
8 * verify and validate if header is a valid coreboot Event Log header.
9 * return CB_ERR if invalid, otherwise CB_SUCCESS.
11 enum cb_err elog_verify_header(const struct elog_header *header)
13 if (header == NULL)
14 return CB_ERR;
16 if (header->magic != ELOG_SIGNATURE)
17 return CB_ERR;
19 if (header->version != ELOG_VERSION)
20 return CB_ERR;
22 if (header->header_size != sizeof(*header))
23 return CB_ERR;
25 return CB_SUCCESS;
29 * return the next elog event.
30 * return NULL if event is invalid.
32 const struct event_header *elog_get_next_event(const struct event_header *event)
34 if (!event)
35 return NULL;
37 /* Point to next event */
38 return (const struct event_header *)((const void *)(event) + event->length);
41 /* return the data associated to the event_header. */
42 const void *event_get_data(const struct event_header *event)
45 * Pointing to the next event returns the data, since data is the first
46 * field right after the header.
48 return (const void *)(&event[1]);
51 /* Populate timestamp in event header with given time. */
52 void elog_fill_timestamp(struct event_header *event, uint8_t sec, uint8_t min,
53 uint8_t hour, uint8_t mday, uint8_t mon, uint16_t year)
55 event->second = bin2bcd(sec);
56 event->minute = bin2bcd(min);
57 event->hour = bin2bcd(hour);
58 event->day = bin2bcd(mday);
59 event->month = bin2bcd(mon);
60 event->year = bin2bcd(year % 100);
62 /* Basic check of expected ranges. */
63 if (event->month > 0x12 || event->day > 0x31 || event->hour > 0x23 ||
64 event->minute > 0x59 || event->second > 0x59) {
65 event->year = 0;
66 event->month = 0;
67 event->day = 0;
68 event->hour = 0;
69 event->minute = 0;
70 event->second = 0;
74 void elog_update_checksum(struct event_header *event, uint8_t checksum)
76 uint8_t *event_data = (uint8_t *)event;
77 event_data[event->length - 1] = checksum;
80 uint8_t elog_checksum_event(const struct event_header *event)
82 uint8_t index, checksum = 0;
83 const uint8_t *data = (const uint8_t *)event;
85 for (index = 0; index < event->length; index++)
86 checksum += data[index];
87 return checksum;