summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authoredisonhello <edisonhello@google.com>2021-08-31 16:48:29 +0800
committerCommit Bot <commit-bot@chromium.org>2021-09-14 08:03:14 +0000
commit0d72f07a52e25c53ce4529345994401c835eb9e2 (patch)
treec2c941245a07ad39db2f93f8bac2ecc5c7089de3 /firmware
parent50fa4408ada6b891ce77de2879ea0bd7f875787f (diff)
downloadvboot-0d72f07a52e25c53ce4529345994401c835eb9e2.tar.gz
vboot/ui: Remove developer menu and related tests
This CL is a part of centralizing ui codes. The removed screens and unit tests will be added in depthcharge. Remove developer menu and its action function. Remove developer mode, developer to norm, developer boot external, developer invalid disk, developer select altfw screens. Remove unit tests for above screens and menu. BUG=b:172339016 TEST=export CC=x86_64-pc-linux-gnu-clang DEBUG=1 DETACHABLE=0; \ make -j test_setup && make -j runtests TEST=export CC=x86_64-pc-linux-gnu-clang DEBUG=1 DETACHABLE=1; \ make -j test_setup && make -j runtests BRANCH=none Cq-Depend: chromium:3132550 Signed-off-by: edisonhello <edisonhello@google.com> Change-Id: I45332f8e059eba612231362cc56a70da1336c7c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3132504 Reviewed-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'firmware')
-rw-r--r--firmware/2lib/2stub.c6
-rw-r--r--firmware/2lib/2ui.c37
-rw-r--r--firmware/2lib/2ui_screens.c369
-rw-r--r--firmware/2lib/include/2api.h14
-rw-r--r--firmware/2lib/include/2ui.h14
-rw-r--r--firmware/lib/vboot_api_kernel.c2
6 files changed, 21 insertions, 421 deletions
diff --git a/firmware/2lib/2stub.c b/firmware/2lib/2stub.c
index 368915b1..181fa496 100644
--- a/firmware/2lib/2stub.c
+++ b/firmware/2lib/2stub.c
@@ -268,3 +268,9 @@ vb2_error_t vb2ex_manual_recovery_ui(struct vb2_context *ctx)
{
return VB2_SUCCESS;
}
+
+__attribute__((weak))
+vb2_error_t vb2ex_developer_ui(struct vb2_context *ctx)
+{
+ return VB2_SUCCESS;
+}
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c
index db79eb72..ab0692bf 100644
--- a/firmware/2lib/2ui.c
+++ b/firmware/2lib/2ui.c
@@ -414,43 +414,6 @@ vb2_error_t vb2_ui_loop(struct vb2_context *ctx, enum vb2_screen root_screen_id,
}
/*****************************************************************************/
-/* Developer mode */
-
-vb2_error_t vb2_developer_menu(struct vb2_context *ctx)
-{
- enum vb2_screen root_screen_id = VB2_SCREEN_DEVELOPER_MODE;
- if (!(ctx->flags & VB2_CONTEXT_DEV_BOOT_ALLOWED)) {
- VB2_DEBUG("WARNING: Dev boot not allowed; forcing to-norm\n");
- root_screen_id = VB2_SCREEN_DEVELOPER_TO_NORM;
- }
- return vb2_ui_loop(ctx, root_screen_id, developer_action);
-}
-
-vb2_error_t developer_action(struct vb2_ui_context *ui)
-{
- /* Developer mode keyboard shortcuts */
- if (ui->key == '\t')
- return vb2_ui_screen_change(ui, VB2_SCREEN_DEBUG_INFO);
-
- /* Ignore other shortcuts */
- if (!(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALLOWED))
- return VB2_REQUEST_UI_CONTINUE;
-
- if (ui->key == VB_KEY_CTRL('S'))
- return vb2_ui_screen_change(ui, VB2_SCREEN_DEVELOPER_TO_NORM);
- if (ui->key == VB_KEY_CTRL('U') ||
- (DETACHABLE && ui->key == VB_BUTTON_VOL_UP_LONG_PRESS))
- return vb2_ui_developer_mode_boot_external_action(ui);
- if (ui->key == VB_KEY_CTRL('D') ||
- (DETACHABLE && ui->key == VB_BUTTON_VOL_DOWN_LONG_PRESS))
- return vb2_ui_developer_mode_boot_internal_action(ui);
- if (ui->key == VB_KEY_CTRL('L')) /* L for aLtfw (formerly Legacy) */
- return vb2_ui_developer_mode_boot_altfw_action(ui);
-
- return VB2_SUCCESS;
-}
-
-/*****************************************************************************/
/* Diagnostics */
vb2_error_t vb2_diagnostic_menu(struct vb2_context *ctx)
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index 51e428a4..5e08b57d 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -515,370 +515,6 @@ static const struct vb2_screen_info recovery_to_dev_screen = {
};
/******************************************************************************/
-/* VB2_SCREEN_DEVELOPER_MODE */
-
-#define DEVELOPER_MODE_ITEM_RETURN_TO_SECURE 1
-#define DEVELOPER_MODE_ITEM_BOOT_INTERNAL 2
-#define DEVELOPER_MODE_ITEM_BOOT_EXTERNAL 3
-#define DEVELOPER_MODE_ITEM_SELECT_ALTFW 4
-
-vb2_error_t developer_mode_init(struct vb2_ui_context *ui)
-{
- enum vb2_dev_default_boot_target default_boot =
- vb2api_get_dev_default_boot_target(ui->ctx);
-
- /* Don't show "Return to secure mode" button if GBB forces dev mode. */
- if (vb2api_gbb_get_flags(ui->ctx) & VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON)
- 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 (!(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_EXTERNAL_ALLOWED))
- VB2_SET_BIT(ui->state->hidden_item_mask,
- DEVELOPER_MODE_ITEM_BOOT_EXTERNAL);
-
- /* Don't show "Select alternate bootloader" button if not allowed. */
- if (!(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALTFW_ALLOWED))
- VB2_SET_BIT(ui->state->hidden_item_mask,
- DEVELOPER_MODE_ITEM_SELECT_ALTFW);
-
- /* Choose the default selection. */
- switch (default_boot) {
- case VB2_DEV_DEFAULT_BOOT_TARGET_EXTERNAL:
- ui->state->selected_item = DEVELOPER_MODE_ITEM_BOOT_EXTERNAL;
- break;
- case VB2_DEV_DEFAULT_BOOT_TARGET_ALTFW:
- ui->state->selected_item =
- DEVELOPER_MODE_ITEM_SELECT_ALTFW;
- break;
- default:
- ui->state->selected_item = DEVELOPER_MODE_ITEM_BOOT_INTERNAL;
- break;
- }
-
- ui->start_time_ms = vb2ex_mtime();
-
- return VB2_SUCCESS;
-}
-
-vb2_error_t vb2_ui_developer_mode_boot_internal_action(
- struct vb2_ui_context *ui)
-{
- vb2_error_t rv;
-
- if (!(ui->ctx->flags & VB2_CONTEXT_DEVELOPER_MODE) ||
- !(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALLOWED)) {
- VB2_DEBUG("ERROR: Dev mode internal boot not allowed\n");
- return VB2_SUCCESS;
- }
-
- rv = VbTryLoadKernel(ui->ctx, VB_DISK_FLAG_FIXED);
- if (rv == VB2_SUCCESS)
- return VB2_REQUEST_UI_EXIT;
-
- VB2_DEBUG("ERROR: Failed to boot from internal disk: %#x\n", rv);
- ui->error_beep = 1;
- return set_ui_error(ui, VB2_UI_ERROR_INTERNAL_BOOT_FAILED);
-}
-
-vb2_error_t vb2_ui_developer_mode_boot_external_action(
- struct vb2_ui_context *ui)
-{
- vb2_error_t rv;
-
- /* Validity check, should never happen. */
- if (!(ui->ctx->flags & VB2_CONTEXT_DEVELOPER_MODE) ||
- !(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALLOWED) ||
- !(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_EXTERNAL_ALLOWED)) {
- VB2_DEBUG("ERROR: Dev mode external boot not allowed\n");
- ui->error_beep = 1;
- return set_ui_error(ui, VB2_UI_ERROR_EXTERNAL_BOOT_DISABLED);
- }
-
- rv = VbTryLoadKernel(ui->ctx, VB_DISK_FLAG_REMOVABLE);
- if (rv == VB2_SUCCESS) {
- return VB2_REQUEST_UI_EXIT;
- } else if (rv == VB2_ERROR_LK_NO_DISK_FOUND) {
- if (ui->state->screen->id !=
- VB2_SCREEN_DEVELOPER_BOOT_EXTERNAL) {
- VB2_DEBUG("No external disk found\n");
- ui->error_beep = 1;
- }
- return vb2_ui_screen_change(
- ui, VB2_SCREEN_DEVELOPER_BOOT_EXTERNAL);
- } else {
- if (ui->state->screen->id !=
- VB2_SCREEN_DEVELOPER_INVALID_DISK) {
- VB2_DEBUG("Invalid external disk: %#x\n", rv);
- ui->error_beep = 1;
- }
- return vb2_ui_screen_change(
- ui, VB2_SCREEN_DEVELOPER_INVALID_DISK);
- }
-}
-
-vb2_error_t developer_mode_action(struct vb2_ui_context *ui)
-{
- const int use_short = vb2api_use_short_dev_screen_delay(ui->ctx);
- uint64_t elapsed_ms;
-
- /* Once any user interaction occurs, stop the timer. */
- if (ui->key)
- ui->disable_timer = 1;
- if (ui->disable_timer)
- return VB2_SUCCESS;
-
- elapsed_ms = vb2ex_mtime() - ui->start_time_ms;
-
- /* If we're using short delay, wait 2 seconds and don't beep. */
- if (use_short && elapsed_ms > DEV_DELAY_SHORT_MS) {
- VB2_DEBUG("Booting default target after 2s\n");
- ui->disable_timer = 1;
- return vb2_ui_menu_select(ui);
- }
-
- /* Otherwise, beep at 20 and 20.5 seconds. */
- if ((ui->beep_count == 0 && elapsed_ms > DEV_DELAY_BEEP1_MS) ||
- (ui->beep_count == 1 && elapsed_ms > DEV_DELAY_BEEP2_MS)) {
- vb2ex_beep(250, 400);
- ui->beep_count++;
- }
-
- /* Stop after 30 seconds. */
- if (elapsed_ms > DEV_DELAY_NORMAL_MS) {
- VB2_DEBUG("Booting default target after 30s\n");
- ui->disable_timer = 1;
- return vb2_ui_menu_select(ui);
- }
-
- return VB2_SUCCESS;
-}
-
-static const struct vb2_menu_item developer_mode_items[] = {
- LANGUAGE_SELECT_ITEM,
- [DEVELOPER_MODE_ITEM_RETURN_TO_SECURE] = {
- .text = "Return to secure mode",
- .target = VB2_SCREEN_DEVELOPER_TO_NORM,
- },
- [DEVELOPER_MODE_ITEM_BOOT_INTERNAL] = {
- .text = "Boot from internal disk",
- .action = vb2_ui_developer_mode_boot_internal_action,
- },
- [DEVELOPER_MODE_ITEM_BOOT_EXTERNAL] = {
- .text = "Boot from external disk",
- .action = vb2_ui_developer_mode_boot_external_action,
- },
- [DEVELOPER_MODE_ITEM_SELECT_ALTFW] = {
- .text = "Select alternate bootloader",
- .target = VB2_SCREEN_DEVELOPER_SELECT_ALTFW,
- },
- ADVANCED_OPTIONS_ITEM,
- POWER_OFF_ITEM,
-};
-
-static const struct vb2_screen_info developer_mode_screen = {
- .id = VB2_SCREEN_DEVELOPER_MODE,
- .name = "Developer mode",
- .init = developer_mode_init,
- .action = developer_mode_action,
- .menu = MENU_ITEMS(developer_mode_items),
-};
-
-/******************************************************************************/
-/* VB2_SCREEN_DEVELOPER_TO_NORM */
-
-#define DEVELOPER_TO_NORM_ITEM_CONFIRM 1
-#define DEVELOPER_TO_NORM_ITEM_CANCEL 2
-
-static vb2_error_t developer_to_norm_init(struct vb2_ui_context *ui)
-{
- /* Don't allow to-norm if GBB forces dev mode */
- if (vb2api_gbb_get_flags(ui->ctx) & VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON) {
- VB2_DEBUG("ERROR: to-norm not allowed\n");
- return set_ui_error_and_go_back(
- ui, VB2_UI_ERROR_TO_NORM_NOT_ALLOWED);
- }
- ui->state->selected_item = DEVELOPER_TO_NORM_ITEM_CONFIRM;
- /* Hide "Cancel" button if dev boot is not allowed */
- if (!(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALLOWED))
- VB2_SET_BIT(ui->state->hidden_item_mask,
- DEVELOPER_TO_NORM_ITEM_CANCEL);
- return VB2_SUCCESS;
-}
-
-vb2_error_t developer_to_norm_action(struct vb2_ui_context *ui)
-{
- if (vb2api_disable_developer_mode(ui->ctx) == VB2_SUCCESS)
- return VB2_REQUEST_REBOOT;
- else
- return VB2_SUCCESS;
-}
-
-static const struct vb2_menu_item developer_to_norm_items[] = {
- LANGUAGE_SELECT_ITEM,
- [DEVELOPER_TO_NORM_ITEM_CONFIRM] = {
- .text = "Confirm",
- .action = developer_to_norm_action,
- },
- [DEVELOPER_TO_NORM_ITEM_CANCEL] = {
- .text = "Cancel",
- .action = vb2_ui_screen_back,
- },
- POWER_OFF_ITEM,
-};
-
-static const struct vb2_screen_info developer_to_norm_screen = {
- .id = VB2_SCREEN_DEVELOPER_TO_NORM,
- .name = "Transition to normal mode",
- .init = developer_to_norm_init,
- .menu = MENU_ITEMS(developer_to_norm_items),
-};
-
-/******************************************************************************/
-/* VB2_SCREEN_DEVELOPER_BOOT_EXTERNAL */
-
-static const struct vb2_menu_item developer_boot_external_items[] = {
- LANGUAGE_SELECT_ITEM,
- BACK_ITEM,
- POWER_OFF_ITEM,
-};
-
-static const struct vb2_screen_info developer_boot_external_screen = {
- .id = VB2_SCREEN_DEVELOPER_BOOT_EXTERNAL,
- .name = "Developer boot from external disk",
- .action = vb2_ui_developer_mode_boot_external_action,
- .menu = MENU_ITEMS(developer_boot_external_items),
-};
-
-/******************************************************************************/
-/* VB2_SCREEN_DEVELOPER_INVALID_DISK */
-
-static const struct vb2_menu_item developer_invalid_disk_items[] = {
- LANGUAGE_SELECT_ITEM,
- BACK_ITEM,
- POWER_OFF_ITEM,
-};
-
-static const struct vb2_screen_info developer_invalid_disk_screen = {
- .id = VB2_SCREEN_DEVELOPER_INVALID_DISK,
- .name = "Invalid external disk in dev mode",
- .action = vb2_ui_developer_mode_boot_external_action,
- .menu = MENU_ITEMS(developer_invalid_disk_items),
-};
-
-/******************************************************************************/
-/* VB2_SCREEN_DEVELOPER_SELECT_ALTFW */
-
-static const struct vb2_menu_item developer_select_bootloader_items_before[] = {
- LANGUAGE_SELECT_ITEM,
-};
-
-static const struct vb2_menu_item developer_select_bootloader_items_after[] = {
- BACK_ITEM,
- POWER_OFF_ITEM,
-};
-
-static vb2_error_t developer_select_bootloader_init(struct vb2_ui_context *ui)
-{
- if (vb2_get_menu(ui)->num_items == 0)
- return set_ui_error_and_go_back(ui, VB2_UI_ERROR_ALTFW_EMPTY);
- /* Select the first bootloader. */
- ui->state->selected_item =
- ARRAY_SIZE(developer_select_bootloader_items_before);
- return VB2_SUCCESS;
-}
-
-vb2_error_t vb2_ui_developer_mode_boot_altfw_action(
- struct vb2_ui_context *ui)
-{
- uint32_t altfw_id;
- const size_t menu_before_len =
- ARRAY_SIZE(developer_select_bootloader_items_before);
-
- if (!(ui->ctx->flags & VB2_CONTEXT_DEVELOPER_MODE) ||
- !(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALLOWED) ||
- !(ui->ctx->flags & VB2_CONTEXT_DEV_BOOT_ALTFW_ALLOWED)) {
- VB2_DEBUG("ERROR: Dev mode alternate bootloader not allowed\n");
- return set_ui_error(ui, VB2_UI_ERROR_ALTFW_DISABLED);
- }
-
- if (vb2ex_get_altfw_count() == 0) {
- VB2_DEBUG("ERROR: No alternate bootloader was found\n");
- return set_ui_error(ui, VB2_UI_ERROR_ALTFW_EMPTY);
- }
-
- if (ui->key == VB_KEY_CTRL('L')) {
- altfw_id = 0;
- VB2_DEBUG("Try booting from default bootloader\n");
- } else {
- altfw_id = ui->state->selected_item - menu_before_len + 1;
- VB2_DEBUG("Try booting from bootloader #%u\n", altfw_id);
- }
-
- /* vb2ex_run_altfw will not return if successful */
- vb2ex_run_altfw(altfw_id);
-
- VB2_DEBUG("ERROR: Alternate bootloader failed\n");
- return set_ui_error(ui, VB2_UI_ERROR_ALTFW_FAILED);
-}
-
-static const struct vb2_menu *get_bootloader_menu(struct vb2_ui_context *ui)
-{
- int i;
- uint32_t num_bootloaders, num_items;
- struct vb2_menu_item *items;
- const size_t menu_before_len =
- ARRAY_SIZE(developer_select_bootloader_items_before);
- const size_t menu_after_len =
- ARRAY_SIZE(developer_select_bootloader_items_after);
-
- if (ui->bootloader_menu.num_items > 0)
- return &ui->bootloader_menu;
-
- num_bootloaders = vb2ex_get_altfw_count();
- if (num_bootloaders == 0) {
- VB2_DEBUG("ERROR: No bootloader was found\n");
- return NULL;
- }
- VB2_DEBUG("num_bootloaders: %u\n", num_bootloaders);
- num_items = num_bootloaders + menu_before_len + menu_after_len;
- items = malloc(num_items * sizeof(struct vb2_menu_item));
- if (!items) {
- VB2_DEBUG("ERROR: malloc failed for bootloader items\n");
- return NULL;
- }
-
- /* Copy prefix items to the begin. */
- memcpy(&items[0],
- developer_select_bootloader_items_before,
- menu_before_len * sizeof(struct vb2_menu_item));
-
- /* Copy bootloaders. */
- for (i = 0; i < num_bootloaders; i++) {
- items[i + menu_before_len].text = "Some bootloader";
- items[i + menu_before_len].action =
- vb2_ui_developer_mode_boot_altfw_action;
- }
-
- /* Copy postfix items to the end. */
- memcpy(&items[num_items - menu_after_len],
- developer_select_bootloader_items_after,
- menu_after_len * sizeof(struct vb2_menu_item));
-
- ui->bootloader_menu.num_items = num_items;
- ui->bootloader_menu.items = items;
-
- return &ui->bootloader_menu;
-}
-
-static const struct vb2_screen_info developer_select_bootloader_screen = {
- .id = VB2_SCREEN_DEVELOPER_SELECT_ALTFW,
- .name = "Select alternate bootloader",
- .init = developer_select_bootloader_init,
- .get_menu = get_bootloader_menu,
-};
-
-/******************************************************************************/
/* VB2_SCREEN_DIAGNOSTICS */
#define DIAGNOSTICS_ITEM_STORAGE_HEALTH 1
@@ -1218,11 +854,6 @@ static const struct vb2_screen_info *screens[] = {
&debug_info_screen,
&firmware_log_screen,
&recovery_to_dev_screen,
- &developer_mode_screen,
- &developer_to_norm_screen,
- &developer_boot_external_screen,
- &developer_invalid_disk_screen,
- &developer_select_bootloader_screen,
&diagnostics_screen,
&diagnostics_storage_health_screen,
&diagnostics_storage_test_short_screen,
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index df8c8d1a..a1cda6a1 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -1416,6 +1416,20 @@ vb2_error_t vb2ex_broken_screen_ui(struct vb2_context *ctx);
*/
vb2_error_t vb2ex_manual_recovery_ui(struct vb2_context *ctx);
+/**
+ * UI for a developer-mode boot.
+ *
+ * Enter the developer menu, which provides options to switch out of developer
+ * mode, boot from external media, use legacy bootloader, or boot Chrome OS from
+ * disk.
+ *
+ * If a timeout occurs, take the default boot action.
+ *
+ * @param ctx Vboot context
+ * @return VB2_SUCCESS, or non-zero error code.
+ */
+vb2_error_t vb2ex_developer_ui(struct vb2_context *ctx);
+
/* 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)))
diff --git a/firmware/2lib/include/2ui.h b/firmware/2lib/include/2ui.h
index 2ed65e9d..0fb18513 100644
--- a/firmware/2lib/include/2ui.h
+++ b/firmware/2lib/include/2ui.h
@@ -232,20 +232,6 @@ vb2_error_t vb2_ui_screen_change(struct vb2_ui_context *ui, enum vb2_screen id);
/* UI loops */
/**
- * UI for a developer-mode boot.
- *
- * Enter the developer menu, which provides options to switch out of developer
- * mode, boot from external media, use legacy bootloader, or boot Chrome OS from
- * disk.
- *
- * If a timeout occurs, take the default boot action.
- *
- * @param ctx Vboot context
- * @return VB2_SUCCESS, or non-zero error code.
- */
-vb2_error_t vb2_developer_menu(struct vb2_context *ctx);
-
-/**
* UI for a diagnostic tools boot.
*
* Enter the diagnostic tools menu, which provides debug information and
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 9978097d..10728b95 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -217,7 +217,7 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx,
return VB2_REQUEST_REBOOT;
} else if (ctx->flags & VB2_CONTEXT_DEVELOPER_MODE) {
/* Developer boot. This has UI. */
- VB2_TRY(vb2_developer_menu(ctx));
+ VB2_TRY(vb2ex_developer_ui(ctx));
} else {
/* Normal boot */
VB2_TRY(vb2_normal_boot(ctx));