| 71 | namespace HalSystem { |
| 72 | |
| 73 | void begin() { |
| 74 | // This is mostly for the first boot, we need to initialize the panic info and logs to empty state |
| 75 | // If we reboot from a panic state, we want to keep the panic info until we successfully dump it to the SD card, use |
| 76 | // `clearPanic()` to clear it after dumping |
| 77 | if (!isRebootFromPanic()) { |
| 78 | clearPanic(); |
| 79 | } else { |
| 80 | // Panic reboot: preserve logs and panic info, but clamp logHead in case the |
| 81 | // panic occurred before begin() ever ran (e.g. in a static constructor). |
| 82 | // If logHead was out of range, logMessages is also garbage — clear it so |
| 83 | // getLastLogs() does not dump corrupt data into the crash report. |
| 84 | if (sanitizeLogHead()) { |
| 85 | clearLastLogs(); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void checkPanic() { |
| 91 | if (isRebootFromPanic()) { |
no test coverage detected