diff options
author | Mathew King <mathewk@chromium.org> | 2019-02-11 10:27:59 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-22 18:23:43 -0800 |
commit | 9d6dc0d222418f90f5080f6c25cd06ca14abf48b (patch) | |
tree | 77c8aa1f55543be4ac6da3b96f38d111e276d3e0 /firmware/lib | |
parent | af26dc17173d82c75821cf5385054a3b3b17165d (diff) | |
download | vboot-9d6dc0d222418f90f5080f6c25cd06ca14abf48b.tar.gz |
vboot: Add ui for setting vendor data in VPDfirmware-atlas-11827.12.B
BUG=b:124297157
TEST=make runtest
test on device
BRANCH=none
CQ-DEPEND=CL:1466822
Change-Id: Ic3b1b502b1aff14a795397da3024f8a12eb04775
Reviewed-on: https://chromium-review.googlesource.com/1466290
Commit-Ready: Mathew King <mathewk@chromium.org>
Tested-by: Mathew King <mathewk@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Mathew King <mathewk@chromium.org>
Diffstat (limited to 'firmware/lib')
-rw-r--r-- | firmware/lib/ec_sync_all.c | 2 | ||||
-rw-r--r-- | firmware/lib/include/sysincludes.h | 1 | ||||
-rw-r--r-- | firmware/lib/include/vboot_display.h | 3 | ||||
-rw-r--r-- | firmware/lib/vboot_api_kernel.c | 3 | ||||
-rw-r--r-- | firmware/lib/vboot_display.c | 10 | ||||
-rw-r--r-- | firmware/lib/vboot_ui.c | 207 | ||||
-rw-r--r-- | firmware/lib/vboot_ui_menu.c | 6 |
7 files changed, 208 insertions, 24 deletions
diff --git a/firmware/lib/ec_sync_all.c b/firmware/lib/ec_sync_all.c index 36d9e727..6c3fe74f 100644 --- a/firmware/lib/ec_sync_all.c +++ b/firmware/lib/ec_sync_all.c @@ -79,7 +79,7 @@ VbError_t ec_sync_all(struct vb2_context *ctx) /* Display the wait screen if we need it */ if (need_wait_screen) { VB2_DEBUG("EC is slow. Show WAIT screen.\n"); - VbDisplayScreen(ctx, VB_SCREEN_WAIT, 0); + VbDisplayScreen(ctx, VB_SCREEN_WAIT, 0, NULL); } /* Phase 2; Applies update and/or jumps to the correct EC image */ diff --git a/firmware/lib/include/sysincludes.h b/firmware/lib/include/sysincludes.h index 7a9139c0..28aa96c5 100644 --- a/firmware/lib/include/sysincludes.h +++ b/firmware/lib/include/sysincludes.h @@ -15,6 +15,7 @@ #ifndef VBOOT_REFERENCE_SYSINCLUDES_H_ #define VBOOT_REFERENCE_SYSINCLUDES_H_ +#include <ctype.h> #include <inttypes.h> /* For PRIu64 */ #include <stddef.h> #include <stdint.h> diff --git a/firmware/lib/include/vboot_display.h b/firmware/lib/include/vboot_display.h index 20066dfa..4c8df0e6 100644 --- a/firmware/lib/include/vboot_display.h +++ b/firmware/lib/include/vboot_display.h @@ -10,7 +10,8 @@ struct vb2_context; -VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force); +VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force, + const VbScreenData *data); VbError_t VbDisplayMenu(struct vb2_context *ctx, uint32_t screen, int force, uint32_t selected_index, uint32_t disabled_idx_mask); diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index 516b1e44..17b3b7b2 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -432,6 +432,9 @@ VbError_t VbSelectAndLoadKernel(VbCommonParams *cparams, retval = VbBootRecovery(&ctx); VbExEcEnteringMode(0, VB_EC_RECOVERY); } else if (ctx.flags & VB2_CONTEXT_DEVELOPER_MODE) { + if (kparams->inflags & VB_SALK_INFLAGS_VENDOR_DATA_SETTABLE) + ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; + /* Developer boot. This has UI. */ if (kparams->inflags & VB_SALK_INFLAGS_ENABLE_DETACHABLE_UI) retval = VbBootDeveloperMenu(&ctx); diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c index c7607726..a17d6dd1 100644 --- a/firmware/lib/vboot_display.c +++ b/firmware/lib/vboot_display.c @@ -35,7 +35,8 @@ VbError_t VbExGetAltFwIdxMask(void) { return 0; } -VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force) +VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force, + const VbScreenData *data) { uint32_t locale; VbError_t rv; @@ -47,7 +48,7 @@ VbError_t VbDisplayScreen(struct vb2_context *ctx, uint32_t screen, int force) /* Read the locale last saved */ locale = vb2_nv_get(ctx, VB2_NV_LOCALIZATION_INDEX); - rv = VbExDisplayScreen(screen, locale); + rv = VbExDisplayScreen(screen, locale, data); if (rv == VBERROR_SUCCESS) /* Keep track of the currently displayed screen */ @@ -464,12 +465,13 @@ VbError_t VbCheckDisplayKey(struct vb2_context *ctx, uint32_t key) #endif /* Force redraw of current screen */ - return VbDisplayScreen(ctx, disp_current_screen, 1); + return VbDisplayScreen(ctx, disp_current_screen, 1, NULL); } if (0 == memcmp(MagicBuffer, MAGIC_WORD, MAGIC_WORD_LEN)) { if (VBEASTEREGG) - (void)VbDisplayScreen(ctx, disp_current_screen, 1); + (void)VbDisplayScreen(ctx, disp_current_screen, 1, + NULL); } return VBERROR_SUCCESS; diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c index 57e546a2..dea6e039 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -176,7 +176,7 @@ VbError_t vb2_altfw_ui(struct vb2_context *ctx) { int active = 1; - VbDisplayScreen(ctx, VB_SCREEN_ALT_FW_PICK, 0); + VbDisplayScreen(ctx, VB_SCREEN_ALT_FW_PICK, 0, NULL); /* We'll loop until the user decides what to do */ do { @@ -217,11 +217,152 @@ VbError_t vb2_altfw_ui(struct vb2_context *ctx) } while (active); /* Back to developer screen */ - VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_WARNING, 0); + VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_WARNING, 0, NULL); return 0; } +/* + * Prompt the user to enter the vendor data + */ +VbError_t vb2_enter_vendor_data_ui(struct vb2_context *ctx, char *data_value) +{ + int len = 0; + VbScreenData data = { + .vendor_data = { data_value } + }; + + data_value[0] = '\0'; + VbDisplayScreen(ctx, VB_SCREEN_SET_VENDOR_DATA, 1, &data); + + /* We'll loop until the user decides what to do */ + do { + uint32_t key = VbExKeyboardRead(); + + if (VbWantShutdown(ctx, key)) { + VB2_DEBUG("Vendor Data UI - shutdown requested!\n"); + return VBERROR_SHUTDOWN_REQUESTED; + } + switch (key) { + case 0: + /* nothing pressed */ + break; + case VB_KEY_ESC: + /* Escape pressed - return to developer screen */ + VB2_DEBUG("Vendor Data UI - user pressed Esc: " + "exit to Developer screen\n"); + data_value[0] = '\0'; + return VBERROR_SUCCESS; + case 'a'...'z': + key = toupper(key); + case '0'...'9': + case 'A'...'Z': + if (len < VENDOR_DATA_LENGTH) { + data_value[len++] = key; + data_value[len] = '\0'; + VbDisplayScreen(ctx, VB_SCREEN_SET_VENDOR_DATA, + 1, &data); + } else { + vb2_error_beep(VB_BEEP_NOT_ALLOWED); + } + + VB2_DEBUG("Vendor Data UI - vendor_data: %s\n", + data_value); + break; + case VB_KEY_BACKSPACE: + if (len > 0) { + data_value[--len] = '\0'; + VbDisplayScreen(ctx, VB_SCREEN_SET_VENDOR_DATA, + 1, &data); + } + + VB2_DEBUG("Vendor Data UI - vendor_data: %s\n", + data_value); + break; + case VB_KEY_ENTER: + if (len == VENDOR_DATA_LENGTH) { + /* Enter pressed - confirm input */ + VB2_DEBUG("Vendor Data UI - user pressed " + "Enter: confirm vendor data\n"); + return VBERROR_SUCCESS; + } else { + vb2_error_beep(VB_BEEP_NOT_ALLOWED); + } + break; + default: + VB2_DEBUG("Vendor Data UI - pressed key %d\n", key); + break; + } + VbExSleepMs(DEV_KEY_DELAY); + } while (1); + + return VBERROR_SUCCESS; +} + +/* + * User interface for setting the vendor data in VPD + */ +VbError_t vb2_vendor_data_ui(struct vb2_context *ctx) +{ + char data_value[VENDOR_DATA_LENGTH + 1]; + VbScreenData data = { + .vendor_data = { data_value } + }; + + VbError_t ret = vb2_enter_vendor_data_ui(ctx, data_value); + + if (ret) + return ret; + + /* Vendor data was not entered just return */ + if (data_value[0] == '\0') + return VBERROR_SUCCESS; + + VbDisplayScreen(ctx, VB_SCREEN_CONFIRM_VENDOR_DATA, 1, &data); + /* We'll loop until the user decides what to do */ + do { + uint32_t key = VbExKeyboardRead(); + + if (VbWantShutdown(ctx, key)) { + VB2_DEBUG("Vendor Data UI - shutdown requested!\n"); + return VBERROR_SHUTDOWN_REQUESTED; + } + switch (key) { + case 0: + /* nothing pressed */ + break; + case VB_KEY_ESC: + /* Escape pressed - return to developer screen */ + VB2_DEBUG("Vendor Data UI - user pressed Esc: " + "exit to Developer screen\n"); + return VBERROR_SUCCESS; + case VB_KEY_ENTER: + /* Enter pressed - write vendor data */ + VB2_DEBUG("Vendor Data UI - user pressed Enter: " + "write vendor data (%s) to VPD\n", + data_value); + ret = VbExSetVendorData(data_value); + + if (ret == VBERROR_SUCCESS) { + vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1); + return VBERROR_REBOOT_REQUIRED; + } else { + /* + * TODO(mathewk): If setting vendor data fails + * we should give helpful feedback to the user + */ + return ret; + } + default: + VB2_DEBUG("Vendor Data UI - pressed key %d\n", key); + break; + } + VbExSleepMs(DEV_KEY_DELAY); + } while (1); + + return VBERROR_SUCCESS; +} + static const char dev_disable_msg[] = "Developer mode is disabled on this device by system policy.\n" "For more information, see http://dev.chromium.org/chromium-os/fwmp\n" @@ -279,7 +420,8 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) /* If dev mode is disabled, only allow TONORM */ while (disable_dev_boot) { VB2_DEBUG("dev_disable_boot is set\n"); - VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_TO_NORM, 0); + VbDisplayScreen(ctx, + VB_SCREEN_DEVELOPER_TO_NORM, 0, NULL); VbExDisplayDebugInfo(dev_disable_msg); /* Ignore space in VbUserConfirms()... */ @@ -287,7 +429,8 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) case 1: VB2_DEBUG("leaving dev-mode\n"); vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1); - VbDisplayScreen(ctx, VB_SCREEN_TO_NORM_CONFIRMED, 0); + VbDisplayScreen(ctx, + VB_SCREEN_TO_NORM_CONFIRMED, 0, NULL); VbExSleepMs(5000); return VBERROR_REBOOT_REQUIRED; case -1: @@ -300,7 +443,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) } /* Show the dev mode warning screen */ - VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_WARNING, 0); + VbDisplayScreen(ctx, VB_SCREEN_DEVELOPER_WARNING, 0, NULL); /* Initialize audio/delay context */ vb2_audio_start(ctx); @@ -342,7 +485,8 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) break; } VbDisplayScreen(ctx, - VB_SCREEN_DEVELOPER_TO_NORM, 0); + VB_SCREEN_DEVELOPER_TO_NORM, + 0, NULL); /* Ignore space in VbUserConfirms()... */ switch (VbUserConfirms(ctx, 0)) { case 1: @@ -350,7 +494,8 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1); VbDisplayScreen(ctx, - VB_SCREEN_TO_NORM_CONFIRMED, 0); + VB_SCREEN_TO_NORM_CONFIRMED, + 0, NULL); VbExSleepMs(5000); return VBERROR_REBOOT_REQUIRED; case -1: @@ -360,7 +505,8 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) /* Stay in dev-mode */ VB2_DEBUG("stay in dev-mode\n"); VbDisplayScreen(ctx, - VB_SCREEN_DEVELOPER_WARNING, 0); + VB_SCREEN_DEVELOPER_WARNING, + 0, NULL); /* Start new countdown */ vb2_audio_start(ctx); } @@ -395,6 +541,35 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) vb2_error_no_altfw(); } break; + case VB_KEY_CTRL('S'): + if (VENDOR_DATA_LENGTH == 0) + break; + /* + * Only show the vendor data ui if it is tag is settable + */ + if (ctx->flags & VB2_CONTEXT_VENDOR_DATA_SETTABLE) { + int ret; + + VB2_DEBUG("VbBootDeveloper() - user pressed " + "Ctrl+S; Try set vendor data\n"); + + ret = vb2_vendor_data_ui(ctx); + if (ret) { + return ret; + } else { + /* Show dev mode warning screen again */ + VbDisplayScreen(ctx, + VB_SCREEN_DEVELOPER_WARNING, + 0, NULL); + } + } else { + vb2_error_notify( + "WARNING: Vendor data cannot be " + "changed because it is already set.\n", + NULL, + VB_BEEP_NOT_ALLOWED); + } + break; case VB_KEY_CTRL_ENTER: /* * The Ctrl-Enter is special for Lumpy test purpose; @@ -418,13 +593,14 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) * Clear the screen to show we get the Ctrl+U * key press. */ - VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0); + VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL); if (VBERROR_SUCCESS == VbTryUsb(ctx)) { return VBERROR_SUCCESS; } else { /* Show dev mode warning screen again */ VbDisplayScreen(ctx, - VB_SCREEN_DEVELOPER_WARNING, 0); + VB_SCREEN_DEVELOPER_WARNING, + 0, NULL); } } break; @@ -467,7 +643,7 @@ VbError_t VbBootDeveloper(struct vb2_context *ctx) { vb2_init_ui(); VbError_t retval = vb2_developer_ui(ctx); - VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0); + VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL); return retval; } @@ -509,7 +685,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx) */ vb2_nv_commit(ctx); - VbDisplayScreen(ctx, VB_SCREEN_OS_BROKEN, 0); + VbDisplayScreen(ctx, VB_SCREEN_OS_BROKEN, 0, NULL); VB2_DEBUG("VbBootRecovery() waiting for manual recovery\n"); while (1) { key = VbExKeyboardRead(); @@ -541,7 +717,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx) VbDisplayScreen(ctx, VBERROR_NO_DISK_FOUND == retval ? VB_SCREEN_RECOVERY_INSERT : VB_SCREEN_RECOVERY_NO_GOOD, - 0); + 0, NULL); /* * Scan keyboard more frequently than media, since x86 @@ -578,7 +754,8 @@ static VbError_t recovery_ui(struct vb2_context *ctx) /* Ask the user to confirm entering dev-mode */ VbDisplayScreen(ctx, - VB_SCREEN_RECOVERY_TO_DEV, 0); + VB_SCREEN_RECOVERY_TO_DEV, + 0, NULL); /* SPACE means no... */ uint32_t vbc_flags = VB_CONFIRM_SPACE_MEANS_NO | @@ -622,6 +799,6 @@ VbError_t VbBootRecovery(struct vb2_context *ctx) { vb2_init_ui(); VbError_t retval = recovery_ui(ctx); - VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0); + VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL); return retval; } diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c index e269d237..380dd3ed 100644 --- a/firmware/lib/vboot_ui_menu.c +++ b/firmware/lib/vboot_ui_menu.c @@ -71,7 +71,7 @@ static VbError_t vb2_draw_current_screen(struct vb2_context *ctx) { /* Flash the screen to black to catch user awareness, then redraw menu. */ static void vb2_flash_screen(struct vb2_context *ctx) { - VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0); + VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL); VbExSleepMs(50); vb2_draw_current_screen(ctx); } @@ -808,7 +808,7 @@ VbError_t VbBootDeveloperMenu(struct vb2_context *ctx) if (VBERROR_SUCCESS != retval) return retval; retval = vb2_developer_menu(ctx); - VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0); + VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL); return retval; } @@ -913,6 +913,6 @@ VbError_t VbBootRecoveryMenu(struct vb2_context *ctx) retval = recovery_ui(ctx); else retval = broken_ui(ctx); - VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0); + VbDisplayScreen(ctx, VB_SCREEN_BLANK, 0, NULL); return retval; } |