From 8f5432e1003b86e72b14bac60a66daa54bd26630 Mon Sep 17 00:00:00 2001 From: Pranay Shoroff Date: Mon, 13 Jan 2020 16:37:12 -0700 Subject: vboot_ui: refactor vendor data code Refactored wilco-specific functions related to setting serial numbers to their own file and diagnostic UI feature BUG=b:138812835 BRANCH=None TEST=emerge-drallion vboot_reference, flashed drallion and tested vendor data setting Related to chromium:1983248, chromium:1926508, chrome-internal:2180149 Change-Id: I02b2a62943ea60af007b6fc084b74e990062f3c3 Signed-off-by: Pranay Shoroff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1999050 Reviewed-by: Mathew King Reviewed-by: Joel Kitching Tested-by: Mathew King --- firmware/lib/vboot_ui_common.c | 53 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'firmware/lib/vboot_ui_common.c') diff --git a/firmware/lib/vboot_ui_common.c b/firmware/lib/vboot_ui_common.c index 49e20fd4..65f3b368 100644 --- a/firmware/lib/vboot_ui_common.c +++ b/firmware/lib/vboot_ui_common.c @@ -6,12 +6,23 @@ */ #include "2common.h" +#include "2misc.h" #include "2sysincludes.h" #include "vboot_api.h" #include "vboot_kernel.h" +#include "vboot_test.h" #include "vboot_ui_common.h" -/* One or two beeps to notify that attempted action was disallowed. */ +static enum { + POWER_BUTTON_HELD_SINCE_BOOT = 0, + POWER_BUTTON_RELEASED, + POWER_BUTTON_PRESSED, /* Must have been previously released */ +} power_button_state; + +void vb2_reset_power_button(void) { + power_button_state = POWER_BUTTON_HELD_SINCE_BOOT; +} + void vb2_error_beep(enum vb2_beep_type beep) { switch (beep) { @@ -49,15 +60,6 @@ void vb2_error_no_altfw(void) vb2_error_beep(VB_BEEP_NOT_ALLOWED); } -/** - * Run alternative firmware - * - * This will only return if vboot data fails to commit, secdata_kernel fails to - * lock, or the bootloader cannot be found / fails to start. - * - * @param ctx Context pointer - * @param altfw_num Number of bootloader to start (0=any, 1=first, etc.) - */ void vb2_try_altfw(struct vb2_context *ctx, int allowed, enum VbAltFwIndex_t altfw_num) { @@ -78,3 +80,34 @@ void vb2_try_altfw(struct vb2_context *ctx, int allowed, vb2_error_notify("Legacy boot failed. Missing BIOS?\n", NULL, VB_BEEP_FAILED); } + +int vb2_want_shutdown(struct vb2_context *ctx, uint32_t key) +{ + struct vb2_gbb_header *gbb = vb2_get_gbb(ctx); + uint32_t shutdown_request = VbExIsShutdownRequested(); + + /* + * 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. 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) { + shutdown_request &= ~VB_SHUTDOWN_REQUEST_POWER_BUTTON; + if (power_button_state == POWER_BUTTON_RELEASED) + power_button_state = POWER_BUTTON_PRESSED; + } else { + 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) + shutdown_request |= VB_SHUTDOWN_REQUEST_POWER_BUTTON; + + /* If desired, ignore shutdown request due to lid closure. */ + if (gbb->flags & VB2_GBB_FLAG_DISABLE_LID_SHUTDOWN) + shutdown_request &= ~VB_SHUTDOWN_REQUEST_LID_CLOSED; + + return shutdown_request; +} -- cgit v1.2.1