summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHsuan Ting Chen <roccochen@chromium.org>2020-08-31 14:04:57 +0800
committerCommit Bot <commit-bot@chromium.org>2020-09-21 04:08:18 +0000
commit07cd40854b31ad018657a173d4ff422d575a1f8f (patch)
tree0d25824de1d34ab7fce126b05409aa234a5e1d5a
parent4e5ce4293a724bce9e1fa36c5e305bdbc85946bd (diff)
downloadvboot-07cd40854b31ad018657a173d4ff422d575a1f8f.tar.gz
firmware/2lib: Handle errors in alternate boot
Handle three different errors in alternate boot: - VB2_UI_ERROR_ALTERNATE_BOOT_DISABLED - VB2_UI_ERROR_NO_BOOTLOADER - VB2_UI_ERROR_ALTERNATE_BOOT_FAILED BUG=b:146399181, b:161092974 TEST=make clean && make runtests BRANCH=puff, zork Cq-Depend: chromium:2384995 Signed-off-by: Hsuan Ting Chen <roccochen@chromium.org> Change-Id: I1e6572ed4a1c756d6d3727818439de25cad03158 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2382998 Tested-by: Shelley Chen <shchen@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-by: Shelley Chen <shchen@chromium.org>
-rw-r--r--firmware/2lib/2ui_screens.c29
-rw-r--r--firmware/2lib/include/2api.h6
2 files changed, 30 insertions, 5 deletions
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index 3e7ead2a..a398aa45 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -892,15 +892,28 @@ static const struct vb2_screen_info developer_invalid_disk_screen = {
/******************************************************************************/
/* VB2_SCREEN_DEVELOPER_SELECT_BOOTLOADER */
-const struct vb2_menu_item developer_select_bootloader_items_before[] = {
+static const struct vb2_menu_item developer_select_bootloader_items_before[] = {
LANGUAGE_SELECT_ITEM,
};
-const struct vb2_menu_item developer_select_bootloader_items_after[] = {
+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 (get_menu(ui)->num_items == 0) {
+ ui->error_beep = 1;
+ ui->error_code = VB2_UI_ERROR_NO_BOOTLOADER;
+ return vb2_ui_screen_back(ui);
+ }
+ /* Select the first bootloader. */
+ ui->state->selected_item =
+ ARRAY_SIZE(developer_select_bootloader_items_before);
+ return VB2_REQUEST_UI_CONTINUE;
+}
+
vb2_error_t vb2_ui_developer_mode_boot_alternate_action(
struct vb2_ui_context *ui)
{
@@ -913,12 +926,14 @@ vb2_error_t vb2_ui_developer_mode_boot_alternate_action(
!vb2_dev_boot_legacy_allowed(ui->ctx)) {
VB2_DEBUG("ERROR: Dev mode alternate bootloader not allowed\n");
ui->error_beep = 1;
+ ui->error_code = VB2_UI_ERROR_ALTERNATE_BOOT_DISABLED;
return VB2_REQUEST_UI_CONTINUE;
}
if (vb2ex_get_bootloader_count() == 0) {
- VB2_DEBUG("ERROR: No bootloader was found\n");
+ VB2_DEBUG("ERROR: No alternate bootloader was found\n");
ui->error_beep = 1;
+ ui->error_code = VB2_UI_ERROR_NO_BOOTLOADER;
return VB2_REQUEST_UI_CONTINUE;
}
@@ -934,8 +949,8 @@ vb2_error_t vb2_ui_developer_mode_boot_alternate_action(
VbExLegacy(altfw_num);
VB2_DEBUG("ERROR: Alternate bootloader failed\n");
- /* TODO(b/161092974): Leverage the error dialog on error. */
ui->error_beep = 1;
+ ui->error_code = VB2_UI_ERROR_ALTERNATE_BOOT_FAILED;
return VB2_REQUEST_UI_CONTINUE;
}
@@ -952,8 +967,11 @@ static const struct vb2_menu *get_bootloader_menu(struct vb2_ui_context *ui)
if (ui->bootloader_menu.num_items > 0)
return &ui->bootloader_menu;
- /* TODO(b/161092974): Show error dialog if no bootloader. */
num_bootloaders = vb2ex_get_bootloader_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));
@@ -988,6 +1006,7 @@ static const struct vb2_menu *get_bootloader_menu(struct vb2_ui_context *ui)
static const struct vb2_screen_info developer_select_bootloader_screen = {
.id = VB2_SCREEN_DEVELOPER_SELECT_BOOTLOADER,
.name = "Select alternate bootloader",
+ .init = developer_select_bootloader_init,
.get_menu = get_bootloader_menu,
};
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index 9f4dbcb9..323b91c9 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -1340,6 +1340,12 @@ enum vb2_ui_error {
VB2_UI_ERROR_FIRMWARE_LOG,
/* Untrusted confirmation */
VB2_UI_ERROR_UNTRUSTED_CONFIRMATION,
+ /* Alternate bootloader is disabled */
+ VB2_UI_ERROR_ALTERNATE_BOOT_DISABLED,
+ /* No bootloader was found */
+ VB2_UI_ERROR_NO_BOOTLOADER,
+ /* Alternate bootloader failed */
+ VB2_UI_ERROR_ALTERNATE_BOOT_FAILED,
/* Diagnostics internal failure */
VB2_UI_ERROR_DIAGNOSTICS,
};