Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | |
| 3 | #include "eventlog.h" |
| 4 | |
| 5 | #include <inttypes.h> |
| 6 | #include <stdarg.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <time.h> |
| 9 | |
| 10 | #include <commonlib/console/post_codes.h> |
| 11 | #include <commonlib/bsd/elog.h> |
| 12 | #include <vb2_api.h> |
| 13 | |
Ricardo Quesada | 49a96a9 | 2021-08-16 11:25:52 -0700 | [diff] [blame] | 14 | #include "common.h" |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 15 | #include "valstr.h" |
| 16 | |
| 17 | #define PATH_PCI_BUS_SHIFT 8 |
| 18 | #define PATH_PCI_BUS_MASK 0xff |
| 19 | #define PATH_PCI_DEV_SHIFT 3 |
| 20 | #define PATH_PCI_DEV_MASK 0x1f |
| 21 | #define PATH_PCI_FN_SHIFT 0 |
| 22 | #define PATH_PCI_FN_MASK 0x03 |
| 23 | #define PATH_I2C_MODE10BIT_SHIFT 8 |
| 24 | #define PATH_I2C_MODE10BIT_MASK 0xff |
| 25 | #define PATH_I2C_ADDRESS_MASK 0xff |
| 26 | |
| 27 | /* When true, then the separator is not printed */ |
| 28 | static int eventlog_printf_ignore_separator_once = 1; |
| 29 | |
| 30 | static void eventlog_printf(const char *format, ...) |
| 31 | { |
| 32 | va_list args; |
| 33 | |
| 34 | // Separator for each field |
| 35 | if (eventlog_printf_ignore_separator_once) |
| 36 | eventlog_printf_ignore_separator_once = 0; |
| 37 | else |
| 38 | fprintf(stdout, " | "); |
| 39 | |
| 40 | va_start(args, format); |
| 41 | vfprintf(stdout, format, args); |
| 42 | va_end(args); |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * eventlog_print_timestamp - forms the key-value pair for event timestamp |
| 47 | * |
| 48 | * @entry: the smbios log entry to get the data information |
| 49 | * |
| 50 | * Forms the key-value description pair for the event timestamp. |
| 51 | */ |
| 52 | static void eventlog_print_timestamp(const struct event_header *event) |
| 53 | { |
| 54 | const char *tm_format = "%y-%m-%d%t%H:%M:%S"; |
| 55 | char tm_string[40]; |
| 56 | struct tm tm; |
| 57 | time_t time; |
| 58 | |
| 59 | memset(&tm, 0, sizeof(tm)); |
| 60 | |
| 61 | /* Time is in "hexa". Convert it to decimal, and then convert it to "tm" struct */ |
| 62 | snprintf(tm_string, sizeof(tm_string), "%02x-%02x-%02x %02x:%02x:%02x", event->year, |
| 63 | event->month, event->day, event->hour, event->minute, event->second); |
| 64 | |
| 65 | if (strptime(tm_string, tm_format, &tm) == NULL) { |
| 66 | /* Backup in case string could not be parsed. Timezone not included */ |
| 67 | eventlog_printf("%02d%02x-%02x-%02x %02x:%02x:%02x", |
| 68 | (event->year > 0x80 && event->year < 0x99) ? 19 : 20, |
| 69 | event->year, event->month, event->day, event->hour, |
| 70 | event->minute, event->second); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | /* Set DST flag to -1 to indicate "not available" and let |
| 75 | * system determine if DST is on based on date */ |
| 76 | tm.tm_isdst = -1; |
| 77 | |
| 78 | time = mktime(&tm); |
| 79 | time += tm.tm_gmtoff; /* force adjust for timezone */ |
| 80 | |
| 81 | strftime(tm_string, sizeof(tm_string), "%Y-%m-%d %H:%M:%S", localtime(&time)); |
| 82 | |
| 83 | eventlog_printf("%s", tm_string); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * eventlog_print_type - print the type of the entry |
| 89 | * |
| 90 | * @entry: the smbios log entry to get type information |
| 91 | * |
| 92 | */ |
| 93 | static void eventlog_print_type(const struct event_header *event) |
| 94 | { |
| 95 | const char *type; |
| 96 | static const struct valstr elog_event_types[] = { |
| 97 | /* SMBIOS Event Log types, SMBIOSv2.4 section 3.3.16.1 */ |
| 98 | {ELOG_TYPE_UNDEFINED_EVENT, "Reserved"}, |
| 99 | {ELOG_TYPE_SINGLE_BIT_ECC_MEM_ERR, "Single-bit ECC memory error"}, |
| 100 | {ELOG_TYPE_MULTI_BIT_ECC_MEM_ERR, "Multi-bit ECC memory error"}, |
| 101 | {ELOG_TYPE_MEM_PARITY_ERR, "Parity memory error"}, |
| 102 | {ELOG_TYPE_BUS_TIMEOUT, "Bus timeout"}, |
| 103 | {ELOG_TYPE_IO_CHECK, "I/O channel check"}, |
| 104 | {ELOG_TYPE_SW_NMI, "Software NMI"}, |
| 105 | {ELOG_TYPE_POST_MEM_RESIZE, "POST memory resize"}, |
| 106 | {ELOG_TYPE_POST_ERR, "POST error"}, |
| 107 | {ELOG_TYPE_PCI_PERR, "PCI parity error"}, |
| 108 | {ELOG_TYPE_PCI_SERR, "PCI system error"}, |
| 109 | {ELOG_TYPE_CPU_FAIL, "CPU failure"}, |
| 110 | {ELOG_TYPE_EISA_TIMEOUT, "EISA failsafe timer timeout"}, |
| 111 | {ELOG_TYPE_CORRECTABLE_MEMLOG_DIS, "Correctable memory log disabled"}, |
| 112 | {ELOG_TYPE_LOG_DISABLED, "Logging disabled, too many errors"}, |
| 113 | {ELOG_TYPE_UNDEFINED_EVENT2, "Reserved"}, |
| 114 | {ELOG_TYPE_SYS_LIMIT_EXCEED, "System limit exceeded"}, |
| 115 | {ELOG_TYPE_ASYNC_HW_TIMER_EXPIRED, "Hardware watchdog reset"}, |
| 116 | {ELOG_TYPE_SYS_CONFIG_INFO, "System configuration information"}, |
| 117 | {ELOG_TYPE_HDD_INFO, "Hard-disk information"}, |
| 118 | {ELOG_TYPE_SYS_RECONFIG, "System reconfigured"}, |
| 119 | {ELOG_TYPE_CPU_ERROR, "Uncorrectable CPU-complex error"}, |
| 120 | {ELOG_TYPE_LOG_CLEAR, "Log area cleared"}, |
| 121 | {ELOG_TYPE_BOOT, "System boot"}, |
| 122 | |
| 123 | /* Extended events defined by OEMs */ |
| 124 | {ELOG_TYPE_OS_EVENT, "Kernel Event"}, |
| 125 | {ELOG_TYPE_OS_BOOT, "OS Boot"}, |
| 126 | {ELOG_TYPE_EC_EVENT, "EC Event"}, |
| 127 | {ELOG_TYPE_POWER_FAIL, "Power Fail"}, |
| 128 | {ELOG_TYPE_SUS_POWER_FAIL, "SUS Power Fail"}, |
| 129 | {ELOG_TYPE_PWROK_FAIL, "PWROK Fail"}, |
| 130 | {ELOG_TYPE_SYS_PWROK_FAIL, "SYS PWROK Fail"}, |
| 131 | {ELOG_TYPE_POWER_ON, "Power On"}, |
| 132 | {ELOG_TYPE_POWER_BUTTON, "Power Button"}, |
| 133 | {ELOG_TYPE_POWER_BUTTON_OVERRIDE, "Power Button Override"}, |
| 134 | {ELOG_TYPE_RESET_BUTTON, "Reset Button"}, |
| 135 | {ELOG_TYPE_SYSTEM_RESET, "System Reset"}, |
| 136 | {ELOG_TYPE_RTC_RESET, "RTC Reset"}, |
| 137 | {ELOG_TYPE_TCO_RESET, "TCO Reset"}, |
| 138 | {ELOG_TYPE_ACPI_ENTER, "ACPI Enter"}, |
| 139 | {ELOG_TYPE_ACPI_WAKE, "ACPI Wake"}, |
| 140 | {ELOG_TYPE_ACPI_DEEP_WAKE, "ACPI Wake"}, |
| 141 | {ELOG_TYPE_S0IX_ENTER, "S0ix Enter"}, |
| 142 | {ELOG_TYPE_S0IX_EXIT, "S0ix Exit"}, |
| 143 | {ELOG_TYPE_WAKE_SOURCE, "Wake Source"}, |
Subrata Banik | 151dcf4 | 2022-08-02 11:42:49 +0000 | [diff] [blame] | 144 | {ELOG_DEPRECATED_TYPE_CROS_DEVELOPER_MODE, "ChromeOS Developer Mode"}, |
| 145 | {ELOG_DEPRECATED_TYPE_CROS_RECOVERY_MODE, "ChromeOS Recovery Mode"}, |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 146 | {ELOG_TYPE_MANAGEMENT_ENGINE, "Management Engine"}, |
| 147 | {ELOG_TYPE_MANAGEMENT_ENGINE_EXT, "Management Engine Extra"}, |
| 148 | {ELOG_TYPE_LAST_POST_CODE, "Last post code in previous boot"}, |
| 149 | {ELOG_TYPE_POST_EXTRA, "Extra info from previous boot"}, |
| 150 | {ELOG_TYPE_EC_SHUTDOWN, "EC Shutdown"}, |
| 151 | {ELOG_TYPE_SLEEP, "Sleep"}, |
| 152 | {ELOG_TYPE_WAKE, "Wake"}, |
| 153 | {ELOG_TYPE_FW_WAKE, "FW Wake"}, |
| 154 | {ELOG_TYPE_MEM_CACHE_UPDATE, "Memory Cache Update"}, |
| 155 | {ELOG_TYPE_THERM_TRIP, "CPU Thermal Trip"}, |
| 156 | {ELOG_TYPE_CR50_UPDATE, "cr50 Update Reset"}, |
| 157 | {ELOG_TYPE_CR50_NEED_RESET, "cr50 Reset Required"}, |
| 158 | {ELOG_TYPE_EC_DEVICE_EVENT, "EC Device"}, |
| 159 | {ELOG_TYPE_EXTENDED_EVENT, "Extended Event"}, |
Hsuan Ting Chen | fec16a3 | 2022-09-26 19:37:11 +0800 | [diff] [blame] | 160 | {ELOG_TYPE_CROS_DIAGNOSTICS, "Diagnostics Mode"}, |
Subrata Banik | 8b46840 | 2022-07-17 18:20:24 +0530 | [diff] [blame] | 161 | {ELOG_TYPE_FW_VBOOT_INFO, "Firmware vboot info"}, |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 162 | |
| 163 | {ELOG_TYPE_EOL, "End of log"}, |
| 164 | }; |
| 165 | |
| 166 | /* Passing NULL as default, because we want to print the event->type if it fails */ |
| 167 | type = val2str_default(event->type, elog_event_types, NULL); |
| 168 | |
| 169 | if (type == NULL) { |
| 170 | /* Indicate unknown type in value pair */ |
| 171 | eventlog_printf("Unknown"); |
| 172 | eventlog_printf("0x%02x", event->type); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | eventlog_printf("%s", type); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * CMOS Extra log format: |
| 181 | * [31:24] = Extra Log Type |
| 182 | * [23:0] = Extra Log Data |
| 183 | * |
| 184 | * If Extra Log Type is 0x01 then Data is Device Path |
| 185 | * [23:16] = Device Type |
| 186 | * [15:0] = Encoded Device Path |
| 187 | */ |
| 188 | static int eventlog_print_post_extra(uint32_t extra) |
| 189 | { |
| 190 | static const struct valstr path_type_values[] = { |
| 191 | {ELOG_DEV_PATH_TYPE_NONE, "None"}, |
| 192 | {ELOG_DEV_PATH_TYPE_ROOT, "Root"}, |
| 193 | {ELOG_DEV_PATH_TYPE_PCI, "PCI"}, |
| 194 | {ELOG_DEV_PATH_TYPE_PNP, "PNP"}, |
| 195 | {ELOG_DEV_PATH_TYPE_I2C, "I2C"}, |
| 196 | {ELOG_DEV_PATH_TYPE_APIC, "APIC"}, |
| 197 | {ELOG_DEV_PATH_TYPE_DOMAIN, "DOMAIN"}, |
| 198 | {ELOG_DEV_PATH_TYPE_CPU_CLUSTER, "CPU Cluster"}, |
| 199 | {ELOG_DEV_PATH_TYPE_CPU, "CPU"}, |
| 200 | {ELOG_DEV_PATH_TYPE_CPU_BUS, "CPU Bus"}, |
| 201 | {ELOG_DEV_PATH_TYPE_IOAPIC, "IO-APIC"}, |
| 202 | {0, NULL}, |
| 203 | }; |
| 204 | const uint8_t type = (extra >> 16) & 0xff; |
| 205 | |
| 206 | /* Currently only know how to print device path */ |
| 207 | if ((extra >> 24) != ELOG_TYPE_POST_EXTRA_PATH) { |
| 208 | eventlog_printf("0x%08x", extra); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | eventlog_printf("%s", val2str(type, path_type_values)); |
| 213 | |
| 214 | /* Handle different device path types */ |
| 215 | switch (type) { |
| 216 | case ELOG_DEV_PATH_TYPE_PCI: |
| 217 | eventlog_printf("%02x:%02x.%1x", |
| 218 | (extra >> PATH_PCI_BUS_SHIFT) & PATH_PCI_BUS_MASK, |
| 219 | (extra >> PATH_PCI_DEV_SHIFT) & PATH_PCI_DEV_MASK, |
| 220 | (extra >> PATH_PCI_FN_SHIFT) & PATH_PCI_FN_MASK); |
| 221 | break; |
| 222 | case ELOG_DEV_PATH_TYPE_PNP: |
| 223 | case ELOG_DEV_PATH_TYPE_I2C: |
| 224 | eventlog_printf("%02x:%02x", |
| 225 | (extra >> PATH_I2C_MODE10BIT_SHIFT) & PATH_I2C_MODE10BIT_MASK, |
| 226 | extra & PATH_I2C_ADDRESS_MASK); |
| 227 | break; |
| 228 | case ELOG_DEV_PATH_TYPE_APIC: |
| 229 | case ELOG_DEV_PATH_TYPE_DOMAIN: |
| 230 | case ELOG_DEV_PATH_TYPE_CPU_CLUSTER: |
| 231 | case ELOG_DEV_PATH_TYPE_CPU: |
| 232 | case ELOG_DEV_PATH_TYPE_CPU_BUS: |
| 233 | case ELOG_DEV_PATH_TYPE_IOAPIC: |
| 234 | eventlog_printf("0x%04x", extra & 0xffff); |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * eventlog_print_data - print the data associated with the entry |
| 243 | * |
| 244 | * @event: the smbios log entry to get the data information |
| 245 | * |
| 246 | * Returns 0 on failure, 1 on success. |
| 247 | */ |
| 248 | static int eventlog_print_data(const struct event_header *event) |
| 249 | { |
| 250 | static const struct valstr os_events[] = { |
| 251 | {ELOG_OS_EVENT_CLEAN, "Clean Shutdown"}, |
| 252 | {ELOG_OS_EVENT_NMIWDT, "NMI Watchdog"}, |
| 253 | {ELOG_OS_EVENT_PANIC, "Panic"}, |
| 254 | {ELOG_OS_EVENT_OOPS, "Oops"}, |
| 255 | {ELOG_OS_EVENT_DIE, "Die"}, |
| 256 | {ELOG_OS_EVENT_MCE, "MCE"}, |
| 257 | {ELOG_OS_EVENT_SOFTWDT, "Software Watchdog"}, |
| 258 | {ELOG_OS_EVENT_MBE, "Multi-bit Error"}, |
| 259 | {ELOG_OS_EVENT_TRIPLE, "Triple Fault"}, |
| 260 | {ELOG_OS_EVENT_THERMAL, "Critical Thermal Threshold"}, |
| 261 | {0, NULL}, |
| 262 | }; |
| 263 | static const struct valstr wake_source_types[] = { |
| 264 | {ELOG_WAKE_SOURCE_PCIE, "PCI Express"}, |
| 265 | {ELOG_WAKE_SOURCE_PME, "PCI PME"}, |
| 266 | {ELOG_WAKE_SOURCE_PME_INTERNAL, "Internal PME"}, |
| 267 | {ELOG_WAKE_SOURCE_RTC, "RTC Alarm"}, |
| 268 | {ELOG_WAKE_SOURCE_GPE, "GPE #"}, |
| 269 | {ELOG_WAKE_SOURCE_SMBUS, "SMBALERT"}, |
| 270 | {ELOG_WAKE_SOURCE_PWRBTN, "Power Button"}, |
| 271 | {ELOG_WAKE_SOURCE_PME_HDA, "PME - HDA"}, |
| 272 | {ELOG_WAKE_SOURCE_PME_GBE, "PME - GBE"}, |
| 273 | {ELOG_WAKE_SOURCE_PME_EMMC, "PME - EMMC"}, |
| 274 | {ELOG_WAKE_SOURCE_PME_SDCARD, "PME - SDCARD"}, |
| 275 | {ELOG_WAKE_SOURCE_PME_PCIE1, "PME - PCIE1"}, |
| 276 | {ELOG_WAKE_SOURCE_PME_PCIE2, "PME - PCIE2"}, |
| 277 | {ELOG_WAKE_SOURCE_PME_PCIE3, "PME - PCIE3"}, |
| 278 | {ELOG_WAKE_SOURCE_PME_PCIE4, "PME - PCIE4"}, |
| 279 | {ELOG_WAKE_SOURCE_PME_PCIE5, "PME - PCIE5"}, |
| 280 | {ELOG_WAKE_SOURCE_PME_PCIE6, "PME - PCIE6"}, |
| 281 | {ELOG_WAKE_SOURCE_PME_PCIE7, "PME - PCIE7"}, |
| 282 | {ELOG_WAKE_SOURCE_PME_PCIE8, "PME - PCIE8"}, |
| 283 | {ELOG_WAKE_SOURCE_PME_PCIE9, "PME - PCIE9"}, |
| 284 | {ELOG_WAKE_SOURCE_PME_PCIE10, "PME - PCIE10"}, |
| 285 | {ELOG_WAKE_SOURCE_PME_PCIE11, "PME - PCIE11"}, |
| 286 | {ELOG_WAKE_SOURCE_PME_PCIE12, "PME - PCIE12"}, |
| 287 | {ELOG_WAKE_SOURCE_PME_SATA, "PME - SATA"}, |
| 288 | {ELOG_WAKE_SOURCE_PME_CSE, "PME - CSE"}, |
| 289 | {ELOG_WAKE_SOURCE_PME_CSE2, "PME - CSE2"}, |
| 290 | {ELOG_WAKE_SOURCE_PME_CSE3, "PME - CSE"}, |
| 291 | {ELOG_WAKE_SOURCE_PME_XHCI, "PME - XHCI"}, |
| 292 | {ELOG_WAKE_SOURCE_PME_XDCI, "PME - XDCI"}, |
| 293 | {ELOG_WAKE_SOURCE_PME_XHCI_USB_2, "PME - XHCI (USB 2.0 port)"}, |
| 294 | {ELOG_WAKE_SOURCE_PME_XHCI_USB_3, "PME - XHCI (USB 3.0 port)"}, |
| 295 | {ELOG_WAKE_SOURCE_PME_WIFI, "PME - WIFI"}, |
| 296 | {ELOG_WAKE_SOURCE_PME_PCIE13, "PME - PCIE13"}, |
| 297 | {ELOG_WAKE_SOURCE_PME_PCIE14, "PME - PCIE14"}, |
| 298 | {ELOG_WAKE_SOURCE_PME_PCIE15, "PME - PCIE15"}, |
| 299 | {ELOG_WAKE_SOURCE_PME_PCIE16, "PME - PCIE16"}, |
| 300 | {ELOG_WAKE_SOURCE_PME_PCIE17, "PME - PCIE17"}, |
| 301 | {ELOG_WAKE_SOURCE_PME_PCIE18, "PME - PCIE18"}, |
| 302 | {ELOG_WAKE_SOURCE_PME_PCIE19, "PME - PCIE19"}, |
| 303 | {ELOG_WAKE_SOURCE_PME_PCIE20, "PME - PCIE20"}, |
| 304 | {ELOG_WAKE_SOURCE_PME_PCIE21, "PME - PCIE21"}, |
| 305 | {ELOG_WAKE_SOURCE_PME_PCIE22, "PME - PCIE22"}, |
| 306 | {ELOG_WAKE_SOURCE_PME_PCIE23, "PME - PCIE23"}, |
| 307 | {ELOG_WAKE_SOURCE_PME_PCIE24, "PME - PCIE24"}, |
| 308 | {ELOG_WAKE_SOURCE_GPIO, " GPIO #"}, |
| 309 | {ELOG_WAKE_SOURCE_PME_TBT, "PME - Thunderbolt"}, |
| 310 | {ELOG_WAKE_SOURCE_PME_TCSS_XHCI, "PME - TCSS XHCI"}, |
| 311 | {ELOG_WAKE_SOURCE_PME_TCSS_XHCI, "PME - TCSS XDCI"}, |
| 312 | {ELOG_WAKE_SOURCE_PME_TCSS_XHCI, "PME - TCSS DMA"}, |
| 313 | {0, NULL}, |
| 314 | }; |
| 315 | static const struct valstr ec_event_types[] = { |
| 316 | {EC_EVENT_LID_CLOSED, "Lid Closed"}, |
| 317 | {EC_EVENT_LID_OPEN, "Lid Open"}, |
| 318 | {EC_EVENT_POWER_BUTTON, "Power Button"}, |
| 319 | {EC_EVENT_AC_CONNECTED, "AC Connected"}, |
| 320 | {EC_EVENT_AC_DISCONNECTED, "AC Disconnected"}, |
| 321 | {EC_EVENT_BATTERY_LOW, "Battery Low"}, |
| 322 | {EC_EVENT_BATTERY_CRITICAL, "Battery Critical"}, |
| 323 | {EC_EVENT_BATTERY, "Battery"}, |
| 324 | {EC_EVENT_THERMAL_THRESHOLD, "Thermal Threshold"}, |
| 325 | {EC_EVENT_DEVICE_EVENT, "Device Event"}, |
| 326 | {EC_EVENT_THERMAL, "Thermal"}, |
| 327 | {EC_EVENT_USB_CHARGER, "USB Charger"}, |
| 328 | {EC_EVENT_KEY_PRESSED, "Key Pressed"}, |
| 329 | {EC_EVENT_INTERFACE_READY, "Host Interface Ready"}, |
| 330 | {EC_EVENT_KEYBOARD_RECOVERY, "Keyboard Recovery"}, |
| 331 | {EC_EVENT_THERMAL_SHUTDOWN, "Thermal Shutdown in previous boot"}, |
| 332 | {EC_EVENT_BATTERY_SHUTDOWN, "Battery Shutdown in previous boot"}, |
| 333 | {EC_EVENT_THROTTLE_START, "Throttle Requested"}, |
| 334 | {EC_EVENT_THROTTLE_STOP, "Throttle Request Removed"}, |
| 335 | {EC_EVENT_HANG_DETECT, "Host Event Hang"}, |
| 336 | {EC_EVENT_HANG_REBOOT, "Host Event Hang Reboot"}, |
| 337 | {EC_EVENT_PD_MCU, "PD MCU Request"}, |
| 338 | {EC_EVENT_BATTERY_STATUS, "Battery Status Request"}, |
| 339 | {EC_EVENT_PANIC, "Panic Reset in previous boot"}, |
| 340 | {EC_EVENT_KEYBOARD_FASTBOOT, "Keyboard Fastboot Recovery"}, |
| 341 | {EC_EVENT_RTC, "RTC"}, |
| 342 | {EC_EVENT_MKBP, "MKBP"}, |
| 343 | {EC_EVENT_USB_MUX, "USB MUX change"}, |
| 344 | {EC_EVENT_MODE_CHANGE, "Mode change"}, |
| 345 | {EC_EVENT_KEYBOARD_RECOVERY_HWREINIT, |
| 346 | "Keyboard Recovery Forced Hardware Reinit"}, |
| 347 | {EC_EVENT_EXTENDED, "Extended EC events"}, |
| 348 | {0, NULL}, |
| 349 | }; |
| 350 | static const struct valstr ec_device_event_types[] = { |
| 351 | {ELOG_EC_DEVICE_EVENT_TRACKPAD, "Trackpad"}, |
| 352 | {ELOG_EC_DEVICE_EVENT_DSP, "DSP"}, |
| 353 | {ELOG_EC_DEVICE_EVENT_WIFI, "WiFi"}, |
| 354 | {0, NULL}, |
| 355 | }; |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 356 | static const struct valstr me_path_types[] = { |
| 357 | {ELOG_ME_PATH_NORMAL, "Normal"}, |
| 358 | {ELOG_ME_PATH_NORMAL, "S3 Wake"}, |
| 359 | {ELOG_ME_PATH_ERROR, "Error"}, |
| 360 | {ELOG_ME_PATH_RECOVERY, "Recovery"}, |
| 361 | {ELOG_ME_PATH_DISABLED, "Disabled"}, |
| 362 | {ELOG_ME_PATH_FW_UPDATE, "Firmware Update"}, |
| 363 | {0, NULL}, |
| 364 | }; |
| 365 | static const struct valstr coreboot_post_codes[] = { |
| 366 | {POST_RESET_VECTOR_CORRECT, "Reset Vector Correct"}, |
| 367 | {POST_ENTER_PROTECTED_MODE, "Enter Protected Mode"}, |
| 368 | {POST_PREPARE_RAMSTAGE, "Prepare RAM stage"}, |
| 369 | {POST_ENTRY_C_START, "RAM stage Start"}, |
| 370 | {POST_MEM_PREINIT_PREP_START, "Preparing memory init params"}, |
| 371 | {POST_MEM_PREINIT_PREP_END, "Memory init param preparation complete"}, |
| 372 | {POST_CONSOLE_READY, "Console is ready"}, |
| 373 | {POST_CONSOLE_BOOT_MSG, "Console Boot Message"}, |
| 374 | {POST_ENABLING_CACHE, "Before Enabling Cache"}, |
| 375 | {POST_PRE_HARDWAREMAIN, "Before Hardware Main"}, |
| 376 | {POST_ENTRY_HARDWAREMAIN, "First call in Hardware Main"}, |
| 377 | {POST_BS_PRE_DEVICE, "Before Device Probe"}, |
| 378 | {POST_BS_DEV_INIT_CHIPS, "Initialize Chips"}, |
| 379 | {POST_BS_DEV_ENUMERATE, "Device Enumerate"}, |
| 380 | {POST_BS_DEV_RESOURCES, "Device Resource Allocation"}, |
| 381 | {POST_BS_DEV_ENABLE, "Device Enable"}, |
| 382 | {POST_BS_DEV_INIT, "Device Initialize"}, |
| 383 | {POST_BS_POST_DEVICE, "After Device Probe"}, |
| 384 | {POST_BS_OS_RESUME_CHECK, "OS Resume Check"}, |
| 385 | {POST_BS_OS_RESUME, "OS Resume"}, |
| 386 | {POST_BS_WRITE_TABLES, "Write Tables"}, |
| 387 | {POST_BS_PAYLOAD_LOAD, "Load Payload"}, |
| 388 | {POST_BS_PAYLOAD_BOOT, "Boot Payload"}, |
| 389 | {POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE, "FSP Notify Before End of Firmware"}, |
| 390 | {POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE, "FSP Notify After End of Firmware"}, |
| 391 | {POST_FSP_TEMP_RAM_INIT, "FSP-T Enter"}, |
| 392 | {POST_FSP_TEMP_RAM_EXIT, "FSP-T Exit"}, |
| 393 | {POST_FSP_MEMORY_INIT, "FSP-M Enter"}, |
| 394 | {POST_FSP_SILICON_INIT, "FSP-S Enter"}, |
| 395 | {POST_FSP_NOTIFY_BEFORE_ENUMERATE, "FSP Notify Before Enumerate"}, |
| 396 | {POST_FSP_NOTIFY_BEFORE_FINALIZE, "FSP Notify Before Finalize"}, |
| 397 | {POST_OS_ENTER_PTS, "ACPI _PTS Method"}, |
| 398 | {POST_OS_ENTER_WAKE, "ACPI _WAK Method"}, |
| 399 | {POST_FSP_MEMORY_EXIT, "FSP-M Exit"}, |
| 400 | {POST_FSP_SILICON_EXIT, "FSP-S Exit"}, |
| 401 | {POST_FSP_MULTI_PHASE_SI_INIT_ENTRY, "FSP-S Init Enter"}, |
| 402 | {POST_FSP_MULTI_PHASE_SI_INIT_EXIT, "FPS-S Init Exit"}, |
| 403 | {POST_FSP_NOTIFY_AFTER_ENUMERATE, "FSP Notify After Enumerate"}, |
| 404 | {POST_FSP_NOTIFY_AFTER_FINALIZE, "FSP Notify After Finalize"}, |
| 405 | {POST_INVALID_ROM, "Invalid ROM"}, |
| 406 | {POST_INVALID_CBFS, "Invalid CBFS"}, |
| 407 | {POST_INVALID_VENDOR_BINARY, "Invalid Vendor Binary"}, |
| 408 | {POST_RAM_FAILURE, "RAM Failure"}, |
| 409 | {POST_HW_INIT_FAILURE, "Hardware Init Failure"}, |
| 410 | {POST_VIDEO_FAILURE, "Video Failure"}, |
| 411 | {POST_TPM_FAILURE, "TPM Failure"}, |
| 412 | {POST_DEAD_CODE, "Dead Code"}, |
| 413 | {POST_RESUME_FAILURE, "Resume Failure"}, |
| 414 | {POST_JUMPING_TO_PAYLOAD, "Before Jump to Payload"}, |
| 415 | {POST_ENTER_ELF_BOOT, "Before ELF Boot"}, |
| 416 | {POST_OS_RESUME, "Before OS Resume"}, |
| 417 | {POST_OS_BOOT, "Before OS Boot"}, |
| 418 | {POST_DIE, "coreboot Dead"}, |
| 419 | {0, NULL}, |
| 420 | }; |
| 421 | static const struct valstr mem_cache_slots[] = { |
| 422 | {ELOG_MEM_CACHE_UPDATE_SLOT_NORMAL, "Normal"}, |
| 423 | {ELOG_MEM_CACHE_UPDATE_SLOT_RECOVERY, "Recovery"}, |
| 424 | {ELOG_MEM_CACHE_UPDATE_SLOT_VARIABLE, "Variable"}, |
| 425 | {0, NULL}, |
| 426 | }; |
| 427 | static const struct valstr mem_cache_statuses[] = { |
| 428 | {ELOG_MEM_CACHE_UPDATE_STATUS_SUCCESS, "Success"}, |
| 429 | {ELOG_MEM_CACHE_UPDATE_STATUS_FAIL, "Fail"}, |
| 430 | {0, NULL}, |
| 431 | }; |
| 432 | |
| 433 | static const struct valstr extended_event_subtypes[] = { |
| 434 | {ELOG_SLEEP_PENDING_PM1_WAKE, "S3 failed due to pending wake event, PM1"}, |
| 435 | {ELOG_SLEEP_PENDING_GPE0_WAKE, "S3 failed due to pending wake event, GPE0"}, |
| 436 | {0, NULL}, |
| 437 | }; |
| 438 | |
Hsuan Ting Chen | fec16a3 | 2022-09-26 19:37:11 +0800 | [diff] [blame] | 439 | static const struct valstr cros_diagnostics_types[] = { |
Subrata Banik | 151dcf4 | 2022-08-02 11:42:49 +0000 | [diff] [blame] | 440 | {ELOG_DEPRECATED_CROS_LAUNCH_DIAGNOSTICS, "Launch Diagnostics"}, |
Hsuan Ting Chen | fec16a3 | 2022-09-26 19:37:11 +0800 | [diff] [blame] | 441 | {ELOG_CROS_DIAGNOSTICS_LOGS, "Diagnostics Logs"}, |
| 442 | {0, NULL}, |
| 443 | }; |
| 444 | |
| 445 | static const struct valstr cros_diagnostics_diag_types[] = { |
| 446 | {ELOG_CROS_DIAG_TYPE_NONE, "None"}, |
| 447 | {ELOG_CROS_DIAG_TYPE_STORAGE_HEALTH, "Storage Health Info"}, |
| 448 | {ELOG_CROS_DIAG_TYPE_STORAGE_TEST_SHORT, "Storage self-test (short)"}, |
| 449 | {ELOG_CROS_DIAG_TYPE_STORAGE_TEST_EXTENDED, "Storage self-test (extended)"}, |
| 450 | {ELOG_CROS_DIAG_TYPE_MEMORY_QUICK, "Memory check (quick)"}, |
| 451 | {ELOG_CROS_DIAG_TYPE_MEMORY_FULL, "Memory check (full)"}, |
| 452 | {0, NULL}, |
| 453 | }; |
| 454 | |
| 455 | static const struct valstr cros_diagnostics_diag_results[] = { |
| 456 | {ELOG_CROS_DIAG_RESULT_PASSED, "Passed"}, |
| 457 | {ELOG_CROS_DIAG_RESULT_ERROR, "Error"}, |
| 458 | {ELOG_CROS_DIAG_RESULT_FAILED, "Failed"}, |
| 459 | {ELOG_CROS_DIAG_RESULT_ABORTED, "Aborted"}, |
Hsuan Ting Chen | a5cbe27 | 2021-11-01 19:14:01 +0800 | [diff] [blame] | 460 | {0, NULL}, |
| 461 | }; |
| 462 | |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 463 | switch (event->type) { |
| 464 | case ELOG_TYPE_LOG_CLEAR: { |
| 465 | const uint16_t *bytes = event_get_data(event); |
| 466 | eventlog_printf("%u", *bytes); |
| 467 | break; |
| 468 | } |
| 469 | |
| 470 | case ELOG_TYPE_BOOT: { |
| 471 | const uint32_t *count = event_get_data(event); |
| 472 | eventlog_printf("%u", *count); |
| 473 | break; |
| 474 | } |
| 475 | case ELOG_TYPE_LAST_POST_CODE: { |
| 476 | const uint16_t *code = event_get_data(event); |
| 477 | eventlog_printf("0x%02x", *code); |
| 478 | eventlog_printf("%s", val2str(*code, coreboot_post_codes)); |
| 479 | break; |
| 480 | } |
| 481 | case ELOG_TYPE_POST_EXTRA: { |
| 482 | const uint32_t *extra = event_get_data(event); |
| 483 | eventlog_print_post_extra(*extra); |
| 484 | break; |
| 485 | } |
| 486 | case ELOG_TYPE_OS_EVENT: { |
| 487 | const uint32_t *osevent = event_get_data(event); |
| 488 | eventlog_printf("%s", val2str(*osevent, os_events)); |
| 489 | break; |
| 490 | } |
| 491 | case ELOG_TYPE_ACPI_ENTER: |
| 492 | case ELOG_TYPE_ACPI_WAKE: { |
| 493 | const uint8_t *state = event_get_data(event); |
| 494 | eventlog_printf("S%u", *state); |
| 495 | break; |
| 496 | } |
| 497 | case ELOG_TYPE_ACPI_DEEP_WAKE: { |
| 498 | const uint8_t *state = event_get_data(event); |
| 499 | eventlog_printf("Deep S%u", *state); |
| 500 | break; |
| 501 | } |
| 502 | case ELOG_TYPE_WAKE_SOURCE: { |
| 503 | const struct elog_event_data_wake *wake_source; |
| 504 | wake_source = event_get_data(event); |
| 505 | eventlog_printf("%s", val2str(wake_source->source, wake_source_types)); |
| 506 | eventlog_printf("%u", wake_source->instance); |
| 507 | break; |
| 508 | } |
| 509 | case ELOG_TYPE_EC_EVENT: { |
| 510 | const uint8_t *ec_event = event_get_data(event); |
| 511 | eventlog_printf("%s", val2str(*ec_event, ec_event_types)); |
| 512 | break; |
| 513 | } |
| 514 | case ELOG_TYPE_EC_DEVICE_EVENT: { |
| 515 | const uint8_t *dev_event = event_get_data(event); |
| 516 | eventlog_printf("%s", val2str(*dev_event, ec_device_event_types)); |
| 517 | break; |
| 518 | } |
Subrata Banik | 151dcf4 | 2022-08-02 11:42:49 +0000 | [diff] [blame] | 519 | case ELOG_DEPRECATED_TYPE_CROS_RECOVERY_MODE: { |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 520 | const uint8_t *reason = event_get_data(event); |
Subrata Banik | 151dcf4 | 2022-08-02 11:42:49 +0000 | [diff] [blame] | 521 | eventlog_printf("%s", vb2_get_recovery_reason_string(*reason)); |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 522 | eventlog_printf("0x%02x", *reason); |
| 523 | break; |
| 524 | } |
| 525 | case ELOG_TYPE_MANAGEMENT_ENGINE: { |
| 526 | const uint8_t *path = event_get_data(event); |
| 527 | eventlog_printf("%s", val2str(*path, me_path_types)); |
| 528 | break; |
| 529 | } |
| 530 | case ELOG_TYPE_MEM_CACHE_UPDATE: { |
| 531 | const struct elog_event_mem_cache_update *update; |
| 532 | update = event_get_data(event); |
| 533 | eventlog_printf("%s", val2str(update->slot, mem_cache_slots)); |
| 534 | eventlog_printf("%s", val2str(update->status, mem_cache_statuses)); |
| 535 | break; |
| 536 | } |
| 537 | case ELOG_TYPE_EXTENDED_EVENT: { |
| 538 | const struct elog_event_extended_event *ext_event; |
| 539 | ext_event = event_get_data(event); |
| 540 | eventlog_printf("%s", val2str(ext_event->event_type, extended_event_subtypes)); |
| 541 | eventlog_printf("0x%X", ext_event->event_complement); |
| 542 | break; |
| 543 | } |
Hsuan Ting Chen | fec16a3 | 2022-09-26 19:37:11 +0800 | [diff] [blame] | 544 | case ELOG_TYPE_CROS_DIAGNOSTICS: { |
| 545 | const uint8_t *data = event_get_data(event); |
| 546 | const uint8_t subtype = *data; |
| 547 | eventlog_printf("%s", val2str(subtype, cros_diagnostics_types)); |
| 548 | |
| 549 | /* |
| 550 | * If the subtype is diagnostics logs, there will be many |
| 551 | * elog_event_diag_log events after subtype: |
| 552 | * |
| 553 | * [event_header][(subtype)(log 1)(log 2)...(log n)][checksum] |
| 554 | * |
| 555 | * Parse them one by one. |
| 556 | */ |
| 557 | if (subtype == ELOG_CROS_DIAGNOSTICS_LOGS) { |
| 558 | size_t i, base_size, log_size, num_logs; |
| 559 | const union elog_event_cros_diag_log *log; |
| 560 | |
| 561 | /* |
| 562 | * base_size = event header + checksum + subtype; |
| 563 | * log_size = event length - base_size. |
| 564 | */ |
| 565 | base_size = sizeof(*event) + 1 + sizeof(subtype); |
| 566 | /* Validity check to prevent log_size overflow */ |
| 567 | if (event->length > base_size) { |
| 568 | log_size = event->length - base_size; |
| 569 | num_logs = log_size / sizeof(union elog_event_cros_diag_log); |
| 570 | log = (const union elog_event_cros_diag_log *)(data + 1); |
| 571 | for (i = 0; i < num_logs; i++) { |
| 572 | eventlog_printf("type=%s, result=%s, time=%um%us", |
| 573 | val2str(log->type, |
| 574 | cros_diagnostics_diag_types), |
| 575 | val2str(log->result, |
| 576 | cros_diagnostics_diag_results), |
| 577 | log->time_s / 60, log->time_s % 60); |
| 578 | log++; |
| 579 | } |
| 580 | } |
| 581 | } |
Subrata Banik | 8b46840 | 2022-07-17 18:20:24 +0530 | [diff] [blame] | 582 | break; |
| 583 | } |
| 584 | case ELOG_TYPE_FW_VBOOT_INFO: { |
| 585 | const union vb2_fw_boot_info *info = event_get_data(event); |
| 586 | |
| 587 | eventlog_printf("boot_mode=%s", vb2_boot_mode_string(info->boot_mode)); |
| 588 | |
| 589 | if (info->boot_mode == VB2_BOOT_MODE_BROKEN_SCREEN || |
| 590 | info->boot_mode == VB2_BOOT_MODE_MANUAL_RECOVERY) |
| 591 | eventlog_printf("recovery_reason=%#x/%#x (%s)", |
| 592 | info->recovery_reason, info->recovery_subcode, |
| 593 | vb2_get_recovery_reason_string(info->recovery_reason)); |
| 594 | |
| 595 | eventlog_printf("fw_tried=%s", vb2_slot_string(info->slot)); |
| 596 | eventlog_printf("fw_try_count=%d", info->tries); |
| 597 | eventlog_printf("fw_prev_tried=%s", vb2_slot_string(info->prev_slot)); |
| 598 | eventlog_printf("fw_prev_result=%s", vb2_result_string(info->prev_result)); |
| 599 | break; |
Hsuan Ting Chen | a5cbe27 | 2021-11-01 19:14:01 +0800 | [diff] [blame] | 600 | } |
Ricardo Quesada | c2cf394 | 2021-07-16 16:49:04 -0700 | [diff] [blame] | 601 | default: |
| 602 | break; |
| 603 | } |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | void eventlog_print_event(const struct event_header *event, int count) |
| 609 | { |
| 610 | /* Ignore the printf separator at the beginning and end of each line */ |
| 611 | eventlog_printf_ignore_separator_once = 1; |
| 612 | |
| 613 | eventlog_printf("%d", count); |
| 614 | eventlog_print_timestamp(event); |
| 615 | eventlog_print_type(event); |
| 616 | eventlog_print_data(event); |
| 617 | |
| 618 | /* End of line, after printing each event */ |
| 619 | eventlog_printf_ignore_separator_once = 1; |
| 620 | eventlog_printf("\n"); |
| 621 | } |
Ricardo Quesada | 49a96a9 | 2021-08-16 11:25:52 -0700 | [diff] [blame] | 622 | |
| 623 | /* |
| 624 | * Initializes the eventlog header with the given type and data, |
| 625 | * and calculates the checksum. |
| 626 | * buffer_get() points to the event to be initialized. |
| 627 | * On success it returns 1, otherwise 0. |
| 628 | */ |
| 629 | int eventlog_init_event(const struct buffer *buf, uint8_t type, |
| 630 | const void *data, int data_size) |
| 631 | { |
| 632 | struct event_header *event; |
| 633 | time_t secs = time(NULL); |
| 634 | struct tm tm; |
| 635 | |
| 636 | /* Must have at least size for data + checksum byte */ |
| 637 | if (buffer_size(buf) < (size_t)data_size + 1) |
| 638 | return 0; |
| 639 | |
| 640 | event = buffer_get(buf); |
| 641 | |
| 642 | event->type = type; |
| 643 | gmtime_r(&secs, &tm); |
Ricardo Quesada | 1427f12 | 2021-09-22 20:08:35 -0700 | [diff] [blame] | 644 | /* Month should be +1, since gmtime uses 0 as first month */ |
Ricardo Quesada | 49a96a9 | 2021-08-16 11:25:52 -0700 | [diff] [blame] | 645 | elog_fill_timestamp(event, tm.tm_sec, tm.tm_min, tm.tm_hour, |
Ricardo Quesada | 1427f12 | 2021-09-22 20:08:35 -0700 | [diff] [blame] | 646 | tm.tm_mday, tm.tm_mon + 1, tm.tm_year); |
Ricardo Quesada | 49a96a9 | 2021-08-16 11:25:52 -0700 | [diff] [blame] | 647 | |
| 648 | if (data && data_size) { |
| 649 | uint32_t *ptr = (uint32_t *)&event[1]; |
| 650 | memcpy(ptr, data, data_size); |
| 651 | } |
| 652 | |
| 653 | /* Header + data + checksum */ |
| 654 | event->length = sizeof(*event) + data_size + 1; |
| 655 | |
| 656 | /* Zero the checksum byte and then compute checksum */ |
| 657 | elog_update_checksum(event, 0); |
| 658 | elog_update_checksum(event, -(elog_checksum_event(event))); |
| 659 | |
| 660 | return 1; |
| 661 | } |