コード例 #1
0
ファイル: Tcg2Pei.c プロジェクト: EvanLloyd/tianocore
/**
  Entry point of this module.

  @param[in] FileHandle   Handle of the file being invoked.
  @param[in] PeiServices  Describes the list of possible PEI Services.

  @return Status.

**/
EFI_STATUS
EFIAPI
PeimEntryMA (
    IN       EFI_PEI_FILE_HANDLE      FileHandle,
    IN CONST EFI_PEI_SERVICES         **PeiServices
)
{
    EFI_STATUS                        Status;
    EFI_STATUS                        Status2;
    EFI_BOOT_MODE                     BootMode;
    TPM_PCRINDEX                      PcrIndex;
    BOOLEAN                           S3ErrorReport;

    if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) ||
            CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)) {
        DEBUG ((EFI_D_ERROR, "No TPM2 instance required!\n"));
        return EFI_UNSUPPORTED;
    }

    if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {
        DEBUG ((EFI_D_ERROR, "TPM2 error!\n"));
        return EFI_DEVICE_ERROR;
    }

    Status = PeiServicesGetBootMode (&BootMode);
    ASSERT_EFI_ERROR (Status);

    //
    // In S3 path, skip shadow logic. no measurement is required
    //
    if (BootMode != BOOT_ON_S3_RESUME) {
        Status = (**PeiServices).RegisterForShadow(FileHandle);
        if (Status == EFI_ALREADY_STARTED) {
            mImageInMemory = TRUE;
            mFileHandle = FileHandle;
        } else if (Status == EFI_NOT_FOUND) {
            ASSERT_EFI_ERROR (Status);
        }
    }

    if (!mImageInMemory) {
        //
        // Initialize TPM device
        //
        Status = Tpm2RequestUseTpm ();
        if (EFI_ERROR (Status)) {
            DEBUG ((DEBUG_ERROR, "TPM2 not detected!\n"));
            goto Done;
        }

        S3ErrorReport = FALSE;
        if (PcdGet8 (PcdTpm2InitializationPolicy) == 1) {
            if (BootMode == BOOT_ON_S3_RESUME) {
                Status = Tpm2Startup (TPM_SU_STATE);
                if (EFI_ERROR (Status) ) {
                    Status = Tpm2Startup (TPM_SU_CLEAR);
                    if (!EFI_ERROR(Status)) {
                        S3ErrorReport = TRUE;
                    }
                }
            } else {
                Status = Tpm2Startup (TPM_SU_CLEAR);
            }
            if (EFI_ERROR (Status) ) {
                goto Done;
            }
        }

        //
        // Update Tpm2HashMask according to PCR bank.
        //
        SyncPcrAllocationsAndPcrMask ();

        if (S3ErrorReport) {
            //
            // The system firmware that resumes from S3 MUST deal with a
            // TPM2_Startup error appropriately.
            // For example, issue a TPM2_Startup(TPM_SU_CLEAR) command and
            // configuring the device securely by taking actions like extending a
            // separator with an error digest (0x01) into PCRs 0 through 7.
            //
            for (PcrIndex = 0; PcrIndex < 8; PcrIndex++) {
                Status = MeasureSeparatorEventWithError (PcrIndex);
                if (EFI_ERROR (Status)) {
                    DEBUG ((EFI_D_ERROR, "Separator Event with Error not Measured. Error!\n"));
                }
            }
        }

        //
        // TpmSelfTest is optional on S3 path, skip it to save S3 time
        //
        if (BootMode != BOOT_ON_S3_RESUME) {
            if (PcdGet8 (PcdTpm2SelfTestPolicy) == 1) {
                Status = Tpm2SelfTest (NO);
                if (EFI_ERROR (Status)) {
                    goto Done;
                }
            }
        }

        //
        // Only intall TpmInitializedPpi on success
        //
        Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
        ASSERT_EFI_ERROR (Status);
    }

    if (mImageInMemory) {
        Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices);
        return Status;
    }

Done:
    if (EFI_ERROR (Status)) {
        DEBUG ((EFI_D_ERROR, "TPM2 error! Build Hob\n"));
        BuildGuidHob (&gTpmErrorHobGuid,0);
        REPORT_STATUS_CODE (
            EFI_ERROR_CODE | EFI_ERROR_MINOR,
            (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
        );
    }
    //
    // Always intall TpmInitializationDonePpi no matter success or fail.
    // Other driver can know TPM initialization state by TpmInitializedPpi.
    //
    Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
    ASSERT_EFI_ERROR (Status2);

    return Status;
}
コード例 #2
0
ファイル: TrEEPei.c プロジェクト: jian-tian/UEFI
/**
  Entry point of this module.

  @param[in] FileHandle   Handle of the file being invoked.
  @param[in] PeiServices  Describes the list of possible PEI Services.

  @return Status.

**/
EFI_STATUS
EFIAPI
PeimEntryMA (
  IN       EFI_PEI_FILE_HANDLE      FileHandle,
  IN CONST EFI_PEI_SERVICES         **PeiServices
  )
{
  EFI_STATUS                        Status;
  EFI_BOOT_MODE                     BootMode;

  if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) ||
      CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
    DEBUG ((EFI_D_ERROR, "No TPM2 instance required!\n"));
    return EFI_UNSUPPORTED;
  }

  //
  // Update for Performance optimization
  //
  Status = Tpm2RequestUseTpm ();
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "TPM not detected!\n"));
    return Status;
  }

  Status = PeiServicesGetBootMode (&BootMode);
  ASSERT_EFI_ERROR (Status);

  //
  // In S3 path, skip shadow logic. no measurement is required
  //
  if (BootMode != BOOT_ON_S3_RESUME) {
    Status = (**PeiServices).RegisterForShadow(FileHandle);
    if (Status == EFI_ALREADY_STARTED) {
      mImageInMemory = TRUE;
      mFileHandle = FileHandle;
    } else if (Status == EFI_NOT_FOUND) {
      ASSERT_EFI_ERROR (Status);
    }
  }

  if (!mImageInMemory) {
    //
    // Initialize TPM device
    //
    if (PcdGet8 (PcdTpm2InitializationPolicy) == 1) {
      if (BootMode == BOOT_ON_S3_RESUME) {
        Status = Tpm2Startup (TPM_SU_STATE);
        if (EFI_ERROR (Status) ) {
          Status = Tpm2Startup (TPM_SU_CLEAR);
        }
      } else {
        Status = Tpm2Startup (TPM_SU_CLEAR);
      }
      if (EFI_ERROR (Status) ) {
        return Status;
      }
    }

    //
    // TpmSelfTest is optional on S3 path, skip it to save S3 time
    //
    if (BootMode != BOOT_ON_S3_RESUME) {
      if (PcdGet8 (PcdTpm2SelfTestPolicy) == 1) {
        Status = Tpm2SelfTest (NO);
        if (EFI_ERROR (Status)) {
          return Status;
        }
      }
    }

    Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
    ASSERT_EFI_ERROR (Status);
  }

  if (mImageInMemory) {
    Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices);
    if (EFI_ERROR (Status)) {
      return Status;
    }
  }

  return Status;
}
コード例 #3
0
ファイル: Tcg2Pei.c プロジェクト: rsalveti/edk2
/**
  Entry point of this module.

  @param[in] FileHandle   Handle of the file being invoked.
  @param[in] PeiServices  Describes the list of possible PEI Services.

  @return Status.

**/
EFI_STATUS
EFIAPI
PeimEntryMA (
  IN       EFI_PEI_FILE_HANDLE      FileHandle,
  IN CONST EFI_PEI_SERVICES         **PeiServices
  )
{
  EFI_STATUS                        Status;
  EFI_STATUS                        Status2;
  EFI_BOOT_MODE                     BootMode;

  if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid) ||
      CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
    DEBUG ((EFI_D_ERROR, "No TPM2 instance required!\n"));
    return EFI_UNSUPPORTED;
  }

  if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {
    DEBUG ((EFI_D_ERROR, "TPM2 error!\n"));
    return EFI_DEVICE_ERROR;
  }

  Status = PeiServicesGetBootMode (&BootMode);
  ASSERT_EFI_ERROR (Status);

  //
  // In S3 path, skip shadow logic. no measurement is required
  //
  if (BootMode != BOOT_ON_S3_RESUME) {
    Status = (**PeiServices).RegisterForShadow(FileHandle);
    if (Status == EFI_ALREADY_STARTED) {
      mImageInMemory = TRUE;
      mFileHandle = FileHandle;
    } else if (Status == EFI_NOT_FOUND) {
      ASSERT_EFI_ERROR (Status);
    }
  }

  if (!mImageInMemory) {
    //
    // Initialize TPM device
    //
    Status = Tpm2RequestUseTpm ();
    if (EFI_ERROR (Status)) {
      DEBUG ((DEBUG_ERROR, "TPM2 not detected!\n"));
      goto Done;
    }

    if (PcdGet8 (PcdTpm2InitializationPolicy) == 1) {
      if (BootMode == BOOT_ON_S3_RESUME) {
        Status = Tpm2Startup (TPM_SU_STATE);
        if (EFI_ERROR (Status) ) {
          Status = Tpm2Startup (TPM_SU_CLEAR);
        }
      } else {
        Status = Tpm2Startup (TPM_SU_CLEAR);
      }
      if (EFI_ERROR (Status) ) {
        goto Done;
      }
    }
    
    //
    // Update Tpm2HashMask according to PCR bank.
    //
    SetTpm2HashMask ();
    //
    // TpmSelfTest is optional on S3 path, skip it to save S3 time
    //
    if (BootMode != BOOT_ON_S3_RESUME) {
      if (PcdGet8 (PcdTpm2SelfTestPolicy) == 1) {
        Status = Tpm2SelfTest (NO);
        if (EFI_ERROR (Status)) {
          goto Done;
        }
      }
    }

    //
    // Only intall TpmInitializedPpi on success
    //
    Status = PeiServicesInstallPpi (&mTpmInitializedPpiList);
    ASSERT_EFI_ERROR (Status);
  }

  if (mImageInMemory) {
    Status = PeimEntryMP ((EFI_PEI_SERVICES**)PeiServices);
    return Status;
  }

Done:
  if (EFI_ERROR (Status)) {
    DEBUG ((EFI_D_ERROR, "TPM2 error! Build Hob\n"));
    BuildGuidHob (&gTpmErrorHobGuid,0);
    REPORT_STATUS_CODE (
      EFI_ERROR_CODE | EFI_ERROR_MINOR,
      (PcdGet32 (PcdStatusCodeSubClassTpmDevice) | EFI_P_EC_INTERFACE_ERROR)
      );
  }
  //
  // Always intall TpmInitializationDonePpi no matter success or fail.
  // Other driver can know TPM initialization state by TpmInitializedPpi.
  //
  Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
  ASSERT_EFI_ERROR (Status2);

  return Status;
}