Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | * |
| 5 | * Tests for vboot_api_kernel, part 2 |
| 6 | */ |
| 7 | |
Bill Richardson | 0c3ba24 | 2013-03-29 11:09:30 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 12 | #include "2common.h" |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 13 | #include "2misc.h" |
| 14 | #include "2nvstorage.h" |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 15 | #include "host_common.h" |
| 16 | #include "load_kernel_fw.h" |
| 17 | #include "rollback_index.h" |
| 18 | #include "test_common.h" |
| 19 | #include "vboot_audio.h" |
| 20 | #include "vboot_common.h" |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 21 | #include "vboot_display.h" |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 22 | #include "vboot_kernel.h" |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 23 | #include "vboot_struct.h" |
Julius Werner | 52fa8c1 | 2019-05-07 12:59:47 -0700 | [diff] [blame] | 24 | #include "vboot_test.h" |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 25 | |
| 26 | /* Mock data */ |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 27 | static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE]; |
| 28 | static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 29 | static LoadKernelParams lkp; |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 30 | static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]; |
| 31 | static struct vb2_context ctx; |
Randall Spangler | 5142132 | 2017-12-14 15:43:17 -0800 | [diff] [blame] | 32 | static struct vb2_shared_data *sd; |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 33 | static struct vb2_gbb_header gbb; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 34 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 35 | static int audio_looping_calls_left; |
| 36 | static uint32_t vbtlk_retval; |
| 37 | static int vbexlegacy_called; |
Matt Delco | 3bfaab1 | 2019-02-13 11:13:27 -0800 | [diff] [blame] | 38 | static enum VbAltFwIndex_t altfw_num; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 39 | static uint64_t current_ticks; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 40 | static int trust_ec; |
| 41 | static int virtdev_set; |
| 42 | static uint32_t virtdev_retval; |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 43 | static uint32_t mock_keypress[16]; |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 44 | static uint32_t mock_keyflags[8]; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 45 | static uint32_t mock_keypress_count; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 46 | |
| 47 | #define GPIO_SHUTDOWN 1 |
| 48 | #define GPIO_PRESENCE 2 |
| 49 | #define GPIO_LID_CLOSED 4 |
| 50 | typedef struct GpioState { |
| 51 | uint32_t gpio_flags; |
| 52 | uint32_t count; |
| 53 | } GpioState; |
| 54 | struct GpioState mock_gpio[8]; |
| 55 | static uint32_t mock_gpio_count; |
| 56 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 57 | static uint32_t screens_displayed[8]; |
| 58 | static uint32_t screens_count = 0; |
| 59 | static uint32_t mock_num_disks[8]; |
| 60 | static uint32_t mock_num_disks_count; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 61 | static int tpm_set_mode_called; |
| 62 | static enum vb2_tpm_mode tpm_mode; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 63 | |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 64 | static char set_vendor_data[32]; |
| 65 | static int set_vendor_data_called; |
| 66 | |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Mocks the assertion of 1 or more gpios in |gpio_flags| for 100 ticks after |
| 69 | * an optional |ticks| delay. |
| 70 | */ |
| 71 | static void MockGpioAfter(uint32_t ticks, uint32_t gpio_flags) |
| 72 | { |
| 73 | uint32_t index = 0; |
| 74 | if (ticks > 0) |
| 75 | mock_gpio[index++].count = ticks - 1; |
| 76 | |
| 77 | mock_gpio[index].gpio_flags = gpio_flags; |
| 78 | mock_gpio[index].count = 100; |
| 79 | } |
| 80 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 81 | /* Reset mock data (for use before each test) */ |
| 82 | static void ResetMocks(void) |
| 83 | { |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 84 | vb2_init_ui(); |
Randall Spangler | 664096b | 2016-10-13 16:16:41 -0700 | [diff] [blame] | 85 | memset(VbApiKernelGetFwmp(), 0, sizeof(struct RollbackSpaceFwmp)); |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 86 | |
Randall Spangler | 664096b | 2016-10-13 16:16:41 -0700 | [diff] [blame] | 87 | memset(&shared_data, 0, sizeof(shared_data)); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 88 | VbSharedDataInit(shared, sizeof(shared_data)); |
| 89 | |
Randall Spangler | 664096b | 2016-10-13 16:16:41 -0700 | [diff] [blame] | 90 | memset(&lkp, 0, sizeof(lkp)); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 91 | |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 92 | memset(&ctx, 0, sizeof(ctx)); |
| 93 | ctx.workbuf = workbuf; |
| 94 | ctx.workbuf_size = sizeof(workbuf); |
| 95 | vb2_init_context(&ctx); |
| 96 | vb2_nv_init(&ctx); |
Randall Spangler | 79c1c61 | 2018-01-03 13:42:40 -0800 | [diff] [blame] | 97 | |
Randall Spangler | 5142132 | 2017-12-14 15:43:17 -0800 | [diff] [blame] | 98 | sd = vb2_get_sd(&ctx); |
Randall Spangler | 79c1c61 | 2018-01-03 13:42:40 -0800 | [diff] [blame] | 99 | sd->vbsd = shared; |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 100 | sd->flags |= VB2_SD_FLAG_DISPLAY_AVAILABLE; |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 101 | |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 102 | memset(&gbb, 0, sizeof(gbb)); |
| 103 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 104 | audio_looping_calls_left = 30; |
| 105 | vbtlk_retval = 1000; |
| 106 | vbexlegacy_called = 0; |
Matt Delco | 3bfaab1 | 2019-02-13 11:13:27 -0800 | [diff] [blame] | 107 | altfw_num = -100; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 108 | current_ticks = 0; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 109 | trust_ec = 0; |
| 110 | virtdev_set = 0; |
| 111 | virtdev_retval = 0; |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 112 | set_vendor_data_called = 0; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 113 | |
Randall Spangler | 664096b | 2016-10-13 16:16:41 -0700 | [diff] [blame] | 114 | memset(screens_displayed, 0, sizeof(screens_displayed)); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 115 | screens_count = 0; |
| 116 | |
Randall Spangler | 664096b | 2016-10-13 16:16:41 -0700 | [diff] [blame] | 117 | memset(mock_keypress, 0, sizeof(mock_keypress)); |
| 118 | memset(mock_keyflags, 0, sizeof(mock_keyflags)); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 119 | mock_keypress_count = 0; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 120 | memset(mock_gpio, 0, sizeof(mock_gpio)); |
| 121 | mock_gpio_count = 0; |
Randall Spangler | 664096b | 2016-10-13 16:16:41 -0700 | [diff] [blame] | 122 | memset(mock_num_disks, 0, sizeof(mock_num_disks)); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 123 | mock_num_disks_count = 0; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 124 | |
| 125 | tpm_set_mode_called = 0; |
| 126 | tpm_mode = VB2_TPM_MODE_ENABLED_TENTATIVE; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* Mock functions */ |
Joel Kitching | d0dae80 | 2019-08-22 16:32:05 +0800 | [diff] [blame] | 130 | uint32_t RollbackKernelLock(int recovery_mode) |
| 131 | { |
| 132 | return TPM_SUCCESS; |
| 133 | } |
| 134 | |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 135 | struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c) |
| 136 | { |
| 137 | return &gbb; |
| 138 | } |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 139 | |
| 140 | uint32_t VbExIsShutdownRequested(void) |
| 141 | { |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 142 | uint32_t result = 0; |
| 143 | if (mock_gpio_count >= ARRAY_SIZE(mock_gpio)) |
| 144 | return 0; |
| 145 | if (mock_gpio[mock_gpio_count].gpio_flags & GPIO_SHUTDOWN) |
| 146 | result |= VB_SHUTDOWN_REQUEST_POWER_BUTTON; |
| 147 | if (mock_gpio[mock_gpio_count].gpio_flags & GPIO_LID_CLOSED) |
| 148 | result |= VB_SHUTDOWN_REQUEST_LID_CLOSED; |
| 149 | if (mock_gpio[mock_gpio_count].count > 0) { |
| 150 | --mock_gpio[mock_gpio_count].count; |
| 151 | } else { |
| 152 | ++mock_gpio_count; |
Edward Hill | 00d4be6 | 2018-10-01 17:42:17 -0600 | [diff] [blame] | 153 | } |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 154 | return result; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | uint32_t VbExKeyboardRead(void) |
| 158 | { |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 159 | return VbExKeyboardReadWithFlags(NULL); |
| 160 | } |
| 161 | |
| 162 | uint32_t VbExKeyboardReadWithFlags(uint32_t *key_flags) |
| 163 | { |
| 164 | if (mock_keypress_count < ARRAY_SIZE(mock_keypress)) { |
Jacob Garber | 7cdd879 | 2019-08-13 14:50:16 -0600 | [diff] [blame] | 165 | if (key_flags != NULL && |
| 166 | mock_keypress_count < ARRAY_SIZE(mock_keyflags)) |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 167 | *key_flags = mock_keyflags[mock_keypress_count]; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 168 | return mock_keypress[mock_keypress_count++]; |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 169 | } else |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | uint32_t VbExGetSwitches(uint32_t request_mask) |
| 174 | { |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 175 | uint32_t result = 0; |
| 176 | if (mock_gpio_count >= ARRAY_SIZE(mock_gpio)) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 177 | return 0; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 178 | if ((request_mask & VB_SWITCH_FLAG_PHYS_PRESENCE_PRESSED) && |
| 179 | (mock_gpio[mock_gpio_count].gpio_flags & GPIO_PRESENCE)) |
| 180 | result |= VB_SWITCH_FLAG_PHYS_PRESENCE_PRESSED; |
| 181 | if (mock_gpio[mock_gpio_count].count > 0) { |
| 182 | --mock_gpio[mock_gpio_count].count; |
| 183 | } else { |
| 184 | ++mock_gpio_count; |
| 185 | } |
| 186 | return result; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Joel Kitching | e6700f4 | 2019-07-31 14:12:30 +0800 | [diff] [blame] | 189 | vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 190 | { |
| 191 | vbexlegacy_called++; |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 192 | altfw_num = _altfw_num; |
| 193 | |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 194 | /* VbExLegacy() can only return failure, or not return at all. */ |
Joel Kitching | 9908a9a | 2019-07-29 18:53:38 +0800 | [diff] [blame] | 195 | return VB2_ERROR_UNKNOWN; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void VbExSleepMs(uint32_t msec) |
| 199 | { |
| 200 | current_ticks += (uint64_t)msec * VB_USEC_PER_MSEC; |
| 201 | } |
| 202 | |
| 203 | uint64_t VbExGetTimer(void) |
| 204 | { |
| 205 | return current_ticks; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 208 | vb2_error_t VbExDiskGetInfo(VbDiskInfo **infos_ptr, uint32_t *count, |
| 209 | uint32_t disk_flags) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 210 | { |
| 211 | if (mock_num_disks_count < ARRAY_SIZE(mock_num_disks)) { |
| 212 | if (mock_num_disks[mock_num_disks_count] == -1) |
Joel Kitching | 166a07d | 2019-07-29 18:55:59 +0800 | [diff] [blame] | 213 | return VB2_ERROR_MOCK; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 214 | else |
| 215 | *count = mock_num_disks[mock_num_disks_count++]; |
| 216 | } else { |
| 217 | *count = 0; |
| 218 | } |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 219 | return VB2_SUCCESS; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 222 | vb2_error_t VbExDiskFreeInfo(VbDiskInfo *infos, |
| 223 | VbExDiskHandle_t preserve_handle) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 224 | { |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 225 | return VB2_SUCCESS; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Randall Spangler | e778ada | 2014-07-15 16:14:21 -0700 | [diff] [blame] | 228 | int VbExTrustEC(int devidx) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 229 | { |
| 230 | return trust_ec; |
| 231 | } |
| 232 | |
Randall Spangler | de818cc | 2017-12-12 14:05:19 -0800 | [diff] [blame] | 233 | int vb2_audio_looping(void) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 234 | { |
| 235 | if (audio_looping_calls_left == 0) |
| 236 | return 0; |
| 237 | else if (audio_looping_calls_left > 0) |
| 238 | audio_looping_calls_left--; |
| 239 | |
| 240 | return 1; |
| 241 | } |
| 242 | |
Joel Kitching | e6700f4 | 2019-07-31 14:12:30 +0800 | [diff] [blame] | 243 | vb2_error_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 244 | { |
| 245 | return vbtlk_retval + get_info_flags; |
| 246 | } |
| 247 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 248 | vb2_error_t VbDisplayScreen(struct vb2_context *c, uint32_t screen, int force, |
| 249 | const VbScreenData *data) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 250 | { |
| 251 | if (screens_count < ARRAY_SIZE(screens_displayed)) |
| 252 | screens_displayed[screens_count++] = screen; |
| 253 | |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 254 | return VB2_SUCCESS; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Joel Kitching | e6700f4 | 2019-07-31 14:12:30 +0800 | [diff] [blame] | 257 | vb2_error_t SetVirtualDevMode(int val) |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 258 | { |
| 259 | virtdev_set = val; |
| 260 | return virtdev_retval; |
| 261 | } |
| 262 | |
Joel Kitching | 90671fa | 2019-07-31 13:17:08 +0800 | [diff] [blame] | 263 | vb2_error_t VbExSetVendorData(const char *vendor_data_value) |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 264 | { |
| 265 | set_vendor_data_called = 1; |
| 266 | strncpy(set_vendor_data, vendor_data_value, sizeof(set_vendor_data)); |
| 267 | |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 268 | return VB2_SUCCESS; |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Joel Kitching | e6700f4 | 2019-07-31 14:12:30 +0800 | [diff] [blame] | 271 | vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val) |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 272 | { |
| 273 | tpm_set_mode_called = 1; |
| 274 | /* |
| 275 | * This mock will pretend that any call will fail if the tpm is |
| 276 | * already disabled (e.g., as if the code always tries to contact the |
| 277 | * tpm to issue a command). The real version may eventually be changed |
| 278 | * to return success if the incoming request is also to disable, but |
| 279 | * the point here is to have a way to simulate failure. |
| 280 | */ |
| 281 | if (tpm_mode == VB2_TPM_MODE_DISABLED) { |
| 282 | return VB2_ERROR_UNKNOWN; |
| 283 | } |
| 284 | tpm_mode = mode_val; |
| 285 | return VB2_SUCCESS; |
| 286 | } |
| 287 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 288 | /* Tests */ |
| 289 | |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 290 | /* |
| 291 | * Helper function to test VbUserConfirms against a sequence of gpio events. |
| 292 | * caller specifies a sequence of gpio events and the expected confirm vs. |
| 293 | * reboot result. |
| 294 | * |
| 295 | * Non-asserted gpios are used for 5 events, then 'first' for 5 events, |
| 296 | * 'second' for 5 events, and 'third' for 5 events. |
| 297 | * Typically most tests want 5 events of each type (so they'll specify 0 for |
| 298 | * 'first' and use 'second' through 'fourth'), but a few tests want the |
| 299 | * shutdown event to be seen once. |
| 300 | */ |
| 301 | static void VbUserConfirmsTestGpio(uint32_t first, uint32_t second, |
| 302 | uint32_t third, uint32_t confirm, |
| 303 | const char *msg) |
| 304 | { |
| 305 | ResetMocks(); |
| 306 | mock_gpio[0].gpio_flags = 0; |
| 307 | mock_gpio[0].count = 4; |
| 308 | mock_gpio[1].gpio_flags = first; |
| 309 | mock_gpio[1].count = 4; |
| 310 | mock_gpio[2].gpio_flags = second; |
| 311 | mock_gpio[2].count = 4; |
| 312 | mock_gpio[3].gpio_flags = third; |
| 313 | mock_gpio[3].count = 4; |
| 314 | if (confirm) { |
| 315 | TEST_EQ(VbUserConfirms(&ctx, |
| 316 | VB_CONFIRM_SPACE_MEANS_NO | |
| 317 | VB_CONFIRM_MUST_TRUST_KEYBOARD), |
| 318 | 1, msg); |
| 319 | } else { |
| 320 | TEST_EQ(VbUserConfirms(&ctx, |
| 321 | VB_CONFIRM_SPACE_MEANS_NO | |
| 322 | VB_CONFIRM_MUST_TRUST_KEYBOARD), |
| 323 | -1, msg); |
| 324 | } |
| 325 | } |
| 326 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 327 | static void VbUserConfirmsTest(void) |
| 328 | { |
| 329 | printf("Testing VbUserConfirms()...\n"); |
| 330 | |
| 331 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 332 | MockGpioAfter(1, GPIO_SHUTDOWN); |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 333 | TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Shutdown requested"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 334 | |
| 335 | ResetMocks(); |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 336 | mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS; |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 337 | TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Shutdown requested"); |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 338 | |
| 339 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 340 | mock_keypress[0] = VB_KEY_ENTER; |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 341 | TEST_EQ(VbUserConfirms(&ctx, 0), 1, "Enter"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 342 | |
| 343 | ResetMocks(); |
Simon Glass | 4d4c36e | 2018-10-17 08:41:53 -0600 | [diff] [blame] | 344 | mock_keypress[0] = VB_KEY_ESC; |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 345 | TEST_EQ(VbUserConfirms(&ctx, 0), 0, "Esc"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 346 | |
| 347 | ResetMocks(); |
| 348 | mock_keypress[0] = ' '; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 349 | MockGpioAfter(1, GPIO_SHUTDOWN); |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 350 | TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_SPACE_MEANS_NO), 0, |
Joel Kitching | 9ad8a41 | 2018-08-02 16:21:17 +0800 | [diff] [blame] | 351 | "Space means no"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 352 | |
| 353 | ResetMocks(); |
| 354 | mock_keypress[0] = ' '; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 355 | MockGpioAfter(1, GPIO_SHUTDOWN); |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 356 | TEST_EQ(VbUserConfirms(&ctx, 0), -1, "Space ignored"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 357 | |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 358 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 359 | mock_keypress[0] = VB_KEY_ENTER; |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 360 | mock_keyflags[0] = VB_KEY_FLAG_TRUSTED_KEYBOARD; |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 361 | TEST_EQ(VbUserConfirms(&ctx, VB_CONFIRM_MUST_TRUST_KEYBOARD), |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 362 | 1, "Enter with trusted keyboard"); |
| 363 | |
| 364 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 365 | mock_keypress[0] = VB_KEY_ENTER; /* untrusted */ |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 366 | mock_keypress[1] = ' '; |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 367 | TEST_EQ(VbUserConfirms(&ctx, |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 368 | VB_CONFIRM_SPACE_MEANS_NO | |
| 369 | VB_CONFIRM_MUST_TRUST_KEYBOARD), |
| 370 | 0, "Untrusted keyboard"); |
| 371 | |
| 372 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 373 | MockGpioAfter(0, GPIO_PRESENCE); |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 374 | TEST_EQ(VbUserConfirms(&ctx, |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 375 | VB_CONFIRM_SPACE_MEANS_NO | |
| 376 | VB_CONFIRM_MUST_TRUST_KEYBOARD), |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 377 | 1, "Presence button"); |
| 378 | |
| 379 | /* |
| 380 | * List of possiblities for shutdown and physical presence events that |
| 381 | * occur over time. Time advanced from left to right (where each |
| 382 | * represents the gpio[s] that are seen during a given iteration of |
| 383 | * the loop). The meaning of the characters: |
| 384 | * |
| 385 | * _ means no gpio |
| 386 | * s means shutdown gpio |
| 387 | * p means presence gpio |
| 388 | * B means both shutdown and presence gpio |
| 389 | * |
| 390 | * 1: ______ppp______ -> confirm |
| 391 | * 2: ______sss______ -> shutdown |
| 392 | * 3: ___pppsss______ -> confirm |
| 393 | * 4: ___sssppp______ -> shutdown |
| 394 | * 5: ___pppBBB______ -> confirm |
| 395 | * 6: ___pppBBBppp___ -> shutdown |
| 396 | * 7: ___pppBBBsss___ -> confirm |
| 397 | * 8: ___sssBBB______ -> confirm |
| 398 | * 9: ___sssBBBppp___ -> shutdown |
| 399 | * 10: ___sssBBBsss___ -> confirm |
| 400 | * 11: ______BBB______ -> confirm |
| 401 | * 12: ______BBBsss___ -> confirm |
| 402 | * 13: ______BBBppp___ -> shutdown |
| 403 | */ |
| 404 | |
| 405 | /* 1: presence means confirm */ |
| 406 | VbUserConfirmsTestGpio(GPIO_PRESENCE, 0, 0, 1, "presence"); |
| 407 | |
| 408 | /* 2: shutdown means shutdown */ |
| 409 | VbUserConfirmsTestGpio(GPIO_SHUTDOWN, 0, 0, 0, "shutdown"); |
| 410 | |
| 411 | /* 3: presence then shutdown means confirm */ |
| 412 | VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_SHUTDOWN, 0, 1, |
| 413 | "presence then shutdown"); |
| 414 | |
| 415 | /* 4: shutdown then presence means shutdown */ |
| 416 | VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE, 0, 0, |
| 417 | "shutdown then presence"); |
| 418 | |
| 419 | /* 5: presence then shutdown+presence then none mean confirm */ |
| 420 | VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 421 | 0, 1, "presence, both, none"); |
| 422 | |
| 423 | /* 6: presence then shutdown+presence then presence means shutdown */ |
| 424 | VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 425 | GPIO_PRESENCE, 0, "presence, both, presence"); |
| 426 | |
| 427 | /* 7: presence then shutdown+presence then shutdown means confirm */ |
| 428 | VbUserConfirmsTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 429 | GPIO_SHUTDOWN, 1, "presence, both, shutdown"); |
| 430 | |
| 431 | /* 8: shutdown then shutdown+presence then none means confirm */ |
| 432 | VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 433 | 0, 1, "shutdown, both, none"); |
| 434 | |
| 435 | /* 9: shutdown then shutdown+presence then presence means shutdown */ |
| 436 | VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 437 | GPIO_PRESENCE, 0, "shutdown, both, presence"); |
| 438 | |
| 439 | /* 10: shutdown then shutdown+presence then shutdown means confirm */ |
| 440 | VbUserConfirmsTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 441 | GPIO_SHUTDOWN, 1, "shutdown, both, shutdown"); |
| 442 | |
| 443 | /* 11: shutdown+presence then none means confirm */ |
| 444 | VbUserConfirmsTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 0, 1, |
| 445 | "both"); |
| 446 | |
| 447 | /* 12: shutdown+presence then shutdown means confirm */ |
| 448 | VbUserConfirmsTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 449 | GPIO_SHUTDOWN, 0, 1, "both, shutdown"); |
| 450 | |
| 451 | /* 13: shutdown+presence then presence means shutdown */ |
| 452 | VbUserConfirmsTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 453 | GPIO_PRESENCE, 0, 0, "both, presence"); |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 454 | |
| 455 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 456 | mock_keypress[0] = VB_KEY_ENTER; |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 457 | mock_keypress[1] = 'y'; |
| 458 | mock_keypress[2] = 'z'; |
| 459 | mock_keypress[3] = ' '; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 460 | mock_gpio[0].gpio_flags = GPIO_PRESENCE; |
| 461 | mock_gpio[0].count = ~0; |
Randall Spangler | 98616d7 | 2018-01-04 16:08:47 -0800 | [diff] [blame] | 462 | TEST_EQ(VbUserConfirms(&ctx, |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 463 | VB_CONFIRM_SPACE_MEANS_NO | |
| 464 | VB_CONFIRM_MUST_TRUST_KEYBOARD), |
| 465 | 0, "Recovery button stuck"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 466 | printf("...done.\n"); |
| 467 | } |
| 468 | |
| 469 | static void VbBootTest(void) |
| 470 | { |
| 471 | ResetMocks(); |
Sheng-Liang Song | 487a54b | 2014-07-26 21:34:28 -0700 | [diff] [blame] | 472 | VbExEcEnteringMode(0, VB_EC_NORMAL); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 473 | TEST_EQ(VbBootNormal(&ctx), 1002, "VbBootNormal()"); |
Sheng-Liang Song | 487a54b | 2014-07-26 21:34:28 -0700 | [diff] [blame] | 474 | TEST_EQ(VbGetMode(), VB_EC_NORMAL, "vboot_mode normal"); |
Joel Kitching | efd0dc2 | 2019-05-29 16:25:05 +0800 | [diff] [blame] | 475 | |
| 476 | ResetMocks(); |
| 477 | vb2_nv_set(&ctx, VB2_NV_DISPLAY_REQUEST, 1); |
| 478 | TEST_EQ(VbBootNormal(&ctx), VBERROR_REBOOT_REQUIRED, |
| 479 | "VbBootNormal() reboot to reset NVRAM display request"); |
| 480 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISPLAY_REQUEST), 0, |
| 481 | " display request reset"); |
| 482 | |
| 483 | ResetMocks(); |
| 484 | vb2_nv_set(&ctx, VB2_NV_DIAG_REQUEST, 1); |
| 485 | TEST_EQ(VbBootNormal(&ctx), VBERROR_REBOOT_REQUIRED, |
| 486 | "VbBootNormal() reboot to reset NVRAM diag request"); |
| 487 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), 0, |
| 488 | " diag request reset"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static void VbBootDevTest(void) |
| 492 | { |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 493 | int key; |
| 494 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 495 | printf("Testing VbBootDeveloper()...\n"); |
| 496 | |
| 497 | /* Proceed after timeout */ |
| 498 | ResetMocks(); |
Sheng-Liang Song | 487a54b | 2014-07-26 21:34:28 -0700 | [diff] [blame] | 499 | VbExEcEnteringMode(0, VB_EC_DEVELOPER); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 500 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); |
Sheng-Liang Song | 487a54b | 2014-07-26 21:34:28 -0700 | [diff] [blame] | 501 | TEST_EQ(VbGetMode(), VB_EC_DEVELOPER, "vboot_mode developer"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 502 | TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING, |
| 503 | " warning screen"); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 504 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, |
| 505 | " recovery reason"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 506 | TEST_EQ(audio_looping_calls_left, 0, " used up audio"); |
| 507 | |
Randall Spangler | f2a1dc0 | 2013-06-11 16:53:07 -0700 | [diff] [blame] | 508 | /* Proceed to legacy after timeout if GBB flag set */ |
| 509 | ResetMocks(); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 510 | gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY | |
Randall Spangler | 5142132 | 2017-12-14 15:43:17 -0800 | [diff] [blame] | 511 | VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 512 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); |
Randall Spangler | f2a1dc0 | 2013-06-11 16:53:07 -0700 | [diff] [blame] | 513 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 514 | TEST_EQ(altfw_num, 0, " check altfw_num"); |
| 515 | |
| 516 | /* Proceed to legacy after timeout if GBB flag set */ |
| 517 | ResetMocks(); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 518 | gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY | |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 519 | VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; |
| 520 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); |
| 521 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
| 522 | TEST_EQ(altfw_num, 0, " check altfw_num"); |
Randall Spangler | f2a1dc0 | 2013-06-11 16:53:07 -0700 | [diff] [blame] | 523 | |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 524 | /* Proceed to legacy after timeout if boot legacy and default boot |
| 525 | * legacy are set */ |
| 526 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 527 | vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 528 | VB2_DEV_DEFAULT_BOOT_LEGACY); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 529 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 530 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 531 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 532 | TEST_EQ(altfw_num, 0, " check altfw_num"); |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 533 | |
| 534 | /* Proceed to legacy boot mode only if enabled */ |
| 535 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 536 | vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 537 | VB2_DEV_DEFAULT_BOOT_LEGACY); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 538 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 539 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 540 | |
| 541 | /* Proceed to usb after timeout if boot usb and default boot |
| 542 | * usb are set */ |
| 543 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 544 | vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 545 | VB2_DEV_DEFAULT_BOOT_USB); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 546 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1); |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 547 | vbtlk_retval = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 548 | TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U USB"); |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 549 | |
| 550 | /* Proceed to usb boot mode only if enabled */ |
| 551 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 552 | vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 553 | VB2_DEV_DEFAULT_BOOT_USB); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 554 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Timeout"); |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 555 | |
| 556 | /* If no USB tries fixed disk */ |
| 557 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 558 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1); |
| 559 | vb2_nv_set(&ctx, VB2_NV_DEV_DEFAULT_BOOT, |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 560 | VB2_DEV_DEFAULT_BOOT_USB); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 561 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+U enabled"); |
Mary Ruthven | 12a55f2 | 2015-10-06 10:42:31 -0700 | [diff] [blame] | 562 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 563 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 564 | /* Up arrow is uninteresting / passed to VbCheckDisplayKey() */ |
| 565 | ResetMocks(); |
| 566 | mock_keypress[0] = VB_KEY_UP; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 567 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Up arrow"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 568 | |
| 569 | /* Shutdown requested in loop */ |
| 570 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 571 | mock_gpio[0].gpio_flags = 0; |
| 572 | mock_gpio[0].count = 2; |
| 573 | mock_gpio[1].gpio_flags = GPIO_SHUTDOWN; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 574 | TEST_EQ(VbBootDeveloper(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 575 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 576 | "Shutdown requested"); |
| 577 | TEST_NEQ(audio_looping_calls_left, 0, " aborts audio"); |
| 578 | |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 579 | /* Shutdown requested by keyboard in loop */ |
| 580 | ResetMocks(); |
| 581 | mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 582 | TEST_EQ(VbBootDeveloper(&ctx), |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 583 | VBERROR_SHUTDOWN_REQUESTED, |
| 584 | "Shutdown requested by keyboard"); |
| 585 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 586 | /* Space goes straight to recovery if no virtual dev switch */ |
| 587 | ResetMocks(); |
| 588 | mock_keypress[0] = ' '; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 589 | TEST_EQ(VbBootDeveloper(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 590 | VBERROR_LOAD_KERNEL_RECOVERY, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 591 | "Space = recovery"); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 592 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), |
Randall Spangler | dff5852 | 2017-11-27 15:37:13 -0800 | [diff] [blame] | 593 | VB2_RECOVERY_RW_DEV_SCREEN, " recovery reason"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 594 | |
| 595 | /* Space asks to disable virtual dev switch */ |
| 596 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 597 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 598 | mock_keypress[0] = ' '; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 599 | mock_keypress[1] = VB_KEY_ENTER; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 600 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 601 | "Space = tonorm"); |
| 602 | TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING, |
| 603 | " warning screen"); |
| 604 | TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM, |
| 605 | " tonorm screen"); |
| 606 | TEST_EQ(screens_displayed[2], VB_SCREEN_TO_NORM_CONFIRMED, |
| 607 | " confirm screen"); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 608 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 1, |
| 609 | " disable dev request"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 610 | |
| 611 | /* Space-space doesn't disable it */ |
| 612 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 613 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 614 | mock_keypress[0] = ' '; |
| 615 | mock_keypress[1] = ' '; |
Simon Glass | 4d4c36e | 2018-10-17 08:41:53 -0600 | [diff] [blame] | 616 | mock_keypress[2] = VB_KEY_ESC; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 617 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Space-space"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 618 | TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING, |
| 619 | " warning screen"); |
| 620 | TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM, |
| 621 | " tonorm screen"); |
| 622 | TEST_EQ(screens_displayed[2], VB_SCREEN_DEVELOPER_WARNING, |
| 623 | " warning screen"); |
| 624 | |
| 625 | /* Enter doesn't by default */ |
| 626 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 627 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 628 | mock_keypress[0] = VB_KEY_ENTER; |
| 629 | mock_keypress[1] = VB_KEY_ENTER; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 630 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Enter ignored"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 631 | |
| 632 | /* Enter does if GBB flag set */ |
| 633 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 634 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 635 | gbb.flags |= VB2_GBB_FLAG_ENTER_TRIGGERS_TONORM; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 636 | mock_keypress[0] = VB_KEY_ENTER; |
| 637 | mock_keypress[1] = VB_KEY_ENTER; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 638 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 639 | "Enter = tonorm"); |
| 640 | |
| 641 | /* Tonorm ignored if GBB forces dev switch on */ |
| 642 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 643 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 644 | gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 645 | mock_keypress[0] = ' '; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 646 | mock_keypress[1] = VB_KEY_ENTER; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 647 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 648 | "Can't tonorm gbb-dev"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 649 | |
| 650 | /* Shutdown requested at tonorm screen */ |
| 651 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 652 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 653 | mock_keypress[0] = ' '; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 654 | MockGpioAfter(3, GPIO_SHUTDOWN); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 655 | TEST_EQ(VbBootDeveloper(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 656 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 657 | "Shutdown requested at tonorm"); |
| 658 | TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_WARNING, |
| 659 | " warning screen"); |
| 660 | TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM, |
| 661 | " tonorm screen"); |
| 662 | |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 663 | /* Shutdown requested by keyboard at tonorm screen */ |
| 664 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 665 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 666 | mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 667 | TEST_EQ(VbBootDeveloper(&ctx), |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 668 | VBERROR_SHUTDOWN_REQUESTED, |
| 669 | "Shutdown requested by keyboard at nonorm"); |
| 670 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 671 | /* Ctrl+D dismisses warning */ |
| 672 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 673 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 674 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+D"); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 675 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, |
| 676 | " recovery reason"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 677 | TEST_NEQ(audio_looping_calls_left, 0, " aborts audio"); |
Randall Spangler | f2a1dc0 | 2013-06-11 16:53:07 -0700 | [diff] [blame] | 678 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 679 | |
| 680 | /* Ctrl+D doesn't boot legacy even if GBB flag is set */ |
| 681 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 682 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 683 | gbb.flags |= VB2_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 684 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+D"); |
Randall Spangler | f2a1dc0 | 2013-06-11 16:53:07 -0700 | [diff] [blame] | 685 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 686 | |
| 687 | /* Ctrl+L tries legacy boot mode only if enabled */ |
| 688 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 689 | mock_keypress[0] = VB_KEY_CTRL('L'); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 690 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+L normal"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 691 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 692 | |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 693 | /* Enter altfw menu and time out */ |
| 694 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 695 | MockGpioAfter(1000, GPIO_SHUTDOWN); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 696 | gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 697 | mock_keypress[0] = VB_KEY_CTRL('L'); |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 698 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_SHUTDOWN_REQUESTED, |
| 699 | "Ctrl+L force legacy"); |
| 700 | TEST_EQ(vbexlegacy_called, 0, " try legacy"); |
| 701 | |
| 702 | /* Enter altfw menu and select firmware 0 */ |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 703 | ResetMocks(); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 704 | gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 705 | mock_keypress[0] = VB_KEY_CTRL('L'); |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 706 | mock_keypress[1] = '0'; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 707 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 708 | "Ctrl+L force legacy"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 709 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 710 | TEST_EQ(altfw_num, 0, " check altfw_num"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 711 | |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 712 | /* Enter altfw menu and then exit it */ |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 713 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 714 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 715 | mock_keypress[0] = VB_KEY_CTRL('L'); |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 716 | mock_keypress[1] = VB_KEY_ESC; |
| 717 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
| 718 | "Ctrl+L nv legacy"); |
| 719 | TEST_EQ(vbexlegacy_called, 0, " try legacy"); |
| 720 | |
| 721 | /* Enter altfw menu and select firmware 0 */ |
| 722 | ResetMocks(); |
| 723 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 724 | mock_keypress[0] = VB_KEY_CTRL('L'); |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 725 | mock_keypress[1] = '0'; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 726 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 727 | "Ctrl+L nv legacy"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 728 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 729 | TEST_EQ(altfw_num, 0, " check altfw_num"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 730 | |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 731 | /* Enter altfw menu and select firmware 0 */ |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 732 | ResetMocks(); |
| 733 | VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 734 | mock_keypress[0] = VB_KEY_CTRL('L'); |
Simon Glass | a0ae318 | 2018-10-16 19:36:48 -0600 | [diff] [blame] | 735 | mock_keypress[1] = '0'; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 736 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 737 | "Ctrl+L fwmp legacy"); |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 738 | TEST_EQ(vbexlegacy_called, 1, " fwmp legacy"); |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 739 | TEST_EQ(altfw_num, 0, " check altfw_num"); |
| 740 | |
| 741 | /* Pressing 1-9 boots alternative firmware only if enabled */ |
| 742 | for (key = '1'; key <= '9'; key++) { |
| 743 | ResetMocks(); |
| 744 | mock_keypress[0] = key; |
| 745 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "'1' normal"); |
| 746 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 747 | |
| 748 | ResetMocks(); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 749 | gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_LEGACY; |
Simon Glass | 89a5177 | 2018-04-08 23:26:57 -0400 | [diff] [blame] | 750 | mock_keypress[0] = key; |
| 751 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
| 752 | "Ctrl+L force legacy"); |
| 753 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
| 754 | TEST_EQ(altfw_num, key - '0', " check altfw_num"); |
| 755 | |
| 756 | ResetMocks(); |
| 757 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_LEGACY, 1); |
| 758 | mock_keypress[0] = key; |
| 759 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
| 760 | "Ctrl+L nv legacy"); |
| 761 | TEST_EQ(vbexlegacy_called, 1, " try legacy"); |
| 762 | TEST_EQ(altfw_num, key - '0', " check altfw_num"); |
| 763 | |
| 764 | ResetMocks(); |
| 765 | VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_LEGACY; |
| 766 | mock_keypress[0] = key; |
| 767 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
| 768 | "Ctrl+L fwmp legacy"); |
| 769 | TEST_EQ(vbexlegacy_called, 1, " fwmp legacy"); |
| 770 | TEST_EQ(altfw_num, key - '0', " check altfw_num"); |
| 771 | } |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 772 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 773 | /* Ctrl+U boots USB only if enabled */ |
| 774 | ResetMocks(); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 775 | mock_keypress[0] = VB_KEY_CTRL('U'); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 776 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+U normal"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 777 | |
| 778 | /* Ctrl+U enabled, with good USB boot */ |
| 779 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 780 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 781 | mock_keypress[0] = VB_KEY_CTRL('U'); |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 782 | vbtlk_retval = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 783 | TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U USB"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 784 | |
| 785 | /* Ctrl+U enabled via GBB */ |
| 786 | ResetMocks(); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 787 | gbb.flags |= VB2_GBB_FLAG_FORCE_DEV_BOOT_USB; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 788 | mock_keypress[0] = VB_KEY_CTRL('U'); |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 789 | vbtlk_retval = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 790 | TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U force USB"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 791 | |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 792 | /* Ctrl+U enabled via FWMP */ |
| 793 | ResetMocks(); |
| 794 | VbApiKernelGetFwmp()->flags |= FWMP_DEV_ENABLE_USB; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 795 | mock_keypress[0] = VB_KEY_CTRL('U'); |
Joel Kitching | cf49e7b | 2019-07-29 18:51:00 +0800 | [diff] [blame] | 796 | vbtlk_retval = VB2_SUCCESS - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 797 | TEST_EQ(VbBootDeveloper(&ctx), 0, "Ctrl+U force USB"); |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 798 | |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 799 | /* Ctrl+S set vendor data and reboot */ |
| 800 | ResetMocks(); |
| 801 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 802 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 803 | mock_keypress[1] = '4'; |
| 804 | mock_keypress[2] = '3'; |
| 805 | mock_keypress[3] = '2'; |
| 806 | mock_keypress[4] = '1'; |
| 807 | mock_keypress[5] = VB_KEY_ENTER; // Set vendor data |
| 808 | mock_keypress[6] = VB_KEY_ENTER; // Confirm vendor data |
| 809 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 810 | "Ctrl+S set vendor data and reboot"); |
| 811 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 812 | TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct"); |
| 813 | |
| 814 | /* Ctrl+S extra keys ignored */ |
| 815 | ResetMocks(); |
| 816 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 817 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 818 | mock_keypress[1] = '4'; |
| 819 | mock_keypress[2] = '3'; |
| 820 | mock_keypress[3] = '2'; |
| 821 | mock_keypress[4] = '1'; |
| 822 | mock_keypress[5] = '5'; |
| 823 | mock_keypress[6] = VB_KEY_ENTER; // Set vendor data |
| 824 | mock_keypress[7] = VB_KEY_ENTER; // Confirm vendor data |
| 825 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 826 | "Ctrl+S extra keys ignored"); |
| 827 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 828 | TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct"); |
| 829 | |
| 830 | /* Ctrl+S converts case */ |
| 831 | ResetMocks(); |
| 832 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 833 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 834 | mock_keypress[1] = 'a'; |
| 835 | mock_keypress[2] = 'B'; |
| 836 | mock_keypress[3] = 'Y'; |
| 837 | mock_keypress[4] = 'z'; |
| 838 | mock_keypress[5] = VB_KEY_ENTER; // Set vendor data |
| 839 | mock_keypress[6] = VB_KEY_ENTER; // Confirm vendor data |
| 840 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 841 | "Ctrl+S converts case"); |
| 842 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 843 | TEST_STR_EQ(set_vendor_data, "ABYZ", " Vendor data correct"); |
| 844 | |
| 845 | /* Ctrl+S backspace works */ |
| 846 | ResetMocks(); |
| 847 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 848 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 849 | mock_keypress[1] = 'A'; |
| 850 | mock_keypress[2] = 'B'; |
| 851 | mock_keypress[3] = 'C'; |
| 852 | mock_keypress[4] = VB_KEY_BACKSPACE; |
| 853 | mock_keypress[5] = VB_KEY_BACKSPACE; |
| 854 | mock_keypress[6] = '3'; |
| 855 | mock_keypress[7] = '2'; |
| 856 | mock_keypress[8] = '1'; |
| 857 | mock_keypress[9] = VB_KEY_ENTER; // Set vendor data |
| 858 | mock_keypress[10] = VB_KEY_ENTER; // Confirm vendor data |
| 859 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 860 | "Ctrl+S backspace works"); |
| 861 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 862 | TEST_STR_EQ(set_vendor_data, "A321", " Vendor data correct"); |
| 863 | |
| 864 | /* Ctrl+S invalid chars don't print */ |
| 865 | ResetMocks(); |
| 866 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 867 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 868 | mock_keypress[1] = '4'; |
| 869 | mock_keypress[2] = '-'; |
| 870 | mock_keypress[3] = '^'; |
| 871 | mock_keypress[4] = '&'; |
| 872 | mock_keypress[5] = '$'; |
| 873 | mock_keypress[6] = '.'; |
| 874 | mock_keypress[7] = '3'; |
| 875 | mock_keypress[8] = '2'; |
| 876 | mock_keypress[9] = '1'; |
| 877 | mock_keypress[10] = VB_KEY_ENTER; // Set vendor data |
| 878 | mock_keypress[11] = VB_KEY_ENTER; // Confirm vendor data |
| 879 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 880 | "Ctrl+S invalid chars don't print"); |
| 881 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 882 | TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct"); |
| 883 | |
| 884 | /* Ctrl+S invalid chars don't print with backspace */ |
| 885 | ResetMocks(); |
| 886 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 887 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 888 | mock_keypress[1] = '4'; |
| 889 | mock_keypress[2] = '-'; |
| 890 | mock_keypress[3] = VB_KEY_BACKSPACE; // Should delete 4 |
| 891 | mock_keypress[4] = '3'; |
| 892 | mock_keypress[5] = '2'; |
| 893 | mock_keypress[6] = '1'; |
| 894 | mock_keypress[7] = '0'; |
| 895 | mock_keypress[8] = VB_KEY_ENTER; // Set vendor data |
| 896 | mock_keypress[9] = VB_KEY_ENTER; // Confirm vendor data |
| 897 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 898 | "Ctrl+S invalid chars don't print with backspace"); |
| 899 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 900 | TEST_STR_EQ(set_vendor_data, "3210", " Vendor data correct"); |
| 901 | |
| 902 | /* Ctrl+S backspace only doesn't underrun */ |
| 903 | ResetMocks(); |
| 904 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 905 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 906 | mock_keypress[1] = 'A'; |
| 907 | mock_keypress[2] = VB_KEY_BACKSPACE; |
| 908 | mock_keypress[3] = VB_KEY_BACKSPACE; |
| 909 | mock_keypress[4] = '4'; |
| 910 | mock_keypress[5] = '3'; |
| 911 | mock_keypress[6] = '2'; |
| 912 | mock_keypress[7] = '1'; |
| 913 | mock_keypress[8] = VB_KEY_ENTER; // Set vendor data |
| 914 | mock_keypress[9] = VB_KEY_ENTER; // Confirm vendor data |
| 915 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 916 | "Ctrl+S backspace only doesn't underrun"); |
| 917 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 918 | TEST_STR_EQ(set_vendor_data, "4321", " Vendor data correct"); |
| 919 | |
Mathew King | 06a65e7 | 2019-03-13 10:24:06 -0600 | [diff] [blame] | 920 | /* Ctrl+S vowels not allowed after first char */ |
| 921 | ResetMocks(); |
| 922 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 923 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 924 | mock_keypress[1] = 'A'; |
| 925 | mock_keypress[2] = 'A'; |
| 926 | mock_keypress[3] = 'B'; |
| 927 | mock_keypress[4] = 'E'; |
| 928 | mock_keypress[5] = 'i'; |
| 929 | mock_keypress[6] = 'C'; |
| 930 | mock_keypress[7] = 'O'; |
| 931 | mock_keypress[8] = 'u'; |
| 932 | mock_keypress[9] = 'D'; |
| 933 | mock_keypress[10] = VB_KEY_ENTER; // Set vendor data |
| 934 | mock_keypress[11] = VB_KEY_ENTER; // Confirm vendor data |
| 935 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
| 936 | "Ctrl+S vowels not allowed after first char"); |
| 937 | TEST_EQ(set_vendor_data_called, 1, " VbExSetVendorData() called"); |
| 938 | TEST_STR_EQ(set_vendor_data, "ABCD", " Vendor data correct"); |
| 939 | |
Mathew King | 9d6dc0d | 2019-02-11 10:27:59 -0700 | [diff] [blame] | 940 | /* Ctrl+S too short */ |
| 941 | ResetMocks(); |
| 942 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 943 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 944 | mock_keypress[1] = '1'; |
| 945 | mock_keypress[2] = '2'; |
| 946 | mock_keypress[3] = '3'; |
| 947 | mock_keypress[4] = VB_KEY_ENTER; // Set vendor data (Nothing happens) |
| 948 | mock_keypress[5] = VB_KEY_ENTER; // Confirm vendor data (Nothing happens) |
| 949 | mock_keypress[6] = VB_KEY_ESC; |
| 950 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+S too short"); |
| 951 | TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called"); |
| 952 | |
| 953 | /* Ctrl+S esc from set screen */ |
| 954 | ResetMocks(); |
| 955 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 956 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 957 | mock_keypress[1] = VB_KEY_ESC; |
| 958 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+S esc from set screen"); |
| 959 | TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called"); |
| 960 | |
| 961 | /* Ctrl+S esc from set screen with tag */ |
| 962 | ResetMocks(); |
| 963 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 964 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 965 | mock_keypress[1] = '4'; |
| 966 | mock_keypress[2] = '3'; |
| 967 | mock_keypress[3] = '2'; |
| 968 | mock_keypress[4] = '1'; |
| 969 | mock_keypress[5] = VB_KEY_ESC; |
| 970 | TEST_EQ(VbBootDeveloper(&ctx), 1002, |
| 971 | "Ctrl+S esc from set screen with tag"); |
| 972 | TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called"); |
| 973 | |
| 974 | /* Ctrl+S esc from confirm screen */ |
| 975 | ResetMocks(); |
| 976 | ctx.flags |= VB2_CONTEXT_VENDOR_DATA_SETTABLE; |
| 977 | mock_keypress[0] = VB_KEY_CTRL('S'); |
| 978 | mock_keypress[1] = '4'; |
| 979 | mock_keypress[2] = '3'; |
| 980 | mock_keypress[3] = '2'; |
| 981 | mock_keypress[4] = '1'; |
| 982 | mock_keypress[5] = VB_KEY_ENTER; // Set vendor data |
| 983 | mock_keypress[6] = VB_KEY_ESC; |
| 984 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+S esc from set screen"); |
| 985 | TEST_EQ(set_vendor_data_called, 0, " VbExSetVendorData() not called"); |
| 986 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 987 | /* If no USB, eventually times out and tries fixed disk */ |
| 988 | ResetMocks(); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 989 | vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_USB, 1); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 990 | mock_keypress[0] = VB_KEY_CTRL('U'); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 991 | TEST_EQ(VbBootDeveloper(&ctx), 1002, "Ctrl+U enabled"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 992 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 993 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, |
| 994 | " recovery reason"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 995 | TEST_EQ(audio_looping_calls_left, 0, " used up audio"); |
| 996 | |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 997 | /* If dev mode is disabled, goes to TONORM screen repeatedly */ |
| 998 | ResetMocks(); |
| 999 | VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1000 | mock_keypress[0] = VB_KEY_ESC; /* Just causes TONORM again */ |
| 1001 | mock_keypress[1] = VB_KEY_ENTER; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1002 | TEST_EQ(VbBootDeveloper(&ctx), VBERROR_REBOOT_REQUIRED, |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 1003 | "FWMP dev disabled"); |
| 1004 | TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM, |
| 1005 | " tonorm screen"); |
| 1006 | TEST_EQ(screens_displayed[1], VB_SCREEN_DEVELOPER_TO_NORM, |
| 1007 | " tonorm screen"); |
| 1008 | TEST_EQ(screens_displayed[2], VB_SCREEN_TO_NORM_CONFIRMED, |
| 1009 | " confirm screen"); |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1010 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISABLE_DEV_REQUEST), 1, |
| 1011 | " disable dev request"); |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 1012 | |
| 1013 | /* Shutdown requested when dev disabled */ |
| 1014 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1015 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 1016 | VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1017 | MockGpioAfter(1, GPIO_SHUTDOWN); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1018 | TEST_EQ(VbBootDeveloper(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1019 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 946abf1 | 2016-04-15 14:49:40 -0700 | [diff] [blame] | 1020 | "Shutdown requested when dev disabled"); |
| 1021 | TEST_EQ(screens_displayed[0], VB_SCREEN_DEVELOPER_TO_NORM, |
| 1022 | " tonorm screen"); |
| 1023 | |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 1024 | /* Shutdown requested by keyboard when dev disabled */ |
| 1025 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1026 | shared->flags = VBSD_BOOT_DEV_SWITCH_ON; |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 1027 | VbApiKernelGetFwmp()->flags |= FWMP_DEV_DISABLE_BOOT; |
| 1028 | mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1029 | TEST_EQ(VbBootDeveloper(&ctx), |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 1030 | VBERROR_SHUTDOWN_REQUESTED, |
| 1031 | "Shutdown requested by keyboard when dev disabled"); |
| 1032 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1033 | printf("...done.\n"); |
| 1034 | } |
| 1035 | |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1036 | /* |
| 1037 | * Helper function to test VbBootRecovery against a sequence of gpio events. |
| 1038 | * caller specifies a sequence of gpio events and the expected confirm vs. |
| 1039 | * reboot result. |
| 1040 | * |
| 1041 | * Non-asserted gpios are used for 5 events, then 'first' for 5 events, |
| 1042 | * 'second' for 5 events, and 'third' for 5 events. |
| 1043 | */ |
| 1044 | static void VbBootRecTestGpio(uint32_t first, uint32_t second, uint32_t third, |
| 1045 | uint32_t confirm, const char *msg) |
| 1046 | { |
| 1047 | ResetMocks(); |
| 1048 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
| 1049 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
| 1050 | trust_ec = 1; |
| 1051 | mock_keypress[0] = VB_KEY_CTRL('D'); |
| 1052 | mock_gpio[0].gpio_flags = 0; |
| 1053 | mock_gpio[0].count = 4; |
| 1054 | mock_gpio[1].gpio_flags = first; |
| 1055 | mock_gpio[1].count = 4; |
| 1056 | mock_gpio[2].gpio_flags = second; |
| 1057 | mock_gpio[2].count = 4; |
| 1058 | mock_gpio[3].gpio_flags = third; |
| 1059 | mock_gpio[3].count = 4; |
| 1060 | |
| 1061 | if (confirm) { |
| 1062 | TEST_EQ(VbBootRecovery(&ctx), VBERROR_EC_REBOOT_TO_RO_REQUIRED, |
| 1063 | msg); |
| 1064 | TEST_EQ(virtdev_set, 1, " virtual dev mode on"); |
| 1065 | } else { |
| 1066 | TEST_EQ(VbBootRecovery(&ctx), VBERROR_SHUTDOWN_REQUESTED, msg); |
| 1067 | TEST_EQ(virtdev_set, 0, " virtual dev mode off"); |
| 1068 | } |
| 1069 | } |
| 1070 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1071 | static void VbBootRecTest(void) |
| 1072 | { |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1073 | printf("Testing VbBootRecovery()...\n"); |
| 1074 | |
| 1075 | /* Shutdown requested in loop */ |
| 1076 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1077 | MockGpioAfter(10, GPIO_SHUTDOWN); |
Sheng-Liang Song | 487a54b | 2014-07-26 21:34:28 -0700 | [diff] [blame] | 1078 | VbExEcEnteringMode(0, VB_EC_RECOVERY); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1079 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1080 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1081 | "Shutdown requested"); |
Sheng-Liang Song | 487a54b | 2014-07-26 21:34:28 -0700 | [diff] [blame] | 1082 | TEST_EQ(VbGetMode(), VB_EC_RECOVERY, "vboot_mode recovery"); |
| 1083 | |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1084 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), 0, |
| 1085 | " recovery reason"); |
Daisuke Nojiri | 73a6372 | 2015-04-30 12:41:24 -0700 | [diff] [blame] | 1086 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1087 | " broken screen"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1088 | |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 1089 | /* Shutdown requested by keyboard */ |
| 1090 | ResetMocks(); |
| 1091 | VbExEcEnteringMode(0, VB_EC_RECOVERY); |
| 1092 | mock_keypress[0] = VB_BUTTON_POWER_SHORT_PRESS; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1093 | TEST_EQ(VbBootRecovery(&ctx), |
Daisuke Nojiri | eb13c06 | 2017-12-06 09:30:08 -0800 | [diff] [blame] | 1094 | VBERROR_SHUTDOWN_REQUESTED, |
| 1095 | "Shutdown requested by keyboard"); |
| 1096 | |
Edward Hill | 00d4be6 | 2018-10-01 17:42:17 -0600 | [diff] [blame] | 1097 | /* Ignore power button held on boot */ |
| 1098 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1099 | mock_gpio[0].gpio_flags = GPIO_SHUTDOWN; |
| 1100 | mock_gpio[0].count = 10; |
| 1101 | mock_gpio[1].gpio_flags = 0; |
| 1102 | mock_gpio[1].count = 10; |
| 1103 | mock_gpio[2].gpio_flags = GPIO_SHUTDOWN; |
| 1104 | mock_gpio[2].count = 10; |
| 1105 | mock_gpio[3].gpio_flags = 0; |
| 1106 | mock_gpio[3].count = 100; |
Edward Hill | 00d4be6 | 2018-10-01 17:42:17 -0600 | [diff] [blame] | 1107 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
| 1108 | trust_ec = 1; |
| 1109 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
| 1110 | TEST_EQ(VbBootRecovery(&ctx), |
| 1111 | VBERROR_SHUTDOWN_REQUESTED, |
| 1112 | "Ignore power button held on boot"); |
| 1113 | TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT, |
| 1114 | " insert screen"); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1115 | /* Shutdown should happen while we're sending the 2nd block of events */ |
| 1116 | TEST_EQ(mock_gpio_count, 3, " ignore held button"); |
Edward Hill | 00d4be6 | 2018-10-01 17:42:17 -0600 | [diff] [blame] | 1117 | |
Julius Werner | 5b26e40 | 2018-02-16 13:19:42 -0800 | [diff] [blame] | 1118 | /* Broken screen */ |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1119 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1120 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1121 | mock_num_disks[0] = 1; |
| 1122 | mock_num_disks[1] = 1; |
Shawn Nematbakhsh | 0417153 | 2013-12-13 14:41:47 -0800 | [diff] [blame] | 1123 | mock_num_disks[2] = 1; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1124 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1125 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1126 | VBERROR_SHUTDOWN_REQUESTED, |
Julius Werner | 5b26e40 | 2018-02-16 13:19:42 -0800 | [diff] [blame] | 1127 | "Broken"); |
Daisuke Nojiri | 73a6372 | 2015-04-30 12:41:24 -0700 | [diff] [blame] | 1128 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1129 | " broken screen"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1130 | |
Julius Werner | 5b26e40 | 2018-02-16 13:19:42 -0800 | [diff] [blame] | 1131 | /* Broken screen even if dev switch is on */ |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1132 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1133 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1134 | mock_num_disks[0] = 1; |
| 1135 | mock_num_disks[1] = 1; |
| 1136 | shared->flags |= VBSD_BOOT_DEV_SWITCH_ON; |
| 1137 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1138 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1139 | VBERROR_SHUTDOWN_REQUESTED, |
Julius Werner | 5b26e40 | 2018-02-16 13:19:42 -0800 | [diff] [blame] | 1140 | "Broken (dev)"); |
| 1141 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1142 | " broken screen"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1143 | |
Julius Werner | 3f896a5 | 2018-03-22 14:38:11 -0700 | [diff] [blame] | 1144 | /* Force insert screen with GBB flag */ |
| 1145 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1146 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Joel Kitching | de2cae6 | 2019-05-21 12:20:38 +0800 | [diff] [blame] | 1147 | gbb.flags |= VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY; |
Julius Werner | 3f896a5 | 2018-03-22 14:38:11 -0700 | [diff] [blame] | 1148 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
| 1149 | TEST_EQ(VbBootRecovery(&ctx), |
| 1150 | VBERROR_SHUTDOWN_REQUESTED, |
| 1151 | "Insert (forced by GBB)"); |
| 1152 | TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT, |
| 1153 | " insert screen"); |
| 1154 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1155 | /* No removal if recovery button physically pressed */ |
| 1156 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1157 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1158 | mock_num_disks[0] = 1; |
| 1159 | mock_num_disks[1] = 1; |
| 1160 | shared->flags |= VBSD_BOOT_REC_SWITCH_ON; |
| 1161 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1162 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1163 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1164 | "No remove in rec"); |
Daisuke Nojiri | 95554e4 | 2017-09-28 15:53:21 -0700 | [diff] [blame] | 1165 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1166 | " broken screen"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1167 | |
Shawn Nematbakhsh | 0417153 | 2013-12-13 14:41:47 -0800 | [diff] [blame] | 1168 | /* Removal if no disk initially found, but found on second attempt */ |
| 1169 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1170 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Shawn Nematbakhsh | 0417153 | 2013-12-13 14:41:47 -0800 | [diff] [blame] | 1171 | mock_num_disks[0] = 0; |
| 1172 | mock_num_disks[1] = 1; |
| 1173 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1174 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1175 | VBERROR_SHUTDOWN_REQUESTED, |
Shawn Nematbakhsh | 0417153 | 2013-12-13 14:41:47 -0800 | [diff] [blame] | 1176 | "Remove"); |
Daisuke Nojiri | 73a6372 | 2015-04-30 12:41:24 -0700 | [diff] [blame] | 1177 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1178 | " broken screen"); |
Shawn Nematbakhsh | 0417153 | 2013-12-13 14:41:47 -0800 | [diff] [blame] | 1179 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1180 | /* Bad disk count doesn't require removal */ |
| 1181 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1182 | MockGpioAfter(10, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1183 | mock_num_disks[0] = -1; |
| 1184 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1185 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1186 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1187 | "Bad disk count"); |
Daisuke Nojiri | 73a6372 | 2015-04-30 12:41:24 -0700 | [diff] [blame] | 1188 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1189 | " broken screen"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1190 | |
| 1191 | /* Ctrl+D ignored for many reasons... */ |
| 1192 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1193 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1194 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1195 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1196 | trust_ec = 0; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1197 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1198 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1199 | "Ctrl+D ignored if EC not trusted"); |
| 1200 | TEST_EQ(virtdev_set, 0, " virtual dev mode off"); |
| 1201 | TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV, |
| 1202 | " todev screen"); |
| 1203 | |
| 1204 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1205 | shared->flags = VBSD_BOOT_REC_SWITCH_ON | VBSD_BOOT_DEV_SWITCH_ON; |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1206 | trust_ec = 1; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1207 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1208 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1209 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1210 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1211 | "Ctrl+D ignored if already in dev mode"); |
| 1212 | TEST_EQ(virtdev_set, 0, " virtual dev mode off"); |
| 1213 | TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV, |
| 1214 | " todev screen"); |
| 1215 | |
| 1216 | ResetMocks(); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1217 | trust_ec = 1; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1218 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1219 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1220 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1221 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1222 | "Ctrl+D ignored if recovery not manually triggered"); |
| 1223 | TEST_EQ(virtdev_set, 0, " virtual dev mode off"); |
| 1224 | TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV, |
| 1225 | " todev screen"); |
| 1226 | |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1227 | /* Ctrl+D ignored because the physical presence switch is still pressed |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 1228 | * and we don't like that. |
| 1229 | */ |
| 1230 | ResetMocks(); |
| 1231 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
| 1232 | trust_ec = 1; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1233 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1234 | mock_gpio[0].gpio_flags = GPIO_PRESENCE; |
| 1235 | mock_gpio[0].count = 100; |
| 1236 | mock_gpio[1].gpio_flags = GPIO_PRESENCE | GPIO_SHUTDOWN; |
| 1237 | mock_gpio[1].count = 100; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1238 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1239 | VBERROR_SHUTDOWN_REQUESTED, |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1240 | "Ctrl+D ignored if phys pres button is still pressed"); |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 1241 | TEST_NEQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV, |
| 1242 | " todev screen"); |
| 1243 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1244 | /* Ctrl+D then space means don't enable */ |
| 1245 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1246 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1247 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1248 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
| 1249 | trust_ec = 1; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1250 | mock_keypress[0] = VB_KEY_CTRL('D'); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1251 | mock_keypress[1] = ' '; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1252 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1253 | VBERROR_SHUTDOWN_REQUESTED, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1254 | "Ctrl+D todev abort"); |
| 1255 | TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT, |
| 1256 | " insert screen"); |
| 1257 | TEST_EQ(screens_displayed[1], VB_SCREEN_RECOVERY_TO_DEV, |
| 1258 | " todev screen"); |
| 1259 | TEST_EQ(screens_displayed[2], VB_SCREEN_RECOVERY_INSERT, |
| 1260 | " insert screen"); |
| 1261 | TEST_EQ(virtdev_set, 0, " virtual dev mode off"); |
| 1262 | |
| 1263 | /* Ctrl+D then enter means enable */ |
| 1264 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1265 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1266 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1267 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
| 1268 | trust_ec = 1; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1269 | mock_keypress[0] = VB_KEY_CTRL('D'); |
| 1270 | mock_keypress[1] = VB_KEY_ENTER; |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 1271 | mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD; |
Daisuke Nojiri | c729318 | 2018-02-07 15:09:30 -0800 | [diff] [blame] | 1272 | TEST_EQ(VbBootRecovery(&ctx), VBERROR_EC_REBOOT_TO_RO_REQUIRED, |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1273 | "Ctrl+D todev confirm via enter"); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1274 | TEST_EQ(virtdev_set, 1, " virtual dev mode on"); |
| 1275 | |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1276 | /* |
| 1277 | * List of possiblities for shutdown and physical presence events that |
| 1278 | * occur over time. Time advanced from left to right (where each |
| 1279 | * represents the gpio[s] that are seen during a given iteration of |
| 1280 | * the loop). The meaning of the characters: |
| 1281 | * |
| 1282 | * _ means no gpio |
| 1283 | * s means shutdown gpio |
| 1284 | * p means presence gpio |
| 1285 | * B means both shutdown and presence gpio |
| 1286 | * |
| 1287 | * 1: ______ppp______ -> confirm |
| 1288 | * 2: ______sss______ -> shutdown |
| 1289 | * 3: ___pppsss______ -> confirm |
| 1290 | * 4: ___sssppp______ -> shutdown |
| 1291 | * 5: ___pppBBB______ -> confirm |
| 1292 | * 6: ___pppBBBppp___ -> shutdown |
| 1293 | * 7: ___pppBBBsss___ -> confirm |
| 1294 | * 8: ___sssBBB______ -> confirm |
| 1295 | * 9: ___sssBBBppp___ -> shutdown |
| 1296 | * 10: ___sssBBBsss___ -> confirm |
| 1297 | * 11: ______BBB______ -> confirm |
| 1298 | * 12: ______BBBsss___ -> confirm |
| 1299 | * 13: ______BBBppp___ -> shutdown |
| 1300 | */ |
| 1301 | |
| 1302 | /* 1: Ctrl+D then presence means enable */ |
| 1303 | VbBootRecTestGpio(GPIO_PRESENCE, 0, 0, 1, |
| 1304 | "Ctrl+D todev confirm via presence"); |
| 1305 | |
| 1306 | /* 2: Ctrl+D then shutdown means shutdown */ |
| 1307 | VbBootRecTestGpio(GPIO_SHUTDOWN, 0, 0, 0, |
| 1308 | "Ctrl+D todev then shutdown"); |
| 1309 | |
| 1310 | /* 3: Ctrl+D then presence then shutdown means confirm */ |
| 1311 | VbBootRecTestGpio(GPIO_PRESENCE, GPIO_SHUTDOWN, 0, 1, |
| 1312 | "Ctrl+D todev confirm via presence then shutdown"); |
| 1313 | |
| 1314 | /* 4: Ctrl+D then 2+ instance shutdown then presence means shutdown */ |
| 1315 | VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE, 0, 0, |
| 1316 | "Ctrl+D todev then 2+ shutdown then presence"); |
| 1317 | |
| 1318 | /* 5: Ctrl+D then presence then shutdown+presence then none */ |
| 1319 | VbBootRecTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 1, |
| 1320 | "Ctrl+D todev confirm via presence, both, none"); |
| 1321 | |
| 1322 | /* 6: Ctrl+D then presence then shutdown+presence then presence */ |
| 1323 | VbBootRecTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 1324 | GPIO_PRESENCE, 0, |
| 1325 | "Ctrl+D todev confirm via presence, both, presence"); |
| 1326 | |
| 1327 | /* 7: Ctrl+D then presence then shutdown+presence then shutdown */ |
| 1328 | VbBootRecTestGpio(GPIO_PRESENCE, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 1329 | GPIO_SHUTDOWN, 1, |
| 1330 | "Ctrl+D todev confirm via presence, both, shutdown"); |
| 1331 | |
| 1332 | /* 8: Ctrl+D then shutdown then shutdown+presence then none */ |
| 1333 | VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 1, |
| 1334 | "Ctrl+D todev then 2+ shutdown, both, none"); |
| 1335 | |
| 1336 | /* 9: Ctrl+D then shutdown then shutdown+presence then presence */ |
| 1337 | VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 1338 | GPIO_PRESENCE, 0, |
| 1339 | "Ctrl+D todev then 2+ shutdown, both, presence"); |
| 1340 | |
| 1341 | /* 10: Ctrl+D then shutdown then shutdown+presence then shutdown */ |
| 1342 | VbBootRecTestGpio(GPIO_SHUTDOWN, GPIO_PRESENCE | GPIO_SHUTDOWN, |
| 1343 | GPIO_SHUTDOWN, 1, |
| 1344 | "Ctrl+D todev then 2+ shutdown, both, shutdown"); |
| 1345 | |
| 1346 | /* 11: Ctrl+D then shutdown+presence then none */ |
| 1347 | VbBootRecTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, 0, 0, 1, |
| 1348 | "Ctrl+D todev confirm via both then none"); |
| 1349 | |
| 1350 | /* 12: Ctrl+D then shutdown+presence then shutdown */ |
| 1351 | VbBootRecTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, GPIO_SHUTDOWN, 0, 1, |
| 1352 | "Ctrl+D todev confirm via both then shutdown"); |
| 1353 | |
| 1354 | /* 13: Ctrl+D then shutdown+presence then presence */ |
| 1355 | VbBootRecTestGpio(GPIO_PRESENCE | GPIO_SHUTDOWN, GPIO_PRESENCE, 0, 0, |
| 1356 | "Ctrl+D todev confirm via both then presence"); |
| 1357 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1358 | /* Handle TPM error in enabling dev mode */ |
| 1359 | ResetMocks(); |
Joel Kitching | e1761d6 | 2019-03-18 16:36:36 +0800 | [diff] [blame] | 1360 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1361 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1362 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
| 1363 | trust_ec = 1; |
Mathew King | af26dc1 | 2019-02-19 10:43:32 -0700 | [diff] [blame] | 1364 | mock_keypress[0] = VB_KEY_CTRL('D'); |
| 1365 | mock_keypress[1] = VB_KEY_ENTER; |
Luigi Semenzato | a53a0b0 | 2014-01-10 16:26:08 -0800 | [diff] [blame] | 1366 | mock_keyflags[1] = VB_KEY_FLAG_TRUSTED_KEYBOARD; |
Joel Kitching | 166a07d | 2019-07-29 18:55:59 +0800 | [diff] [blame] | 1367 | virtdev_retval = VB2_ERROR_MOCK; |
Randall Spangler | b07b4b9 | 2018-01-04 17:58:01 -0800 | [diff] [blame] | 1368 | TEST_EQ(VbBootRecovery(&ctx), |
Randall Spangler | e4136dc | 2016-10-27 14:34:59 -0700 | [diff] [blame] | 1369 | VBERROR_TPM_SET_BOOT_MODE_STATE, |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1370 | "Ctrl+D todev failure"); |
| 1371 | |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 1372 | /* Test Diagnostic Mode via Ctrl-C - display available */ |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1373 | ResetMocks(); |
| 1374 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
| 1375 | trust_ec = 1; |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1376 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1377 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1378 | mock_keypress[0] = VB_KEY_CTRL('C'); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1379 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), 0, |
| 1380 | "todiag is zero"); |
| 1381 | if (DIAGNOSTIC_UI) |
| 1382 | TEST_EQ(VbBootRecovery(&ctx), |
| 1383 | VBERROR_REBOOT_REQUIRED, |
| 1384 | "Ctrl+C todiag - enabled"); |
| 1385 | else |
| 1386 | TEST_EQ(VbBootRecovery(&ctx), |
| 1387 | VBERROR_SHUTDOWN_REQUESTED, |
| 1388 | "Ctrl+C todiag - disabled"); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1389 | |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1390 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), DIAGNOSTIC_UI, |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1391 | " todiag is updated for Ctrl-C"); |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 1392 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISPLAY_REQUEST), 0, |
| 1393 | " todiag doesn't set unneeded DISPLAY_REQUEST"); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1394 | TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT, |
| 1395 | " insert screen"); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1396 | |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 1397 | /* Test Diagnostic Mode via F12 - display disabled */ |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1398 | ResetMocks(); |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 1399 | shared->flags = VBSD_BOOT_REC_SWITCH_ON; |
| 1400 | sd->flags &= ~VB2_SD_FLAG_DISPLAY_AVAILABLE; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1401 | trust_ec = 1; |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1402 | vbtlk_retval = VBERROR_NO_DISK_FOUND - VB_DISK_FLAG_REMOVABLE; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1403 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1404 | mock_keypress[0] = VB_KEY_F(12); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1405 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), 0, |
| 1406 | "todiag is zero"); |
| 1407 | if (DIAGNOSTIC_UI) |
| 1408 | TEST_EQ(VbBootRecovery(&ctx), |
| 1409 | VBERROR_REBOOT_REQUIRED, |
| 1410 | "F12 todiag - enabled"); |
| 1411 | else |
| 1412 | TEST_EQ(VbBootRecovery(&ctx), |
| 1413 | VBERROR_SHUTDOWN_REQUESTED, |
| 1414 | "F12 todiag - disabled"); |
| 1415 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), DIAGNOSTIC_UI, |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1416 | " todiag is updated for F12"); |
Joel Kitching | 451813e | 2019-05-29 15:22:54 +0800 | [diff] [blame] | 1417 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISPLAY_REQUEST), 0, |
| 1418 | " todiag doesn't set unneeded DISPLAY_REQUEST"); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1419 | TEST_EQ(screens_displayed[0], VB_SCREEN_RECOVERY_INSERT, |
| 1420 | " insert screen"); |
| 1421 | |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 1422 | /* Test Diagnostic Mode via Ctrl-C OS broken - display available */ |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1423 | ResetMocks(); |
| 1424 | shared->flags = 0; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1425 | MockGpioAfter(100, GPIO_SHUTDOWN); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1426 | mock_keypress[0] = VB_KEY_CTRL('C'); |
| 1427 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), 0, |
| 1428 | "todiag is zero"); |
| 1429 | if (DIAGNOSTIC_UI) |
| 1430 | TEST_EQ(VbBootRecovery(&ctx), |
| 1431 | VBERROR_REBOOT_REQUIRED, |
| 1432 | "Ctrl+C todiag os broken - enabled"); |
| 1433 | else |
| 1434 | TEST_EQ(VbBootRecovery(&ctx), |
| 1435 | VBERROR_SHUTDOWN_REQUESTED, |
| 1436 | "Ctrl+C todiag os broken - disabled"); |
| 1437 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DIAG_REQUEST), DIAGNOSTIC_UI, |
| 1438 | " todiag is updated for Ctrl-C"); |
Joel Kitching | 43f6cab | 2019-05-10 12:17:18 +0800 | [diff] [blame] | 1439 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_DISPLAY_REQUEST), 0, |
| 1440 | " todiag doesn't set unneeded DISPLAY_REQUEST"); |
Mathew King | 351c005 | 2019-04-11 11:56:47 -0600 | [diff] [blame] | 1441 | TEST_EQ(screens_displayed[0], VB_SCREEN_OS_BROKEN, |
| 1442 | " os broken screen"); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1443 | |
| 1444 | printf("...done.\n"); |
| 1445 | } |
| 1446 | |
| 1447 | static void VbBootDiagTest(void) |
| 1448 | { |
| 1449 | printf("Testing VbBootDiagnostic()...\n"); |
| 1450 | |
| 1451 | /* No key pressed - timeout. */ |
| 1452 | ResetMocks(); |
| 1453 | TEST_EQ(VbBootDiagnostic(&ctx), VBERROR_REBOOT_REQUIRED, "Timeout"); |
| 1454 | TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG, |
| 1455 | " confirm screen"); |
| 1456 | TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, |
| 1457 | " blank screen"); |
| 1458 | TEST_EQ(tpm_set_mode_called, 0, " no tpm call"); |
| 1459 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 1460 | TEST_EQ(current_ticks, 30 * VB_USEC_PER_SEC, |
| 1461 | " waited for 30 seconds"); |
| 1462 | |
| 1463 | /* Esc key pressed. */ |
| 1464 | ResetMocks(); |
| 1465 | mock_keypress[0] = VB_KEY_ESC; |
| 1466 | TEST_EQ(VbBootDiagnostic(&ctx), VBERROR_REBOOT_REQUIRED, "Esc key"); |
| 1467 | TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG, |
| 1468 | " confirm screen"); |
| 1469 | TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, |
| 1470 | " blank screen"); |
| 1471 | TEST_EQ(tpm_set_mode_called, 0, " no tpm call"); |
| 1472 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 1473 | TEST_EQ(current_ticks, 0, " didn't wait at all"); |
| 1474 | |
| 1475 | /* Shutdown requested via lid close */ |
| 1476 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1477 | MockGpioAfter(10, GPIO_LID_CLOSED); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1478 | TEST_EQ(VbBootDiagnostic(&ctx), VBERROR_SHUTDOWN_REQUESTED, "Shutdown"); |
| 1479 | TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG, |
| 1480 | " confirm screen"); |
| 1481 | TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, |
| 1482 | " blank screen"); |
| 1483 | TEST_EQ(tpm_set_mode_called, 0, " no tpm call"); |
| 1484 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 1485 | TEST_TRUE(current_ticks < VB_USEC_PER_SEC, " didn't wait long"); |
| 1486 | |
| 1487 | /* Power button pressed but not released. */ |
| 1488 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1489 | mock_gpio[0].gpio_flags = GPIO_PRESENCE; |
| 1490 | mock_gpio[0].count = ~0; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1491 | TEST_EQ(VbBootDiagnostic(&ctx), VBERROR_REBOOT_REQUIRED, "Power held"); |
| 1492 | TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG, |
| 1493 | " confirm screen"); |
| 1494 | TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, |
| 1495 | " blank screen"); |
| 1496 | TEST_EQ(tpm_set_mode_called, 0, " no tpm call"); |
| 1497 | TEST_EQ(vbexlegacy_called, 0, " not legacy"); |
| 1498 | |
| 1499 | /* Power button is pressed and released. */ |
| 1500 | ResetMocks(); |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1501 | MockGpioAfter(3, GPIO_PRESENCE); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1502 | TEST_EQ(VbBootDiagnostic(&ctx), VBERROR_REBOOT_REQUIRED, "Confirm"); |
| 1503 | TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG, |
| 1504 | " confirm screen"); |
| 1505 | TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, |
| 1506 | " blank screen"); |
| 1507 | TEST_EQ(tpm_set_mode_called, 1, " tpm call"); |
| 1508 | TEST_EQ(tpm_mode, VB2_TPM_MODE_DISABLED, " tpm disabled"); |
| 1509 | TEST_EQ(vbexlegacy_called, 1, " legacy"); |
| 1510 | TEST_EQ(altfw_num, VB_ALTFW_DIAGNOSTIC, " check altfw_num"); |
| 1511 | /* |
| 1512 | * Ideally we'd that no recovery request was recorded, but |
| 1513 | * VbExLegacy() can only fail or crash the tests. |
| 1514 | */ |
| 1515 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), |
| 1516 | VB2_RECOVERY_ALTFW_HASH_FAILED, |
| 1517 | " recovery request"); |
| 1518 | |
| 1519 | /* Power button confirm, but now with a tpm failure. */ |
| 1520 | ResetMocks(); |
| 1521 | tpm_mode = VB2_TPM_MODE_DISABLED; |
Matt Delco | 28c21d9 | 2019-04-23 13:37:26 -0700 | [diff] [blame] | 1522 | mock_gpio[0].gpio_flags = 0; |
| 1523 | mock_gpio[0].count = 2; |
| 1524 | mock_gpio[1].gpio_flags = GPIO_PRESENCE; |
| 1525 | mock_gpio[1].count = 2; |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1526 | TEST_EQ(VbBootDiagnostic(&ctx), VBERROR_REBOOT_REQUIRED, |
| 1527 | "Confirm but tpm fail"); |
| 1528 | TEST_EQ(screens_displayed[0], VB_SCREEN_CONFIRM_DIAG, |
| 1529 | " confirm screen"); |
| 1530 | TEST_EQ(screens_displayed[1], VB_SCREEN_BLANK, |
| 1531 | " blank screen"); |
| 1532 | TEST_EQ(tpm_set_mode_called, 1, " tpm call"); |
| 1533 | TEST_EQ(tpm_mode, VB2_TPM_MODE_DISABLED, " tpm disabled"); |
| 1534 | TEST_EQ(vbexlegacy_called, 0, " legacy not called"); |
| 1535 | TEST_EQ(vb2_nv_get(&ctx, VB2_NV_RECOVERY_REQUEST), |
| 1536 | VB2_RECOVERY_TPM_DISABLE_FAILED, |
| 1537 | " recovery request"); |
| 1538 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1539 | printf("...done.\n"); |
| 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | int main(void) |
| 1544 | { |
| 1545 | VbUserConfirmsTest(); |
| 1546 | VbBootTest(); |
| 1547 | VbBootDevTest(); |
| 1548 | VbBootRecTest(); |
Matt Delco | b6f4def | 2019-02-13 12:58:58 -0800 | [diff] [blame] | 1549 | if (DIAGNOSTIC_UI) |
| 1550 | VbBootDiagTest(); |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1551 | |
Randall Spangler | 7f43669 | 2013-02-05 12:42:36 -0800 | [diff] [blame] | 1552 | return gTestSuccess ? 0 : 255; |
| 1553 | } |