summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-04-08 23:26:57 -0400
committerchrome-bot <chrome-bot@chromium.org>2018-09-26 14:59:54 -0700
commit89a517730f0207dbef9b3ff219d360904dca456e (patch)
treef88a77c3e82d345099ceb034f4eec01024ebcdcf /tests
parentc297fe4ddfaf0d9308955a5c41da5074e34324e7 (diff)
downloadvboot-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>
Diffstat (limited to 'tests')
-rw-r--r--tests/vboot_api_kernel2_tests.c53
-rw-r--r--tests/vboot_detach_menu_tests.c12
2 files changed, 63 insertions, 2 deletions
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;