summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-10-15 06:55:06 -0600
committerMartin Roth <martinroth@chromium.org>2018-10-23 22:34:00 +0000
commit71d798dce54e34ba836e7187e7d526396dce52e0 (patch)
tree96c864e95d8dd030ec78ae12c02319a8536d940a
parent3f67b7c5a13df1bec3062e9cfe1d35679df6b2c1 (diff)
downloadvboot-71d798dce54e34ba836e7187e7d526396dce52e0.tar.gz
Move developer menu code higher in the file
We want to reuse this code for the altfw feature. Move it up in the file to permit this without needing forward declarations. BUG=chromium:837018 BRANCH=none TEST=FEATURES=test emerge-grunt --nodeps vboot_reference Change-Id: I02e6cdfb1ea7d5b48e272a778976cdaf50378235 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1286217 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/1297019 Reviewed-by: Martin Roth <martinroth@chromium.org> Tested-by: Martin Roth <martinroth@chromium.org>
-rw-r--r--firmware/lib/vboot_ui_menu.c187
1 files changed, 94 insertions, 93 deletions
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index 3a9d9e52..eb75be2b 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -362,6 +362,100 @@ static VbError_t power_off_action(struct vb2_context *ctx)
return VBERROR_SHUTDOWN_REQUESTED;
}
+/**
+ * Updates current_menu_idx upon an up/down key press, taking into
+ * account disabled indices (from disabled_idx_mask). The cursor
+ * will not wrap, meaning that we block on the 0 or max index when
+ * we hit the ends of the menu.
+ *
+ * @param key VOL_KEY_UP = increase index selection
+ * VOL_KEY_DOWN = decrease index selection.
+ * Every other key has no effect now.
+ */
+static void vb2_update_selection(uint32_t key) {
+ int idx;
+
+ switch (key) {
+ case VB_BUTTON_VOL_UP_SHORT_PRESS:
+ case VB_KEY_UP:
+ idx = current_menu_idx - 1;
+ while (idx >= 0 &&
+ ((1 << idx) & disabled_idx_mask))
+ idx--;
+ /* Only update if idx is valid */
+ if (idx >= 0)
+ current_menu_idx = idx;
+ break;
+ case VB_BUTTON_VOL_DOWN_SHORT_PRESS:
+ case VB_KEY_DOWN:
+ idx = current_menu_idx + 1;
+ while (idx < menus[current_menu].size &&
+ ((1 << idx) & disabled_idx_mask))
+ idx++;
+ /* Only update if idx is valid */
+ if (idx < menus[current_menu].size)
+ current_menu_idx = idx;
+ break;
+ default:
+ VB2_DEBUG("ERROR: %s called with key 0x%x!\n", __func__, key);
+ break;
+ }
+}
+
+static VbError_t vb2_handle_menu_input(struct vb2_context *ctx,
+ uint32_t key, uint32_t key_flags)
+{
+ switch (key) {
+ case 0:
+ /* nothing pressed */
+ break;
+ case '\t':
+ /* Tab = display debug info */
+ return debug_info_action(ctx);
+ case VB_KEY_UP:
+ case VB_KEY_DOWN:
+ case VB_BUTTON_VOL_UP_SHORT_PRESS:
+ case VB_BUTTON_VOL_DOWN_SHORT_PRESS:
+ /* Untrusted (USB keyboard) input disabled for TO_DEV menu. */
+ if (current_menu == VB_MENU_TO_DEV &&
+ !(key_flags & VB_KEY_FLAG_TRUSTED_KEYBOARD)) {
+ vb2_flash_screen(ctx);
+ vb2_error_beep();
+ break;
+ }
+
+ /* Menuless screens enter OPTIONS on volume button press. */
+ if (!menus[current_menu].size) {
+ enter_options_menu(ctx);
+ break;
+ }
+
+ vb2_update_selection(key);
+ vb2_draw_current_screen(ctx);
+ break;
+ case VB_BUTTON_POWER_SHORT_PRESS:
+ case '\r':
+ /* Menuless screens shut down on power button press. */
+ if (!menus[current_menu].size)
+ return VBERROR_SHUTDOWN_REQUESTED;
+
+ return menus[current_menu].items[current_menu_idx].action(ctx);
+ default:
+ VB2_DEBUG("pressed key 0x%x\n", key);
+ break;
+ }
+
+ if (VbWantShutdownMenu(ctx)) {
+ VB2_DEBUG("shutdown requested!\n");
+ return VBERROR_SHUTDOWN_REQUESTED;
+ }
+
+ return VBERROR_KEEP_LOOPING;
+}
+
+/* Delay in developer menu */
+#define DEV_KEY_DELAY 20 /* Check keys every 20ms */
+
/* Master table of all menus. Menus with size == 0 count as menuless screens. */
static struct vb2_menu menus[VB_MENU_COUNT] = {
[VB_MENU_DEV_WARNING] = {
@@ -543,99 +637,6 @@ static VbError_t vb2_init_menus(struct vb2_context *ctx)
}
/**
- * Updates current_menu_idx upon an up/down key press, taking into
- * account disabled indices (from disabled_idx_mask). The cursor
- * will not wrap, meaning that we block on the 0 or max index when
- * we hit the ends of the menu.
- *
- * @param key VOL_KEY_UP = increase index selection
- * VOL_KEY_DOWN = decrease index selection.
- * Every other key has no effect now.
- */
-static void vb2_update_selection(uint32_t key) {
- int idx;
-
- switch (key) {
- case VB_BUTTON_VOL_UP_SHORT_PRESS:
- case VB_KEY_UP:
- idx = current_menu_idx - 1;
- while (idx >= 0 &&
- ((1 << idx) & disabled_idx_mask))
- idx--;
- /* Only update if idx is valid */
- if (idx >= 0)
- current_menu_idx = idx;
- break;
- case VB_BUTTON_VOL_DOWN_SHORT_PRESS:
- case VB_KEY_DOWN:
- idx = current_menu_idx + 1;
- while (idx < menus[current_menu].size &&
- ((1 << idx) & disabled_idx_mask))
- idx++;
- /* Only update if idx is valid */
- if (idx < menus[current_menu].size)
- current_menu_idx = idx;
- break;
- default:
- VB2_DEBUG("ERROR: %s called with key 0x%x!\n", __func__, key);
- break;
- }
-}
-
-static VbError_t vb2_handle_menu_input(struct vb2_context *ctx,
- uint32_t key, uint32_t key_flags)
-{
- switch (key) {
- case 0:
- /* nothing pressed */
- break;
- case '\t':
- /* Tab = display debug info */
- return debug_info_action(ctx);
- case VB_KEY_UP:
- case VB_KEY_DOWN:
- case VB_BUTTON_VOL_UP_SHORT_PRESS:
- case VB_BUTTON_VOL_DOWN_SHORT_PRESS:
- /* Untrusted (USB keyboard) input disabled for TO_DEV menu. */
- if (current_menu == VB_MENU_TO_DEV &&
- !(key_flags & VB_KEY_FLAG_TRUSTED_KEYBOARD)) {
- vb2_flash_screen(ctx);
- vb2_error_beep();
- break;
- }
-
- /* Menuless screens enter OPTIONS on volume button press. */
- if (!menus[current_menu].size) {
- enter_options_menu(ctx);
- break;
- }
-
- vb2_update_selection(key);
- vb2_draw_current_screen(ctx);
- break;
- case VB_BUTTON_POWER_SHORT_PRESS:
- case '\r':
- /* Menuless screens shut down on power button press. */
- if (!menus[current_menu].size)
- return VBERROR_SHUTDOWN_REQUESTED;
-
- return menus[current_menu].items[current_menu_idx].action(ctx);
- default:
- VB2_DEBUG("pressed key 0x%x\n", key);
- break;
- }
-
- if (VbWantShutdownMenu(ctx)) {
- VB2_DEBUG("shutdown requested!\n");
- return VBERROR_SHUTDOWN_REQUESTED;
- }
-
- return VBERROR_KEEP_LOOPING;
-}
-
-/* Delay in developer menu */
-#define DEV_KEY_DELAY 20 /* Check keys every 20ms */
-/**
* Main function that handles developer warning menu functionality
*
* @param ctx Vboot2 context