diff options
author | Simon Glass <sjg@chromium.org> | 2018-04-08 23:26:57 -0400 |
---|---|---|
committer | Martin Roth <martinroth@chromium.org> | 2018-10-11 18:30:34 +0000 |
commit | 61511927b9b2415fba167b2ec3a7a7d6d746b82c (patch) | |
tree | 9a344180af8fc5d2c310c4900aaa9e24d80b45d1 | |
parent | 5536c751eda9e729c95310443f81767c13fd125e (diff) | |
download | vboot-61511927b9b2415fba167b2ec3a7a7d6d746b82c.tar.gz |
Add support for booting into alternative boot loaders
Add a generic way of selecting an alternative bootloader to run from the
developer-mode menu. This enables keys 1-9 to select a particular numbered
bootloader.
Adjust VbExLegacy() to take a numeric parameter to signal which boot
loader to run.
CQ-DEPEND=CL:1228875
BUG=chromium:837018
BRANCH=none
TEST=FEATURES=test emerge-grunt --nodeps vboot_reference
Change-Id: I02eab1b87e21a6401ec42317c4c1fa1bd2767b53
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1060854
Reviewed-by: Julius Werner <jwerner@chromium.org>
(cherry picked from commit 89a517730f0207dbef9b3ff219d360904dca456e)
Reviewed-on: https://chromium-review.googlesource.com/c/1277325
Reviewed-by: Martin Roth <martinroth@chromium.org>
Tested-by: Martin Roth <martinroth@chromium.org>
-rw-r--r-- | firmware/include/vboot_api.h | 5 | ||||
-rw-r--r-- | firmware/lib/vboot_ui.c | 22 | ||||
-rw-r--r-- | firmware/lib/vboot_ui_menu.c | 2 | ||||
-rw-r--r-- | firmware/stub/vboot_api_stub.c | 2 | ||||
-rw-r--r-- | tests/vboot_api_kernel2_tests.c | 53 | ||||
-rw-r--r-- | tests/vboot_detach_menu_tests.c | 12 |
6 files changed, 87 insertions, 9 deletions
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h index 55c3d02a..254fb23d 100644 --- a/firmware/include/vboot_api.h +++ b/firmware/include/vboot_api.h @@ -955,8 +955,11 @@ enum { /** * Execute legacy boot option. + * + * @param altfw_num Bootloader sequence number to execute. Use + * 0 to boot the default payload, if any */ -int VbExLegacy(void); +int VbExLegacy(int altfw_num); /* Regions for VbExRegionRead() */ enum vb_firmware_region { diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c index 933092c2..d5e29281 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -72,14 +72,22 @@ static int VbWantShutdown(struct vb2_context *ctx, uint32_t key) return !!shutdown_request; } -static void VbTryLegacy(int allowed) +/** + * Call out to firmware to boot a numbered boot loader + * + * Provided that it is permitted, this function starts up the numbered boot + * loader. + * + * @param altfw_num Boot loader number to boot (0=any, 1=first, etc.) + */ +static void VbTryLegacy(int allowed, int altfw_num) { if (!allowed) VB2_DEBUG("VbBootDeveloper() - Legacy boot is disabled\n"); else if (0 != RollbackKernelLock(0)) VB2_DEBUG("Error locking kernel versions on legacy boot.\n"); else - VbExLegacy(); /* will not return if successful */ + VbExLegacy(altfw_num); /* will not return if successful */ /* If legacy boot fails, beep and return to calling UI loop. */ VbExBeep(120, 400); @@ -337,7 +345,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) case 0x0c: VB2_DEBUG("VbBootDeveloper() - " "user pressed Ctrl+L; Try legacy boot\n"); - VbTryLegacy(allow_legacy); + VbTryLegacy(allow_legacy, 0); break; case VB_KEY_CTRL_ENTER: @@ -375,6 +383,12 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) } } break; + case '1'...'9': + VB2_DEBUG("VbBootDeveloper() - " + "user pressed key '%c': Boot alternative " + "firmware\n", key); + VbTryLegacy(allow_legacy, key - '0'); + break; default: VB2_DEBUG("VbBootDeveloper() - pressed key %d\n", key); VbCheckDisplayKey(ctx, key); @@ -387,7 +401,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) /* If defaulting to legacy boot, try that unless Ctrl+D was pressed */ if (use_legacy && !ctrl_d_pressed) { VB2_DEBUG("VbBootDeveloper() - defaulting to legacy\n"); - VbTryLegacy(allow_legacy); + VbTryLegacy(allow_legacy, 0); } if ((use_usb && !ctrl_d_pressed) && allow_usb) { diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c index c050ec8e..daed42f0 100644 --- a/firmware/lib/vboot_ui_menu.c +++ b/firmware/lib/vboot_ui_menu.c @@ -145,7 +145,7 @@ static VbError_t boot_legacy_action(struct vb2_context *ctx) } if (0 == RollbackKernelLock(0)) - VbExLegacy(); /* Will not return if successful */ + VbExLegacy(0);/* Will not return if successful */ else VB2_DEBUG("Error locking kernel versions on legacy boot.\n"); diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c index 1dbeca0f..effa237d 100644 --- a/firmware/stub/vboot_api_stub.c +++ b/firmware/stub/vboot_api_stub.c @@ -164,7 +164,7 @@ enum VbEcBootMode_t VbGetMode(void) return vboot_mode; } -int VbExLegacy(void) +int VbExLegacy(int altfw_num) { return 1; } diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c index 651e8fef..3bc3a7f8 100644 --- a/tests/vboot_api_kernel2_tests.c +++ b/tests/vboot_api_kernel2_tests.c @@ -37,6 +37,7 @@ static int shutdown_request_power_held; static int audio_looping_calls_left; static uint32_t vbtlk_retval; static int vbexlegacy_called; +static int altfw_num; static int trust_ec; static int virtdev_set; static uint32_t virtdev_retval; @@ -78,6 +79,7 @@ static void ResetMocks(void) audio_looping_calls_left = 30; vbtlk_retval = 1000; vbexlegacy_called = 0; + altfw_num = -1; trust_ec = 0; virtdev_set = 0; virtdev_retval = 0; @@ -143,9 +145,11 @@ uint32_t VbExGetSwitches(uint32_t request_mask) return 0; } -int VbExLegacy(void) +int VbExLegacy(int _altfw_num) { vbexlegacy_called++; + altfw_num = _altfw_num; + return 0; } @@ -282,6 +286,8 @@ static void VbBootTest(void) static void VbBootDevTest(void) { + int key; + printf("Testing VbBootDeveloper()...\n"); /* Proceed after timeout */ @@ -301,6 +307,15 @@ static void VbBootDevTest(void) VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); + + /* Proceed to legacy after timeout if GBB flag set */ + ResetMocks(); + sd->gbb_flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY | + VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; + TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); + TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); /* Proceed to legacy after timeout if boot legacy and default boot * legacy are set */ @@ -310,6 +325,7 @@ static void VbBootDevTest(void) vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); /* Proceed to legacy boot mode only if enabled */ ResetMocks(); @@ -474,6 +490,7 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+L force legacy"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); ResetMocks(); vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); @@ -481,6 +498,7 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+L nv legacy"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); ResetMocks(); VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY; @@ -488,6 +506,39 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+L fwmp legacy"); TEST_EQ(vbexlegacy_called, 1, " fwmp legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); + + /* Pressing 1-9 boots alternative firmware only if enabled */ + for (key = '1'; key <= '9'; key++) { + ResetMocks(); + mock_keypress[0] = key; + TEST_EQ(VbBootDeveloper(&ctx), 1002, "'1' normal"); + TEST_EQ(vbexlegacy_called, 0, " not legacy"); + + ResetMocks(); + sd->gbb_flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; + mock_keypress[0] = key; + TEST_EQ(VbBootDeveloper(&ctx), 1002, + "Ctrl+L force legacy"); + TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, key - '0', " check altfw_num"); + + ResetMocks(); + vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); + mock_keypress[0] = key; + TEST_EQ(VbBootDeveloper(&ctx), 1002, + "Ctrl+L nv legacy"); + TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, key - '0', " check altfw_num"); + + ResetMocks(); + VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY; + mock_keypress[0] = key; + TEST_EQ(VbBootDeveloper(&ctx), 1002, + "Ctrl+L fwmp legacy"); + TEST_EQ(vbexlegacy_called, 1, " fwmp legacy"); + TEST_EQ(altfw_num, key - '0', " check altfw_num"); + } /* Ctrl+U boots USB only if enabled */ ResetMocks(); diff --git a/tests/vboot_detach_menu_tests.c b/tests/vboot_detach_menu_tests.c index 264fbf86..6ec9f334 100644 --- a/tests/vboot_detach_menu_tests.c +++ b/tests/vboot_detach_menu_tests.c @@ -41,6 +41,7 @@ static VbError_t vbtlk_last_retval; static int vbtlk_retval_count; static const VbError_t vbtlk_retval_fixed = 1002; static int vbexlegacy_called; +static int altfw_num; static int debug_info_displayed; static int trust_ec; static int virtdev_set; @@ -84,6 +85,7 @@ static void ResetMocks(void) shutdown_request_calls_left = 301; audio_looping_calls_left = 60; vbexlegacy_called = 0; + altfw_num = -1; debug_info_displayed = 0; trust_ec = 0; virtdev_set = 0; @@ -160,9 +162,11 @@ uint32_t VbExGetSwitches(uint32_t request_mask) return 0; } -int VbExLegacy(void) +int VbExLegacy(int _altfw_num) { vbexlegacy_called++; + altfw_num = _altfw_num; + return 0; } @@ -271,6 +275,7 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "default legacy GBB"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU, " warning screen"); TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)"); @@ -290,6 +295,7 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "default legacy NV"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU, " warning screen"); TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)"); @@ -611,6 +617,7 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+L force legacy"); TEST_EQ(vbexlegacy_called, 1, " try legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU, " warning screen"); TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)"); @@ -646,6 +653,7 @@ static void VbBootDevTest(void) TEST_EQ(VbBootDeveloperMenu(&ctx), vbtlk_retval_fixed, "Ctrl+L fwmp legacy"); TEST_EQ(vbexlegacy_called, 1, " fwmp legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING_MENU, " warning screen"); TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, " blank (error flash)"); @@ -908,6 +916,7 @@ static void VbBootDevTest(void) "Menu selected legacy boot"); TEST_EQ(debug_info_displayed, 0, " no debug info"); TEST_EQ(vbexlegacy_called, 2, " tried legacy boot twice"); + TEST_EQ(altfw_num, 0, " check altfw_num"); TEST_EQ(audio_looping_calls_left, 0, " audio timeout"); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery"); i = 0; @@ -2189,6 +2198,7 @@ static void VbNavigationTest(void) "developer mode long navigation"); TEST_EQ(debug_info_displayed, 1, " showed debug info"); TEST_EQ(vbexlegacy_called, 1, " tried legacy"); + TEST_EQ(altfw_num, 0, " check altfw_num"); TEST_EQ(audio_looping_calls_left, 0, " audio timeout"); TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, " no recovery"); i = 0; |