1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <commonlib/bsd/bcd.h>
4 #include <commonlib/bsd/elog.h>
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
)
16 if (header
->magic
!= ELOG_SIGNATURE
)
19 if (header
->version
!= ELOG_VERSION
)
22 if (header
->header_size
!= sizeof(*header
))
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
)
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) {
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
];