summaryrefslogtreecommitdiff
path: root/firmware/lib/vboot_ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/lib/vboot_ui.c')
-rw-r--r--firmware/lib/vboot_ui.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index 5934d0c1..af8450da 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -28,11 +28,15 @@
#include "vboot_ui_common.h"
/* Global variables */
-static int power_button_released;
+enum {
+ POWER_BUTTON_HELD_SINCE_BOOT = 0,
+ POWER_BUTTON_RELEASED,
+ POWER_BUTTON_PRESSED, /* must have been previously released */
+} power_button_state;
-static void vb2_init_ui(void)
+void vb2_init_ui(void)
{
- power_button_released = 0;
+ power_button_state = POWER_BUTTON_HELD_SINCE_BOOT;
}
static void VbAllowUsbBoot(struct vb2_context *ctx)
@@ -58,13 +62,17 @@ static int VbWantShutdown(struct vb2_context *ctx, uint32_t key)
/*
* Ignore power button push until after we have seen it released.
* This avoids shutting down immediately if the power button is still
- * being held on startup.
+ * being held on startup. After we've recognized a valid power button
+ * push then don't report the event until after the button is released.
*/
if (shutdown_request & VB_SHUTDOWN_REQUEST_POWER_BUTTON) {
- if (!power_button_released)
- shutdown_request &= ~VB_SHUTDOWN_REQUEST_POWER_BUTTON;
+ shutdown_request &= ~VB_SHUTDOWN_REQUEST_POWER_BUTTON;
+ if (power_button_state == POWER_BUTTON_RELEASED)
+ power_button_state = POWER_BUTTON_PRESSED;
} else {
- power_button_released = 1;
+ if (power_button_state == POWER_BUTTON_PRESSED)
+ shutdown_request |= VB_SHUTDOWN_REQUEST_POWER_BUTTON;
+ power_button_state = POWER_BUTTON_RELEASED;
}
if (key == VB_BUTTON_POWER_SHORT_PRESS)
@@ -107,15 +115,15 @@ int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags)
uint32_t key;
uint32_t key_flags;
uint32_t btn;
- int rec_button_was_pressed = 0;
+ int phys_presence_button_was_pressed = 0;
+ int shutdown_requested = 0;
VB2_DEBUG("Entering(%x)\n", confirm_flags);
/* Await further instructions */
- while (1) {
+ do {
key = VbExKeyboardReadWithFlags(&key_flags);
- if (VbWantShutdown(ctx, key))
- return -1;
+ shutdown_requested = VbWantShutdown(ctx, key);
switch (key) {
case VB_KEY_ENTER:
/* If we require a trusted keyboard for confirmation,
@@ -145,26 +153,28 @@ int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags)
return 0;
break;
default:
- /* If the recovery button is physical, and is pressed,
- * this is also a YES, but must wait for release.
+ /* If the physical presence button is physical, and is
+ * pressed, this is also a YES, but must wait for
+ * release.
*/
btn = VbExGetSwitches(
- VB_SWITCH_FLAG_REC_BUTTON_PRESSED);
+ VB_SWITCH_FLAG_PHYS_PRESENCE_PRESSED);
if (!(shared->flags & VBSD_BOOT_REC_SWITCH_VIRTUAL)) {
if (btn) {
- VB2_DEBUG("Rec button pressed\n");
- rec_button_was_pressed = 1;
- } else if (rec_button_was_pressed) {
- VB2_DEBUG("Rec button (1)\n");
+ VB2_DEBUG("Presence button pressed, "
+ "awaiting release\n");
+ phys_presence_button_was_pressed = 1;
+ } else if (phys_presence_button_was_pressed) {
+ VB2_DEBUG("Presence button released "
+ "(1)\n");
return 1;
}
}
VbCheckDisplayKey(ctx, key, NULL);
}
VbExSleepMs(CONFIRM_KEY_DELAY);
- }
+ } while (!shutdown_requested);
- /* Not reached, but compiler will complain without it */
return -1;
}
@@ -898,9 +908,9 @@ static VbError_t recovery_ui(struct vb2_context *ctx)
if (!(shared->flags &
VBSD_BOOT_REC_SWITCH_VIRTUAL) &&
VbExGetSwitches(
- VB_SWITCH_FLAG_REC_BUTTON_PRESSED)) {
+ VB_SWITCH_FLAG_PHYS_PRESENCE_PRESSED)) {
/*
- * Is the recovery button stuck? In
+ * Is the presence button stuck? In
* any case we don't like this. Beep
* and ignore.
*/
@@ -959,7 +969,6 @@ static VbError_t recovery_ui(struct vb2_context *ctx)
VbError_t VbBootRecovery(struct vb2_context *ctx)
{
- vb2_init_ui();
VbError_t retval = recovery_ui(ctx);
VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL);
return retval;