diff options
author | Simon Glass <sjg@chromium.org> | 2018-04-08 23:26:57 -0400 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-26 14:59:54 -0700 |
commit | 89a517730f0207dbef9b3ff219d360904dca456e (patch) | |
tree | f88a77c3e82d345099ceb034f4eec01024ebcdcf | |
parent | c297fe4ddfaf0d9308955a5c41da5074e34324e7 (diff) | |
download | vboot-89a517730f0207dbef9b3ff219d360904dca456e.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>
-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 33b997f8..abc8213d 100644 --- a/firmware/include/vboot_api.h +++ b/firmware/include/vboot_api.h @@ -959,8 +959,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 470e1500..217090ad 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -52,14 +52,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); @@ -320,7 +328,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: @@ -358,6 +366,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); @@ -372,7 +386,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 8cd65af6..3a9d9e52 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 11c4c2f6..f9d061f8 100644 --- a/tests/vboot_api_kernel2_tests.c +++ b/tests/vboot_api_kernel2_tests.c @@ -36,6 +36,7 @@ static int shutdown_request_calls_left; 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; @@ -76,6 +77,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; @@ -132,9 +134,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,8 @@ static void VbBootTest(void) static void VbBootDevTest(void) { + int key; + printf("Testing VbBootDeveloper()...\n"); /* Proceed after timeout */ @@ -290,6 +296,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 */ @@ -299,6 +314,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(); @@ -463,6 +479,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); @@ -470,6 +487,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; @@ -477,6 +495,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; |