diff options
author | Hsuan Ting Chen <roccochen@chromium.org> | 2020-09-24 12:06:06 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-14 05:58:49 +0000 |
commit | 519c608d2464b5b45b7bfe432a27eae119777971 (patch) | |
tree | 9f6053cb0e9b7457c564e7a197cf451958e599ea /firmware/2lib | |
parent | 4e93a487ff99c80777ee80f183193e07bc58c41d (diff) | |
download | vboot-519c608d2464b5b45b7bfe432a27eae119777971.tar.gz |
vboot/ui: Split disabled_item_mask into two masks for log screen
Add three macros in 2api.h for bitmask operations:
- VB2_SET_BIT(mask, index)
- VB2_CLR_BIT(mask, index)
- VB2_GET_BIT(mask, index)
These macros will be used in corresponding depthcharge CLs.
Split disabled_item_mask into:
- disabled_item_mask: Disabled style, but still visible and selectable.
- hidden_item_mask: Not visible.
Ignore selecting on disabled menu items.
Set appropriate disabled_item_mask for page up/down buttons in log
screen.
Revise tests of hidden_item_mask and add unit tests of disabled_item_mask.
BUG=b:163301076, b:146399181
BRANCH=none
TEST=CC=x86_64-pc-linux-gnu-clang;
make clean && make runtests
TEST=CC=x86_64-pc-linux-gnu-clang; DETACHABLE=1;
make clean && make runtests
TEST=CC=x86_64-pc-linux-gnu-clang; PHYSICAL_PRESENCE_KEYBOARD=1;
make clean && make runtests
TEST=CC=x86_64-pc-linux-gnu-clang; DIAGNOSTIC_UI=1;
make clean && make runtests
TEST=Build locally, navigate to debug info screen with <TAB>,
select page up or page down, and observe that nothing happens.
Cq-Depend: chromium:2432168
Signed-off-by: Hsuan Ting Chen <roccochen@chromium.org>
Change-Id: I1607af53f6e2b5c1cde568cb24606314051d2380
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2426154
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
Diffstat (limited to 'firmware/2lib')
-rw-r--r-- | firmware/2lib/2ui.c | 14 | ||||
-rw-r--r-- | firmware/2lib/2ui_screens.c | 185 | ||||
-rw-r--r-- | firmware/2lib/include/2api.h | 12 | ||||
-rw-r--r-- | firmware/2lib/include/2ui.h | 16 |
4 files changed, 141 insertions, 86 deletions
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c index 44edc4a8..5b1e3394 100644 --- a/firmware/2lib/2ui.c +++ b/firmware/2lib/2ui.c @@ -144,8 +144,7 @@ vb2_error_t vb2_ui_menu_prev(struct vb2_ui_context *ui) return VB2_REQUEST_UI_CONTINUE; item = ui->state->selected_item - 1; - while (item >= 0 && - ((1 << item) & ui->state->disabled_item_mask)) + while (item >= 0 && VB2_GET_BIT(ui->state->hidden_item_mask, item)) item--; /* Only update if item is valid */ if (item >= 0) @@ -165,7 +164,7 @@ vb2_error_t vb2_ui_menu_next(struct vb2_ui_context *ui) menu = get_menu(ui); item = ui->state->selected_item + 1; while (item < menu->num_items && - ((1 << item) & ui->state->disabled_item_mask)) + VB2_GET_BIT(ui->state->hidden_item_mask, item)) item++; /* Only update if item is valid */ if (item < menu->num_items) @@ -188,6 +187,14 @@ vb2_error_t vb2_ui_menu_select(struct vb2_ui_context *ui) menu_item = &menu->items[ui->state->selected_item]; + /* Cannot select a disabled menu item */ + if (VB2_GET_BIT(ui->state->disabled_item_mask, + ui->state->selected_item)) { + VB2_DEBUG("Menu item <%s> disabled; ignoring\n", + menu_item->text); + return VB2_REQUEST_UI_CONTINUE; + } + if (menu_item->action) { VB2_DEBUG("Menu item <%s> run action\n", menu_item->text); return menu_item->action(ui); @@ -331,6 +338,7 @@ vb2_error_t ui_loop(struct vb2_context *ctx, enum vb2_screen root_screen_id, vb2ex_display_ui(ui.state->screen->id, ui.locale_id, ui.state->selected_item, ui.state->disabled_item_mask, + ui.state->hidden_item_mask, ui.disable_timer, ui.state->current_page, ui.error_code); diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c index aaf7daf7..29a10625 100644 --- a/firmware/2lib/2ui_screens.c +++ b/firmware/2lib/2ui_screens.c @@ -52,50 +52,92 @@ static vb2_error_t power_off_action(struct vb2_ui_context *ui) }) /******************************************************************************/ -/* Functions used for log screens */ /* - * TODO(b/163301076): Reconsider the functionalities of page up/down buttons - * when reaching the start/end of the log. + * Functions used for log screens + * + * Expects that the page_count is valid and page_up_item and page_down_item are + * assigned to correct menu item indices in all three functions, the + * current_page is valid in prev and next actions, and the back_item is assigned + * to a correct menu item index. */ -static vb2_error_t log_page_init(struct vb2_ui_context *ui, - uint32_t page_down_item, - uint32_t alternate_item) +static vb2_error_t log_page_init(struct vb2_ui_context *ui) { + const struct vb2_screen_info *screen = ui->state->screen; + ui->state->current_page = 0; - if (ui->state->page_count == 1) - ui->state->selected_item = alternate_item; - else - ui->state->selected_item = page_down_item; + if (ui->state->page_count == 1) { + VB2_SET_BIT(ui->state->disabled_item_mask, + screen->page_up_item); + VB2_SET_BIT(ui->state->disabled_item_mask, + screen->page_down_item); + ui->state->selected_item = screen->back_item; + } else { + VB2_SET_BIT(ui->state->disabled_item_mask, + screen->page_up_item); + ui->state->selected_item = screen->page_down_item; + } return VB2_REQUEST_UI_CONTINUE; } static vb2_error_t log_page_prev_action(struct vb2_ui_context *ui) { - if (ui->state->current_page == 0) { - VB2_DEBUG("WARNING: Ignore page up on the first page\n"); - ui->error_beep = 1; + const struct vb2_screen_info *screen = ui->state->screen; + + /* Validity check. */ + if (ui->state->current_page == 0) return VB2_REQUEST_UI_CONTINUE; - } + ui->state->current_page--; + /* Clear bits of page down. */ + if (ui->state->current_page != ui->state->page_count - 1) + VB2_CLR_BIT(ui->state->disabled_item_mask, + screen->page_down_item); + + /* Disable page up at the first page. */ + if (ui->state->current_page == 0) + VB2_SET_BIT(ui->state->disabled_item_mask, + screen->page_up_item); + return VB2_REQUEST_UI_CONTINUE; } static vb2_error_t log_page_next_action(struct vb2_ui_context *ui) { - if (ui->state->current_page == ui->state->page_count - 1) { - VB2_DEBUG("WARNING: Ignore page down on the last page\n"); - ui->error_beep = 1; + const struct vb2_screen_info *screen = ui->state->screen; + + /* Validity check. */ + if (ui->state->current_page == ui->state->page_count - 1) return VB2_REQUEST_UI_CONTINUE; - } + ui->state->current_page++; + /* Clear bits of page up. */ + if (ui->state->current_page != 0) + VB2_CLR_BIT(ui->state->disabled_item_mask, + screen->page_up_item); + + /* Disable page down at the last page. */ + if (ui->state->current_page == ui->state->page_count - 1) + VB2_SET_BIT(ui->state->disabled_item_mask, + screen->page_down_item); + return VB2_REQUEST_UI_CONTINUE; } +#define PAGE_UP_ITEM ((struct vb2_menu_item){ \ + .text = "Page up", \ + .action = log_page_prev_action, \ +}) + +#define PAGE_DOWN_ITEM ((struct vb2_menu_item){ \ + .text = "Page down", \ + .action = log_page_next_action, \ +}) + /******************************************************************************/ /* VB2_SCREEN_BLANK */ @@ -207,8 +249,8 @@ vb2_error_t advanced_options_init(struct vb2_ui_context *ui) ui->state->selected_item = ADVANCED_OPTIONS_ITEM_DEVELOPER_MODE; if (vb2_get_sd(ui->ctx)->flags & VB2_SD_FLAG_DEV_MODE_ENABLED || !vb2_allow_recovery(ui->ctx)) { - ui->state->disabled_item_mask |= - 1 << ADVANCED_OPTIONS_ITEM_DEVELOPER_MODE; + VB2_SET_BIT(ui->state->hidden_item_mask, + ADVANCED_OPTIONS_ITEM_DEVELOPER_MODE); ui->state->selected_item = ADVANCED_OPTIONS_ITEM_DEBUG_INFO; } @@ -243,6 +285,7 @@ static const struct vb2_screen_info advanced_options_screen = { /******************************************************************************/ /* VB2_SCREEN_DEBUG_INFO */ +#define DEBUG_INFO_ITEM_PAGE_UP 1 #define DEBUG_INFO_ITEM_PAGE_DOWN 2 #define DEBUG_INFO_ITEM_BACK 3 @@ -261,9 +304,7 @@ static vb2_error_t debug_info_init(struct vb2_ui_context *ui) return vb2_ui_screen_back(ui); } - return log_page_init(ui, - DEBUG_INFO_ITEM_PAGE_DOWN, - DEBUG_INFO_ITEM_BACK); + return log_page_init(ui); } static vb2_error_t debug_info_reinit(struct vb2_ui_context *ui) @@ -286,14 +327,8 @@ static vb2_error_t debug_info_reinit(struct vb2_ui_context *ui) static const struct vb2_menu_item debug_info_items[] = { LANGUAGE_SELECT_ITEM, - { - .text = "Page up", - .action = log_page_prev_action, - }, - [DEBUG_INFO_ITEM_PAGE_DOWN] = { - .text = "Page down", - .action = log_page_next_action, - }, + [DEBUG_INFO_ITEM_PAGE_UP] = PAGE_UP_ITEM, + [DEBUG_INFO_ITEM_PAGE_DOWN] = PAGE_DOWN_ITEM, [DEBUG_INFO_ITEM_BACK] = BACK_ITEM, POWER_OFF_ITEM, }; @@ -304,11 +339,15 @@ static const struct vb2_screen_info debug_info_screen = { .init = debug_info_init, .reinit = debug_info_reinit, .menu = MENU_ITEMS(debug_info_items), + .page_up_item = DEBUG_INFO_ITEM_PAGE_UP, + .page_down_item = DEBUG_INFO_ITEM_PAGE_DOWN, + .back_item = DEBUG_INFO_ITEM_BACK, }; /******************************************************************************/ /* VB2_SCREEN_FIRMWARE_LOG */ +#define FIRMWARE_LOG_ITEM_PAGE_UP 1 #define FIRMWARE_LOG_ITEM_PAGE_DOWN 2 #define FIRMWARE_LOG_ITEM_BACK 3 @@ -327,9 +366,7 @@ static vb2_error_t firmware_log_init(struct vb2_ui_context *ui) return vb2_ui_screen_back(ui); } - return log_page_init(ui, - FIRMWARE_LOG_ITEM_PAGE_DOWN, - FIRMWARE_LOG_ITEM_BACK); + return log_page_init(ui); } static vb2_error_t firmware_log_reinit(struct vb2_ui_context *ui) @@ -352,14 +389,8 @@ static vb2_error_t firmware_log_reinit(struct vb2_ui_context *ui) static const struct vb2_menu_item firmware_log_items[] = { LANGUAGE_SELECT_ITEM, - { - .text = "Page up", - .action = log_page_prev_action, - }, - [FIRMWARE_LOG_ITEM_PAGE_DOWN] = { - .text = "Page down", - .action = log_page_next_action, - }, + [FIRMWARE_LOG_ITEM_PAGE_UP] = PAGE_UP_ITEM, + [FIRMWARE_LOG_ITEM_PAGE_DOWN] = PAGE_DOWN_ITEM, [FIRMWARE_LOG_ITEM_BACK] = BACK_ITEM, POWER_OFF_ITEM, }; @@ -370,6 +401,9 @@ static const struct vb2_screen_info firmware_log_screen = { .init = firmware_log_init, .reinit = firmware_log_reinit, .menu = MENU_ITEMS(firmware_log_items), + .page_up_item = FIRMWARE_LOG_ITEM_PAGE_UP, + .page_down_item = FIRMWARE_LOG_ITEM_PAGE_DOWN, + .back_item = FIRMWARE_LOG_ITEM_BACK, }; /******************************************************************************/ @@ -392,14 +426,14 @@ vb2_error_t recovery_select_init(struct vb2_ui_context *ui) ui->state->selected_item = RECOVERY_SELECT_ITEM_PHONE; if (!vb2api_phone_recovery_ui_enabled(ui->ctx)) { VB2_DEBUG("WARNING: Phone recovery not available\n"); - ui->state->disabled_item_mask |= - 1 << RECOVERY_SELECT_ITEM_PHONE; + VB2_SET_BIT(ui->state->hidden_item_mask, + RECOVERY_SELECT_ITEM_PHONE); ui->state->selected_item = RECOVERY_SELECT_ITEM_EXTERNAL_DISK; } - if (!DIAGNOSTIC_UI || !vb2api_diagnostic_ui_enabled(ui->ctx)) - ui->state->disabled_item_mask |= - 1 << RECOVERY_SELECT_ITEM_DIAGNOSTICS; + if (!DIAGNOSTIC_UI || !vb2api_diagnostic_ui_enabled(ui->ctx)) + VB2_SET_BIT(ui->state->hidden_item_mask, + RECOVERY_SELECT_ITEM_DIAGNOSTICS); return VB2_REQUEST_UI_CONTINUE; } @@ -466,8 +500,8 @@ vb2_error_t recovery_to_dev_init(struct vb2_ui_context *ui) /* Disable "Confirm" button for other physical presence types. */ if (!PHYSICAL_PRESENCE_KEYBOARD) { - ui->state->disabled_item_mask |= - 1 << RECOVERY_TO_DEV_ITEM_CONFIRM; + VB2_SET_BIT(ui->state->hidden_item_mask, + RECOVERY_TO_DEV_ITEM_CONFIRM); ui->state->selected_item = RECOVERY_TO_DEV_ITEM_CANCEL; } @@ -655,18 +689,18 @@ vb2_error_t developer_mode_init(struct vb2_ui_context *ui) /* Don't show "Return to secure mode" button if GBB forces dev mode. */ if (vb2_get_gbb(ui->ctx)->flags & VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON) - ui->state->disabled_item_mask |= - 1 << DEVELOPER_MODE_ITEM_RETURN_TO_SECURE; + VB2_SET_BIT(ui->state->hidden_item_mask, + DEVELOPER_MODE_ITEM_RETURN_TO_SECURE); /* Don't show "Boot from external disk" button if not allowed. */ if (!vb2_dev_boot_external_allowed(ui->ctx)) - ui->state->disabled_item_mask |= - 1 << DEVELOPER_MODE_ITEM_BOOT_EXTERNAL; + VB2_SET_BIT(ui->state->hidden_item_mask, + DEVELOPER_MODE_ITEM_BOOT_EXTERNAL); /* Don't show "Select alternate bootloader" button if not allowed. */ if (!vb2_dev_boot_legacy_allowed(ui->ctx)) - ui->state->disabled_item_mask |= - 1 << DEVELOPER_MODE_ITEM_SELECT_BOOTLOADER; + VB2_SET_BIT(ui->state->hidden_item_mask, + DEVELOPER_MODE_ITEM_SELECT_BOOTLOADER); /* Choose the default selection. */ switch (default_boot) { @@ -1035,6 +1069,7 @@ static const struct vb2_screen_info diagnostics_screen = { /******************************************************************************/ /* VB2_SCREEN_DIAGNOSTICS_STORAGE */ +#define DIAGNOSTICS_STORAGE_ITEM_PAGE_UP 0 #define DIAGNOSTICS_STORAGE_ITEM_PAGE_DOWN 1 #define DIAGNOSTICS_STORAGE_ITEM_BACK 2 @@ -1053,19 +1088,12 @@ static vb2_error_t diagnostics_storage_init(struct vb2_ui_context *ui) ui->error_code = VB2_UI_ERROR_DIAGNOSTICS; return vb2_ui_screen_back(ui); } - return log_page_init(ui, DIAGNOSTICS_STORAGE_ITEM_PAGE_DOWN, - DIAGNOSTICS_STORAGE_ITEM_BACK); + return log_page_init(ui); } static const struct vb2_menu_item diagnostics_storage_items[] = { - { - .text = "Page up", - .action = log_page_prev_action, - }, - [DIAGNOSTICS_STORAGE_ITEM_PAGE_DOWN] = { - .text = "Page down", - .action = log_page_next_action, - }, + [DIAGNOSTICS_STORAGE_ITEM_PAGE_UP] = PAGE_UP_ITEM, + [DIAGNOSTICS_STORAGE_ITEM_PAGE_DOWN] = PAGE_DOWN_ITEM, [DIAGNOSTICS_STORAGE_ITEM_BACK] = BACK_ITEM, POWER_OFF_ITEM, }; @@ -1075,12 +1103,16 @@ static const struct vb2_screen_info diagnostics_storage_screen = { .name = "Storage", .init = diagnostics_storage_init, .menu = MENU_ITEMS(diagnostics_storage_items), + .page_up_item = DIAGNOSTICS_STORAGE_ITEM_PAGE_UP, + .page_down_item = DIAGNOSTICS_STORAGE_ITEM_PAGE_DOWN, + .back_item = DIAGNOSTICS_STORAGE_ITEM_BACK, }; /******************************************************************************/ /* VB2_SCREEN_DIAGNOSTICS_MEMORY_QUICK VB2_SCREEN_DIAGNOSTICS_MEMORY_FULL */ +#define DIAGNOSTICS_MEMORY_ITEM_PAGE_UP 0 #define DIAGNOSTICS_MEMORY_ITEM_PAGE_DOWN 1 #define DIAGNOSTICS_MEMORY_ITEM_CANCEL 2 #define DIAGNOSTICS_MEMORY_ITEM_BACK 3 @@ -1112,17 +1144,18 @@ static vb2_error_t diagnostics_memory_update_screen(struct vb2_ui_context *ui, /* Show cancel button when the test is running, otherwise show the back * button. VB2_SUCCESS indicates the test is finished. */ - ui->state->disabled_item_mask &= ~(1 << DIAGNOSTICS_MEMORY_ITEM_CANCEL); - ui->state->disabled_item_mask &= ~(1 << DIAGNOSTICS_MEMORY_ITEM_BACK); + VB2_CLR_BIT(ui->state->hidden_item_mask, + DIAGNOSTICS_MEMORY_ITEM_CANCEL); + VB2_CLR_BIT(ui->state->hidden_item_mask, DIAGNOSTICS_MEMORY_ITEM_BACK); if (rv == VB2_ERROR_EX_DIAG_TEST_RUNNING) { - ui->state->disabled_item_mask |= - 1 << DIAGNOSTICS_MEMORY_ITEM_BACK; + VB2_SET_BIT(ui->state->hidden_item_mask, + DIAGNOSTICS_MEMORY_ITEM_BACK); if (ui->state->selected_item == DIAGNOSTICS_MEMORY_ITEM_BACK) ui->state->selected_item = DIAGNOSTICS_MEMORY_ITEM_CANCEL; } else { - ui->state->disabled_item_mask |= - 1 << DIAGNOSTICS_MEMORY_ITEM_CANCEL; + VB2_SET_BIT(ui->state->hidden_item_mask, + DIAGNOSTICS_MEMORY_ITEM_CANCEL); if (ui->state->selected_item == DIAGNOSTICS_MEMORY_ITEM_CANCEL) ui->state->selected_item = DIAGNOSTICS_MEMORY_ITEM_BACK; } @@ -1155,14 +1188,8 @@ static vb2_error_t diagnostics_memory_update_full(struct vb2_ui_context *ui) } static const struct vb2_menu_item diagnostics_memory_items[] = { - { - .text = "Page up", - .action = log_page_prev_action, - }, - [DIAGNOSTICS_MEMORY_ITEM_PAGE_DOWN] = { - .text = "Page down", - .action = log_page_next_action, - }, + [DIAGNOSTICS_MEMORY_ITEM_PAGE_UP] = PAGE_UP_ITEM, + [DIAGNOSTICS_MEMORY_ITEM_PAGE_DOWN] = PAGE_DOWN_ITEM, [DIAGNOSTICS_MEMORY_ITEM_CANCEL] = { .text = "Cancel and go back", .action = vb2_ui_screen_back, diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h index 67b5074a..b4dfadf8 100644 --- a/firmware/2lib/include/2api.h +++ b/firmware/2lib/include/2api.h @@ -1293,6 +1293,11 @@ vb2_error_t vb2ex_ec_battery_cutoff(void); /*****************************************************************************/ /* Functions for UI display. */ +/* Helpers for bitmask operations */ +#define VB2_SET_BIT(mask, index) ((mask) |= ((uint32_t)1 << (index))) +#define VB2_CLR_BIT(mask, index) ((mask) &= ~((uint32_t)1 << (index))) +#define VB2_GET_BIT(mask, index) ((mask) & ((uint32_t)1 << (index))) + /* Screens. */ enum vb2_screen { /* Blank screen */ @@ -1375,6 +1380,12 @@ enum vb2_ui_error { * doesn't have a menu, this value will be ignored. * @param disabled_item_mask Mask for disabled menu items. Bit (1 << idx) * indicates whether item 'idx' is disabled. + * A disabled menu item is visible and selectable, + * with a different button style. + * @param hidden_item_mask Mask for hidden menu items. Bit (1 << idx) + * indicates whether item 'idx' is hidden. + * A hidden menu item is neither visible nor + * selectable. * @param timer_disabled Whether timer is disabled or not. Some screen * descriptions will depend on this value. * @param current_page Current page number for a log screen. If the @@ -1387,6 +1398,7 @@ vb2_error_t vb2ex_display_ui(enum vb2_screen screen, uint32_t locale_id, uint32_t selected_item, uint32_t disabled_item_mask, + uint32_t hidden_item_mask, int timer_disabled, uint32_t current_page, enum vb2_ui_error error_code); diff --git a/firmware/2lib/include/2ui.h b/firmware/2lib/include/2ui.h index 2fefaf32..d8c38470 100644 --- a/firmware/2lib/include/2ui.h +++ b/firmware/2lib/include/2ui.h @@ -59,12 +59,20 @@ struct vb2_screen_info { * will be ignored. */ const struct vb2_menu *(*get_menu)(struct vb2_ui_context *ui); + /* + * Indices of menu items; + * used by log_page_* functions in 2ui_screens.c. + */ + uint32_t page_up_item; + uint32_t page_down_item; + uint32_t back_item; }; struct vb2_screen_state { const struct vb2_screen_info *screen; uint32_t selected_item; uint32_t disabled_item_mask; + uint32_t hidden_item_mask; /* For log screen. */ uint32_t page_count; @@ -139,8 +147,8 @@ const struct vb2_screen_info *vb2_get_screen_info(enum vb2_screen id); /** * Move selection to the previous menu item. * - * Update selected_item, taking into account disabled indices (from - * disabled_item_mask). The selection does not wrap, meaning that we block + * Update selected_item, taking into account hidden indices (from + * hidden_item_mask). The selection does not wrap, meaning that we block * on 0 when we hit the start of the menu. * * @param ui UI context pointer @@ -151,8 +159,8 @@ vb2_error_t vb2_ui_menu_prev(struct vb2_ui_context *ui); /** * Move selection to the next menu item. * - * Update selected_item, taking into account disabled indices (from - * disabled_item_mask). The selection does not wrap, meaning that we block + * Update selected_item, taking into account hidden indices (from + * hidden_item_mask). The selection does not wrap, meaning that we block * on the max index when we hit the end of the menu. * * @param ui UI context pointer |