diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common/boot_mode.c | 48 | ||||
-rw-r--r-- | tests/common/boot_mode.h | 20 | ||||
-rw-r--r-- | tests/vb2_kernel2_tests.c | 5 | ||||
-rw-r--r-- | tests/vb2_kernel_tests.c | 64 | ||||
-rw-r--r-- | tests/vb2_misc_tests.c | 25 | ||||
-rw-r--r-- | tests/vboot_kernel2_tests.c | 6 | ||||
-rw-r--r-- | tests/vboot_kernel_tests.c | 68 |
7 files changed, 142 insertions, 94 deletions
diff --git a/tests/common/boot_mode.c b/tests/common/boot_mode.c new file mode 100644 index 00000000..342b7909 --- /dev/null +++ b/tests/common/boot_mode.c @@ -0,0 +1,48 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Some helper function related to boot mode. + */ + +#include "2api.h" +#include "2misc.h" +#include "2nvstorage.h" +#include "common/boot_mode.h" +#include "common/tests.h" + +void _set_boot_mode(struct vb2_context *ctx, enum vb2_boot_mode boot_mode, + uint32_t recovery_reason, ...) +{ + struct vb2_shared_data *sd = vb2_get_sd(ctx); + + switch (boot_mode) { + case VB2_BOOT_MODE_MANUAL_RECOVERY: + TEST_NEQ(recovery_reason, 0, + "recovery_reason should be set in recovery mode"); + ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + sd->recovery_reason = recovery_reason; + ctx->flags |= VB2_CONTEXT_FORCE_RECOVERY_MODE; + ctx->flags |= VB2_CONTEXT_EC_TRUSTED; + break; + case VB2_BOOT_MODE_BROKEN_SCREEN: + TEST_NEQ(recovery_reason, 0, + "recovery_reason should be set in recovery mode"); + ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + sd->recovery_reason = recovery_reason; + break; + case VB2_BOOT_MODE_DIAGNOSTICS: + vb2_nv_set(ctx, VB2_NV_DIAG_REQUEST, 1); + break; + case VB2_BOOT_MODE_DEVELOPER: + ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; + break; + case VB2_BOOT_MODE_NORMAL: + break; + default: + TEST_TRUE(0, "SET_BOOT_MODE: Undefined boot mode"); + return; + } + vb2_set_boot_mode(ctx); + TEST_EQ(ctx->boot_mode, boot_mode, "Validity check for set boot mode"); +} diff --git a/tests/common/boot_mode.h b/tests/common/boot_mode.h new file mode 100644 index 00000000..bd6a3fd5 --- /dev/null +++ b/tests/common/boot_mode.h @@ -0,0 +1,20 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "2api.h" + +void _set_boot_mode(struct vb2_context *ctx, enum vb2_boot_mode boot_mode, + uint32_t recovery_reason, ...); + +/* + * Set the boot mode to the expected boot mode with the recovery reason if + * given. Also, set the corresponding ctx flag. + * + * @param ctx Vboot context. + * @param boot_mode Boot mode to be set. + * @param recovery_reason Recovery reason set to sd->recovery_reason. + */ +#define SET_BOOT_MODE(ctx, boot_mode, ...) \ + _set_boot_mode(ctx, boot_mode, ##__VA_ARGS__, 0) diff --git a/tests/vb2_kernel2_tests.c b/tests/vb2_kernel2_tests.c index b3477411..ef06b5f1 100644 --- a/tests/vb2_kernel2_tests.c +++ b/tests/vb2_kernel2_tests.c @@ -11,6 +11,7 @@ #include "2nvstorage.h" #include "2secdata.h" #include "2sysincludes.h" +#include "common/boot_mode.h" #include "common/tests.h" #include "host_common.h" #include "load_kernel_fw.h" @@ -25,7 +26,6 @@ static struct vb2_context *ctx; static struct vb2_shared_data *sd; static uint32_t kernel_version; static uint32_t new_version; -static enum vb2_boot_mode *boot_mode; static VbSelectAndLoadKernelParams kparams; /* Mocked function data */ @@ -50,8 +50,7 @@ static void reset_common_data(void) TEST_SUCC(vb2api_init(workbuf, sizeof(workbuf), &ctx), "vb2api_init failed"); - boot_mode = (enum vb2_boot_mode *)&ctx->boot_mode; - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); sd = vb2_get_sd(ctx); diff --git a/tests/vb2_kernel_tests.c b/tests/vb2_kernel_tests.c index 5d857e4e..a573b52b 100644 --- a/tests/vb2_kernel_tests.c +++ b/tests/vb2_kernel_tests.c @@ -12,6 +12,7 @@ #include "2rsa.h" #include "2secdata.h" #include "2sysincludes.h" +#include "common/boot_mode.h" #include "common/tests.h" #include "vboot_struct.h" #include "vboot_api.h" @@ -23,7 +24,6 @@ static struct vb2_context *ctx; static struct vb2_shared_data *sd; static struct vb2_fw_preamble *fwpre; static const char fw_kernel_key_data[36] = "Test kernel key data"; -static enum vb2_boot_mode *boot_mode; static VbSelectAndLoadKernelParams kparams; /* Mocked function data */ @@ -87,13 +87,6 @@ static void reset_common_data(enum reset_type t) mock_gbb.recovery_key.key_offset + mock_gbb.recovery_key.key_size; - /* For boot_mode */ - boot_mode = (enum vb2_boot_mode *)&ctx->boot_mode; - if (t == FOR_PHASE1) - *boot_mode = VB2_BOOT_MODE_BROKEN_SCREEN; - else - *boot_mode = VB2_BOOT_MODE_UNDEFINED; - if (t == FOR_PHASE1) { uint8_t *kdata; @@ -194,6 +187,7 @@ static void phase1_tests(void) /* Test successful call */ reset_common_data(FOR_PHASE1); + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); TEST_SUCC(vb2api_kernel_phase1(ctx), "phase1 good"); /* Make sure normal key was loaded */ TEST_EQ(sd->kernel_key_offset, sd->preamble_offset + @@ -215,7 +209,7 @@ static void phase1_tests(void) /* Test successful call in recovery mode */ reset_common_data(FOR_PHASE1); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); /* No preamble needed in recovery mode */ sd->workbuf_used = sd->preamble_offset; sd->preamble_offset = sd->preamble_size = 0; @@ -241,7 +235,7 @@ static void phase1_tests(void) /* Test flags for experimental features in non-recovery path */ reset_common_data(FOR_PHASE1); - ctx->flags &= ~VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); TEST_SUCC(vb2api_kernel_phase1(ctx), "phase1 non-rec good"); /* Make sure phone recovery functionality is enabled, but UI disabled */ TEST_EQ(vb2api_phone_recovery_enabled(ctx), 1, @@ -258,7 +252,7 @@ static void phase1_tests(void) /* Set 8 bits to 0 */ reset_common_data(FOR_PHASE1); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); vb2_secdata_kernel_set(ctx, VB2_SECDATA_KERNEL_FLAGS, 0); TEST_SUCC(vb2api_kernel_phase1(ctx), "phase1 rec good"); TEST_EQ(vb2_secdata_kernel_get(ctx, VB2_SECDATA_KERNEL_FLAGS), 0, @@ -266,7 +260,7 @@ static void phase1_tests(void) /* Set 8 bits to 1 */ reset_common_data(FOR_PHASE1); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); vb2_secdata_kernel_set(ctx, VB2_SECDATA_KERNEL_FLAGS, UINT8_MAX); TEST_SUCC(vb2api_kernel_phase1(ctx), "phase1 rec good"); TEST_EQ(vb2_secdata_kernel_get(ctx, VB2_SECDATA_KERNEL_FLAGS), @@ -275,6 +269,7 @@ static void phase1_tests(void) /* Bad secdata_fwmp causes failure in normal mode only */ reset_common_data(FOR_PHASE1); + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); mock_secdata_fwmp_check_retval = VB2_ERROR_SECDATA_FWMP_CRC; TEST_EQ(vb2api_kernel_phase1(ctx), mock_secdata_fwmp_check_retval, "phase1 bad secdata_fwmp"); @@ -282,15 +277,15 @@ static void phase1_tests(void) VB2_RECOVERY_SECDATA_FWMP_INIT, " recovery reason"); reset_common_data(FOR_PHASE1); + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); mock_secdata_fwmp_check_retval = VB2_ERROR_SECDATA_FWMP_CRC; - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; TEST_SUCC(vb2api_kernel_phase1(ctx), "phase1 bad secdata_fwmp rec"); TEST_EQ(vb2_nv_get(ctx, VB2_NV_RECOVERY_REQUEST), VB2_RECOVERY_NOT_REQUESTED, " no recovery"); /* Failures while reading recovery key */ reset_common_data(FOR_PHASE1); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); mock_gbb.h.recovery_key_size = sd->workbuf_size - 1; mock_gbb.recovery_key.key_size = mock_gbb.h.recovery_key_size - sizeof(mock_gbb.recovery_key); @@ -298,24 +293,25 @@ static void phase1_tests(void) "phase1 rec workbuf key"); TEST_EQ(sd->kernel_key_offset, 0, " workbuf key offset"); TEST_EQ(sd->kernel_key_size, 0, " workbuf key size"); - mock_gbb.h.flags |= VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); TEST_ABORT(vb2api_kernel_phase1(ctx), " fatal for manual recovery"); reset_common_data(FOR_PHASE1); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); mock_read_res_fail_on_call = 1; TEST_EQ(vb2api_kernel_phase1(ctx), VB2_SUCCESS, "phase1 rec gbb read key"); TEST_EQ(sd->kernel_key_offset, 0, " workbuf key offset"); TEST_EQ(sd->kernel_key_size, 0, " workbuf key size"); - mock_gbb.h.flags |= VB2_GBB_FLAG_FORCE_MANUAL_RECOVERY; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); mock_read_res_fail_on_call = 1; TEST_ABORT(vb2api_kernel_phase1(ctx), " fatal for manual recovery"); /* Failures while parsing subkey from firmware preamble */ reset_common_data(FOR_PHASE1); + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); sd->preamble_size = 0; TEST_EQ(vb2api_kernel_phase1(ctx), VB2_ERROR_API_KPHASE1_PREAMBLE, "phase1 fw preamble"); @@ -324,49 +320,44 @@ static void phase1_tests(void) static void phase2_tests(void) { reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); TEST_SUCC(vb2api_kernel_phase2(ctx), "Normal mode"); TEST_EQ(mock_ec_sync_called, 1, " EC sync"); reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_DEVELOPER; - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); TEST_SUCC(vb2api_kernel_phase2(ctx), "Developer mode"); TEST_EQ(mock_ec_sync_called, 1, " EC sync"); reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_DIAGNOSTICS; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DIAGNOSTICS); TEST_SUCC(vb2api_kernel_phase2(ctx), "Diagnostics mode"); TEST_EQ(mock_ec_sync_called, 1, " EC sync"); /* Commit data for recovery mode */ reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; - sd->recovery_reason = VB2_RECOVERY_RO_MANUAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); TEST_SUCC(vb2api_kernel_phase2(ctx), "Manual recovery mode"); TEST_EQ(mock_commit_data_called, 1, " commit data"); TEST_EQ(mock_ec_sync_called, 0, " EC sync"); reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_BROKEN_SCREEN; - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; - sd->recovery_reason = 123; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 123); TEST_SUCC(vb2api_kernel_phase2(ctx), "Broken screen mode"); TEST_EQ(mock_commit_data_called, 1, " commit data"); TEST_EQ(mock_ec_sync_called, 0, " EC sync"); /* Boot recovery - memory retraining */ reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; - sd->recovery_reason = VB2_RECOVERY_TRAIN_AND_REBOOT; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_TRAIN_AND_REBOOT); TEST_EQ(vb2api_kernel_phase2(ctx), VB2_REQUEST_REBOOT, "Recovery train and reboot"); /* Clear VB2_NV_DIAG_REQUEST */ reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); vb2_nv_set(ctx, VB2_NV_DIAG_REQUEST, 1); TEST_SUCC(vb2api_kernel_phase2(ctx), "Normal mode with DIAG_REQUEST"); TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), 0, @@ -374,7 +365,7 @@ static void phase2_tests(void) TEST_EQ(mock_commit_data_called, 1, " commit data"); reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_DIAGNOSTICS; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DIAGNOSTICS); vb2_nv_set(ctx, VB2_NV_DIAG_REQUEST, 1); TEST_SUCC(vb2api_kernel_phase2(ctx), "Diagnostics mode"); TEST_EQ(vb2_nv_get(ctx, VB2_NV_DIAG_REQUEST), 0, @@ -383,7 +374,7 @@ static void phase2_tests(void) /* Battery cutoff called after EC sync */ reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); vb2_nv_set(ctx, VB2_NV_BATTERY_CUTOFF_REQUEST, 1); TEST_EQ(vb2api_kernel_phase2(ctx), VB2_REQUEST_SHUTDOWN, "Set VB2_NV_BATTERY_CUTOFF_REQUEST"); @@ -392,14 +383,13 @@ static void phase2_tests(void) /* Return EC sync error */ reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); mock_ec_sync_retval = VB2_ERROR_MOCK; TEST_EQ(vb2api_kernel_phase2(ctx), VB2_ERROR_MOCK, "Return EC sync error"); /* Undefined boot mode */ reset_common_data(FOR_PHASE2); - *boot_mode = VB2_BOOT_MODE_UNDEFINED; TEST_EQ(vb2api_kernel_phase2(ctx), VB2_ERROR_ESCAPE_NO_BOOT, "Undefined boot mode"); } diff --git a/tests/vb2_misc_tests.c b/tests/vb2_misc_tests.c index d882743f..4add8d0d 100644 --- a/tests/vb2_misc_tests.c +++ b/tests/vb2_misc_tests.c @@ -11,6 +11,7 @@ #include "2nvstorage.h" #include "2secdata.h" #include "2sysincludes.h" +#include "common/boot_mode.h" #include "common/tests.h" /* Common context for tests */ @@ -22,7 +23,6 @@ static struct vb2_context *ctx; static struct vb2_shared_data *sd; static struct vb2_gbb_header gbb; static struct vb2_secdata_fwmp *fwmp; -static enum vb2_boot_mode *boot_mode; /* Mocked function data */ static enum vb2_resource_index mock_resource_index; @@ -54,8 +54,7 @@ static void reset_common_data(void) mock_tpm_clear_called = 0; mock_tpm_clear_retval = VB2_SUCCESS; - boot_mode = (enum vb2_boot_mode *)&ctx->boot_mode; - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); }; /* Mocked functions */ @@ -655,7 +654,8 @@ static void enable_dev_tests(void) " dev mode flag not set"); reset_common_data(); - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); TEST_SUCC(vb2api_enable_developer_mode(ctx), "vb2api_enable_developer_mode - success"); TEST_NEQ(vb2_secdata_firmware_get(ctx, VB2_SECDATA_FIRMWARE_FLAGS) & @@ -664,17 +664,16 @@ static void enable_dev_tests(void) /* secdata_firmware not initialized, aborts */ reset_common_data(); - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); sd->status &= ~VB2_SD_STATUS_SECDATA_FIRMWARE_INIT; sd->status |= VB2_SD_STATUS_RECOVERY_DECIDED; - TEST_ABORT(vb2api_enable_developer_mode(ctx), - "secdata_firmware no init, enable dev mode aborted"); + TEST_SUCC(vb2api_enable_developer_mode(ctx), + "secdata_firmware no init, enable dev mode ignored"); sd->status |= VB2_SD_STATUS_SECDATA_FIRMWARE_INIT; TEST_EQ(vb2_secdata_firmware_get(ctx, VB2_SECDATA_FIRMWARE_FLAGS) & VB2_SECDATA_FIRMWARE_FLAG_DEV_MODE, 0, " dev mode flag not set"); - TEST_EQ(vb2_nv_get(ctx, VB2_NV_DEV_BOOT_EXTERNAL), 0, - " NV_DEV_BOOT_EXTERNAL not set"); } static void tpm_clear_tests(void) @@ -816,9 +815,7 @@ static void clear_recovery_tests(void) /* Manual recovery */ reset_common_data(); - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; - sd->recovery_reason = 4; - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, 4); vb2_nv_set(ctx, VB2_NV_RECOVERY_REQUEST, 5); vb2_nv_set(ctx, VB2_NV_RECOVERY_SUBCODE, 13); vb2_clear_recovery(ctx); @@ -829,9 +826,7 @@ static void clear_recovery_tests(void) /* Broken screen */ reset_common_data(); - *boot_mode = VB2_BOOT_MODE_BROKEN_SCREEN; - sd->recovery_reason = 4; - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_BROKEN_SCREEN, 4); vb2_nv_set(ctx, VB2_NV_RECOVERY_REQUEST, 5); vb2_nv_set(ctx, VB2_NV_RECOVERY_SUBCODE, 13); vb2_clear_recovery(ctx); diff --git a/tests/vboot_kernel2_tests.c b/tests/vboot_kernel2_tests.c index d402969c..1f2f7a85 100644 --- a/tests/vboot_kernel2_tests.c +++ b/tests/vboot_kernel2_tests.c @@ -10,6 +10,7 @@ #include "2misc.h" #include "2nvstorage.h" #include "2secdata.h" +#include "common/boot_mode.h" #include "common/tests.h" #include "load_kernel_fw.h" #include "vboot_api.h" @@ -47,7 +48,6 @@ static struct vb2_shared_data *sd; static struct vb2_workbuf wb; static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE] __attribute__((aligned(VB2_WORKBUF_ALIGN))); -static enum vb2_boot_mode *boot_mode; static VbSelectAndLoadKernelParams lkp; static VbDiskInfo disk_info; @@ -81,8 +81,8 @@ static void reset_common_data(void) vb2_secdata_kernel_init(ctx); ctx->flags = VB2_CONTEXT_RECOVERY_MODE; - boot_mode = (enum vb2_boot_mode *)&ctx->boot_mode; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); sd = vb2_get_sd(ctx); sd->kernel_version_secdata = 0xabcdef | (1 << 24); diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c index afeb08d7..e4162fbf 100644 --- a/tests/vboot_kernel_tests.c +++ b/tests/vboot_kernel_tests.c @@ -13,6 +13,7 @@ #include "2secdata_struct.h" #include "cgptlib.h" #include "cgptlib_internal.h" +#include "common/boot_mode.h" #include "common/tests.h" #include "gpt.h" #include "load_kernel_fw.h" @@ -51,7 +52,6 @@ static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE] static struct vb2_context *ctx; static struct vb2_shared_data *sd; static struct vb2_packed_key mock_key; -static enum vb2_boot_mode *boot_mode; /** * Reset mock data (for use before each test) @@ -115,8 +115,7 @@ static void ResetMocks(void) fwmp = (struct vb2_secdata_fwmp *)ctx->secdata_fwmp; memcpy(&fwmp->dev_key_hash, mock_digest, sizeof(fwmp->dev_key_hash)); - boot_mode = (enum vb2_boot_mode *)&ctx->boot_mode; - *boot_mode = VB2_BOOT_MODE_NORMAL; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_NORMAL); // TODO: more workbuf fields - flags, secdata_firmware @@ -340,32 +339,28 @@ static void LoadKernelTest(void) /* In dev mode, fail if hash is bad too */ ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); keyblock_verify_fail = 2; TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, "Fail key block dev hash"); /* But just bad sig is ok */ ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); keyblock_verify_fail = 1; TestLoadKernel(0, "Succeed keyblock dev sig"); TEST_EQ(sd->flags & VB2_SD_FLAG_KERNEL_SIGNED, 0, " use hash"); /* In dev mode and requiring signed kernel, fail if sig is bad */ ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); vb2_nv_set(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY, 1); keyblock_verify_fail = 1; TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, "Fail key block dev sig"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_OFFICIAL_ONLY; keyblock_verify_fail = 1; TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, @@ -394,8 +389,8 @@ static void LoadKernelTest(void) "Keyblock minios flag mismatch"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_1 | VB2_KEYBLOCK_FLAG_DEVELOPER_1 | VB2_KEYBLOCK_FLAG_MINIOS_0; @@ -403,16 +398,17 @@ static void LoadKernelTest(void) "Keyblock recdev flag mismatch"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_1 | VB2_KEYBLOCK_FLAG_DEVELOPER_0 | VB2_KEYBLOCK_FLAG_MINIOS_0; TestLoadKernel(0, "Keyblock rec flag okay"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE | VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); + ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_1 | VB2_KEYBLOCK_FLAG_DEVELOPER_0 | VB2_KEYBLOCK_FLAG_MINIOS_0; @@ -420,8 +416,9 @@ static void LoadKernelTest(void) "Keyblock rec!dev flag mismatch"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_RECOVERY_MODE | VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); + ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_1 | VB2_KEYBLOCK_FLAG_DEVELOPER_1 | VB2_KEYBLOCK_FLAG_MINIOS_0; @@ -429,8 +426,7 @@ static void LoadKernelTest(void) /* Check keyblock flags (dev mode + signed kernel required) */ ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); vb2_nv_set(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY, 1); kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_1 | VB2_KEYBLOCK_FLAG_DEVELOPER_0 @@ -439,8 +435,7 @@ static void LoadKernelTest(void) "Keyblock dev flag mismatch (signed kernel required)"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_OFFICIAL_ONLY; kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_1 | VB2_KEYBLOCK_FLAG_DEVELOPER_0 @@ -449,8 +444,7 @@ static void LoadKernelTest(void) "Keyblock dev flag mismatch (signed kernel required)"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_OFFICIAL_ONLY; kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_0 | VB2_KEYBLOCK_FLAG_DEVELOPER_0 @@ -459,8 +453,7 @@ static void LoadKernelTest(void) "Keyblock dev flag mismatch (signed kernel required)"); ResetMocks(); - ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); vb2_nv_set(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY, 1); kbh.keyblock_flags = VB2_KEYBLOCK_FLAG_RECOVERY_0 | VB2_KEYBLOCK_FLAG_DEVELOPER_1 @@ -493,12 +486,13 @@ static void LoadKernelTest(void) ResetMocks(); kbh.data_key.key_version = 1; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); TestLoadKernel(0, "Key version ignored in dev mode"); ResetMocks(); kbh.data_key.key_version = 1; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); TestLoadKernel(0, "Key version ignored in rec mode"); ResetMocks(); @@ -516,18 +510,19 @@ static void LoadKernelTest(void) ResetMocks(); kph.kernel_version = 0; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); TestLoadKernel(0, "Kernel version ignored in dev mode"); ResetMocks(); kph.kernel_version = 0; - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); TestLoadKernel(0, "Kernel version ignored in rec mode"); /* Check kernel version (dev mode + signed kernel required) */ ResetMocks(); kbh.data_key.key_version = 0; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); vb2_nv_set(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY, 1); TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, "Keyblock key version checked in dev mode " @@ -535,7 +530,7 @@ static void LoadKernelTest(void) ResetMocks(); kbh.data_key.key_version = 0; - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); fwmp->flags |= VB2_SECDATA_FWMP_DEV_ENABLE_OFFICIAL_ONLY; TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, "Keyblock key version checked in dev mode " @@ -543,7 +538,7 @@ static void LoadKernelTest(void) /* Check developer key hash - bad */ ResetMocks(); - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); fwmp->flags |= VB2_SECDATA_FWMP_DEV_USE_KEY_HASH; fwmp->dev_key_hash[0]++; TestLoadKernel(VB2_ERROR_LK_INVALID_KERNEL_FOUND, @@ -551,14 +546,15 @@ static void LoadKernelTest(void) /* Check developer key hash - bad (recovery mode) */ ResetMocks(); - *boot_mode = VB2_BOOT_MODE_MANUAL_RECOVERY; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_MANUAL_RECOVERY, + VB2_RECOVERY_RO_MANUAL); fwmp->flags |= VB2_SECDATA_FWMP_DEV_USE_KEY_HASH; fwmp->dev_key_hash[0]++; TestLoadKernel(0, "Bad keyblock dev fwmp hash ignored in rec mode"); /* Check developer key hash - good */ ResetMocks(); - *boot_mode = VB2_BOOT_MODE_DEVELOPER; + SET_BOOT_MODE(ctx, VB2_BOOT_MODE_DEVELOPER); fwmp->flags |= VB2_SECDATA_FWMP_DEV_USE_KEY_HASH; TestLoadKernel(0, "Good keyblock dev fwmp hash"); |