diff options
Diffstat (limited to 'firmware/2lib/2ui_screens.c')
-rw-r--r-- | firmware/2lib/2ui_screens.c | 369 |
1 files changed, 0 insertions, 369 deletions
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, |