diff options
-rw-r--r-- | common/host_event_commands.c | 4 | ||||
-rw-r--r-- | common/system.c | 29 | ||||
-rw-r--r-- | include/ec_commands.h | 8 | ||||
-rw-r--r-- | include/system.h | 13 |
4 files changed, 47 insertions, 7 deletions
diff --git a/common/host_event_commands.c b/common/host_event_commands.c index ae2026efaf..1856c88c37 100644 --- a/common/host_event_commands.c +++ b/common/host_event_commands.c @@ -330,6 +330,10 @@ void host_set_events(host_event_t mask) HOST_EVENT_CPRINTS("event set", mask); + if (!IS_ENABLED(CONFIG_ZTEST) && + (mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY))) + system_enter_manual_recovery(); + host_events_atomic_or(&events, mask); host_events_atomic_or(&events_copy_b, mask); diff --git a/common/system.c b/common/system.c index ca99bf661a..1648bbe465 100644 --- a/common/system.c +++ b/common/system.c @@ -64,6 +64,8 @@ static int disable_jump; /* Disable ALL jumps if system is locked */ static int force_locked; /* Force system locked even if WP isn't enabled */ static enum ec_reboot_cmd reboot_at_shutdown; +static enum sysinfo_flags system_info_flags; + STATIC_IF(CONFIG_HIBERNATE) uint32_t hibernate_seconds; STATIC_IF(CONFIG_HIBERNATE) uint32_t hibernate_microseconds; @@ -919,9 +921,19 @@ void system_common_pre_init(void) } } +void system_enter_manual_recovery(void) +{ + system_info_flags |= SYSTEM_IN_MANUAL_RECOVERY; +} + +void system_exit_manual_recovery(void) +{ + system_info_flags &= ~SYSTEM_IN_MANUAL_RECOVERY; +} + int system_is_manual_recovery(void) { - return host_is_event_set(EC_HOST_EVENT_KEYBOARD_RECOVERY); + return system_info_flags & SYSTEM_IN_MANUAL_RECOVERY; } /** @@ -1030,6 +1042,7 @@ void system_enter_hibernate(uint32_t seconds, uint32_t microseconds) static void system_common_shutdown(void) { + system_exit_manual_recovery(); if (reboot_at_shutdown) CPRINTF("Reboot at shutdown: %d\n", reboot_at_shutdown); handle_pending_reboot(reboot_at_shutdown); @@ -1050,18 +1063,20 @@ static int sysinfo(struct ec_response_sysinfo *info) info->current_image = system_get_image_copy(); if (system_jumped_to_this_image()) - info->flags |= SYSTEM_JUMPED_TO_CURRENT_IMAGE; + system_info_flags |= SYSTEM_JUMPED_TO_CURRENT_IMAGE; if (system_is_locked()) { - info->flags |= SYSTEM_IS_LOCKED; + system_info_flags |= SYSTEM_IS_LOCKED; if (force_locked) - info->flags |= SYSTEM_IS_FORCE_LOCKED; + system_info_flags |= SYSTEM_IS_FORCE_LOCKED; if (!disable_jump) - info->flags |= SYSTEM_JUMP_ENABLED; + system_info_flags |= SYSTEM_JUMP_ENABLED; } if (reboot_at_shutdown) - info->flags |= SYSTEM_REBOOT_AT_SHUTDOWN; + system_info_flags |= SYSTEM_REBOOT_AT_SHUTDOWN; + + info->flags = system_info_flags; return EC_SUCCESS; } @@ -1081,6 +1096,8 @@ static int command_sysinfo(int argc, char **argv) ccprintf("Copy: %s\n", ec_image_to_string(info.current_image)); ccprintf("Jumped: %s\n", (info.flags & SYSTEM_JUMPED_TO_CURRENT_IMAGE) ? "yes" : "no"); + ccprintf("Recovery: %s\n", + (info.flags & SYSTEM_IN_MANUAL_RECOVERY) ? "yes" : "no"); ccputs("Flags: "); if (info.flags & SYSTEM_IS_LOCKED) { diff --git a/include/ec_commands.h b/include/ec_commands.h index bda9bb5378..d1b5b3ea90 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1949,7 +1949,13 @@ enum sysinfo_flags { SYSTEM_IS_FORCE_LOCKED = BIT(1), SYSTEM_JUMP_ENABLED = BIT(2), SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), - SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4) + SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4), + /* + * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is + * set and cleared when the system shuts down (not when the host event + * flag is cleared). + */ + SYSTEM_IN_MANUAL_RECOVERY = BIT(5), }; struct ec_response_sysinfo { diff --git a/include/system.h b/include/system.h index deb97b5023..230141fffe 100644 --- a/include/system.h +++ b/include/system.h @@ -64,6 +64,19 @@ void system_common_pre_init(void); int system_is_manual_recovery(void); /** + * Set a flag indicating system is in recovery mode. + */ +void system_enter_manual_recovery(void); + +/** + * Set a flag indicating system left recovery mode. + * + * WARNING: This flag should be cleared right after a shutdown from recovery + * boot. You most likely shouldn't call this elsewhere. + */ +void system_exit_manual_recovery(void); + +/** * Make sure AP shutdown completely, before call system_hibernate */ void system_enter_hibernate(uint32_t seconds, uint32_t microseconds); |