From af26dc17173d82c75821cf5385054a3b3b17165d Mon Sep 17 00:00:00 2001 From: Mathew King Date: Tue, 19 Feb 2019 10:43:32 -0700 Subject: vboot: Don't hardcode special keyboard values. BUG=chromium:933391 TEST=make runtests Test ctrl+d, ctrl+u, and ctrl+l on device BRANCH=none Change-Id: Icf8699e5facac44a074cfd47e796b9957fd6b714 Reviewed-on: https://chromium-review.googlesource.com/1475781 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Mathew King Reviewed-by: Julius Werner Reviewed-by: Mathew King --- firmware/include/vboot_api.h | 4 ++++ firmware/lib/vboot_ui.c | 12 ++++++------ firmware/lib/vboot_ui_menu.c | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'firmware') diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h index 904e5a20..0d3addff 100644 --- a/firmware/include/vboot_api.h +++ b/firmware/include/vboot_api.h @@ -717,8 +717,12 @@ VbError_t VbExDisplayDebugInfo(const char *info_str); /*****************************************************************************/ /* Keyboard and switches */ +/* Key code for CTRL + letter */ +#define VB_KEY_CTRL(letter) (letter & 0x1f) + /* Key codes for required non-printable-ASCII characters. */ enum VbKeyCode_t { + VB_KEY_ENTER = '\r', VB_KEY_ESC = 0x1b, VB_KEY_UP = 0x100, VB_KEY_DOWN = 0x101, diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c index a866e10b..57e546a2 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -113,7 +113,7 @@ int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags) if (VbWantShutdown(ctx, key)) return -1; switch (key) { - case '\r': + case VB_KEY_ENTER: /* If we require a trusted keyboard for confirmation, * but the keyboard may be faked (for instance, a USB * device), beep and keep waiting. @@ -317,7 +317,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) case 0: /* nothing pressed */ break; - case '\r': + case VB_KEY_ENTER: /* Only disable virtual dev switch if allowed by GBB */ if (!(sd->gbb_flags & VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM)) @@ -375,14 +375,14 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) return VBERROR_LOAD_KERNEL_RECOVERY; } break; - case 0x04: + case VB_KEY_CTRL('D'): /* Ctrl+D = dismiss warning; advance to timeout */ VB2_DEBUG("VbBootDeveloper() - " "user pressed Ctrl+D; skip delay\n"); ctrl_d_pressed = 1; goto fallout; break; - case 0x0c: + case VB_KEY_CTRL('L'): VB2_DEBUG("VbBootDeveloper() - " "user pressed Ctrl+L; Try alt firmware\n"); if (allow_legacy) { @@ -400,7 +400,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) * The Ctrl-Enter is special for Lumpy test purpose; * fall through to Ctrl+U handler. */ - case 0x15: + case VB_KEY_CTRL('U'): /* Ctrl+U = try USB boot, or beep if failure */ VB2_DEBUG("VbBootDeveloper() - " "user pressed Ctrl+U; try USB\n"); @@ -557,7 +557,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx) * - not already in dev mode * - user forced recovery mode */ - if (key == 0x04 && + if (key == VB_KEY_CTRL('D') && shared->flags & VBSD_HONOR_VIRT_DEV_SWITCH && !(shared->flags & VBSD_BOOT_DEV_SWITCH_ON) && (shared->flags & VBSD_BOOT_REC_SWITCH_ON)) { diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c index c0246462..e269d237 100644 --- a/firmware/lib/vboot_ui_menu.c +++ b/firmware/lib/vboot_ui_menu.c @@ -463,7 +463,7 @@ static VbError_t vb2_handle_menu_input(struct vb2_context *ctx, vb2_draw_current_screen(ctx); break; case VB_BUTTON_POWER_SHORT_PRESS: - case '\r': + case VB_KEY_ENTER: /* Menuless screens shut down on power button press. */ if (!menus[current_menu].size) return VBERROR_SHUTDOWN_REQUESTED; @@ -753,16 +753,16 @@ static VbError_t vb2_developer_menu(struct vb2_context *ctx) switch (key) { case VB_BUTTON_VOL_DOWN_LONG_PRESS: - case 'D' & 0x1f: + case VB_KEY_CTRL('D'): /* Ctrl+D = boot from internal disk */ ret = boot_disk_action(ctx); break; - case 'L' & 0x1f: + case VB_KEY_CTRL('L'): /* Ctrl+L = boot alternative bootloader */ ret = enter_altfw_menu(ctx); break; case VB_BUTTON_VOL_UP_LONG_PRESS: - case 'U' & 0x1f: + case VB_KEY_CTRL('U'): /* Ctrl+U = boot from USB or SD card */ ret = boot_usb_action(ctx); break; -- cgit v1.2.1