Boot reason via watchdog scratch register, reboot/picoboot CLI commands, enum msgpack support

This commit is contained in:
Ian Gulliver
2026-04-12 08:17:22 +09:00
parent 9b7362c460
commit 6c3e0757f9
8 changed files with 110 additions and 6 deletions

View File

@@ -9,6 +9,17 @@
static constexpr uint32_t XIP_BASE_ADDR = 0x10000000;
static constexpr uint32_t FLASH_SIZE = 2 * 1024 * 1024;
static constexpr uint32_t REBOOT_MAGIC = 0x504D5242;
static boot_reason detected_boot_reason;
void handlers_init() {
if (watchdog_hw->scratch[0] == REBOOT_MAGIC)
detected_boot_reason = boot_reason::request_reboot;
else
detected_boot_reason = boot_reason::cold_boot;
watchdog_hw->scratch[0] = 0;
}
std::optional<ResponsePICOBOOT> handle_picoboot(const responder&, const RequestPICOBOOT&) {
dispatch_schedule_ms(100, []{ reset_usb_boot(0, 1); });
@@ -24,6 +35,7 @@ std::optional<ResponseInfo> handle_info(const responder&, const RequestInfo&) {
resp.mac = ns.mac;
resp.ip = ns.ip;
resp.firmware_name = firmware_name;
resp.boot = detected_boot_reason;
return resp;
}
@@ -67,7 +79,10 @@ std::optional<ResponseFlashWrite> handle_flash_write(const responder&, const Req
}
std::optional<ResponseReboot> handle_reboot(const responder&, const RequestReboot&) {
dispatch_schedule_ms(100, []{ watchdog_reboot(0, 0, 0); });
dispatch_schedule_ms(100, []{
watchdog_hw->scratch[0] = REBOOT_MAGIC;
watchdog_reboot(0, 0, 0);
});
return ResponseReboot{};
}