static void tpm_clear_tests(void) { /* No clear request */ reset_common_data(); TEST_SUCC(vb2_check_tpm_clear(&cc), "no clear request"); TEST_EQ(mock_tpm_clear_called, 0, "tpm not cleared"); /* Successful request */ reset_common_data(); vb2_nv_set(&cc, VB2_NV_CLEAR_TPM_OWNER_REQUEST, 1); TEST_SUCC(vb2_check_tpm_clear(&cc), "clear request"); TEST_EQ(vb2_nv_get(&cc, VB2_NV_CLEAR_TPM_OWNER_REQUEST), 0, "request cleared"); TEST_EQ(vb2_nv_get(&cc, VB2_NV_CLEAR_TPM_OWNER_DONE), 1, "done set"); TEST_EQ(mock_tpm_clear_called, 1, "tpm cleared"); /* Failed request */ reset_common_data(); mock_tpm_clear_retval = VB2_ERROR_EX_TPM_CLEAR_OWNER; vb2_nv_set(&cc, VB2_NV_CLEAR_TPM_OWNER_REQUEST, 1); TEST_EQ(vb2_check_tpm_clear(&cc), VB2_ERROR_EX_TPM_CLEAR_OWNER, "clear failure"); TEST_EQ(vb2_nv_get(&cc, VB2_NV_CLEAR_TPM_OWNER_REQUEST), 0, "request cleared"); TEST_EQ(vb2_nv_get(&cc, VB2_NV_CLEAR_TPM_OWNER_DONE), 0, "done not set"); }
int vb2api_fw_phase2(struct vb2_context *ctx) { int rv; /* * Use the slot from the last boot if this is a resume. Do not set * VB2_SD_STATUS_CHOSE_SLOT so the try counter is not decremented on * failure as we are explicitly not attempting to boot from a new slot. */ if (ctx->flags & VB2_CONTEXT_S3_RESUME) { struct vb2_shared_data *sd = vb2_get_sd(ctx); /* Set the current slot to the last booted slot */ sd->fw_slot = vb2_nv_get(ctx, VB2_NV_FW_TRIED); /* Set context flag if we're using slot B */ if (sd->fw_slot) ctx->flags |= VB2_CONTEXT_FW_SLOT_B; return VB2_SUCCESS; } /* Always clear RAM when entering developer mode */ if (ctx->flags & VB2_CONTEXT_DEVELOPER_MODE) ctx->flags |= VB2_CONTEXT_CLEAR_RAM; /* Check for explicit request to clear TPM */ rv = vb2_check_tpm_clear(ctx); if (rv) { vb2_fail(ctx, VB2_RECOVERY_TPM_CLEAR_OWNER, rv); return rv; } /* Decide which firmware slot to try this boot */ rv = vb2_select_fw_slot(ctx); if (rv) { vb2_fail(ctx, VB2_RECOVERY_FW_SLOT, rv); return rv; } return VB2_SUCCESS; }
int vb2api_fw_phase2(struct vb2_context *ctx) { int rv; /* Always clear RAM when entering developer mode */ if (ctx->flags & VB2_CONTEXT_DEVELOPER_MODE) ctx->flags |= VB2_CONTEXT_CLEAR_RAM; /* Check for explicit request to clear TPM */ rv = vb2_check_tpm_clear(ctx); if (rv) { vb2_fail(ctx, VB2_RECOVERY_TPM_CLEAR_OWNER, rv); return rv; } /* Decide which firmware slot to try this boot */ rv = vb2_select_fw_slot(ctx); if (rv) { vb2_fail(ctx, VB2_RECOVERY_FW_SLOT, rv); return rv; } return VB2_SUCCESS; }