【发布时间】:2019-06-06 18:57:10
【问题描述】:
我正在使用 TPM2 开发 UEFI 应用程序。 getCapabilities 有效,但其他一切都被推到这个 submitCommand() 函数上。我在那里尝试的所有内容都返回 EFI_ABORTED 作为状态。
我尝试了几个命令,例如 read_PCR 和 get_random_number,但它似乎适用于所有命令(TPM2 规范第 3 部分)。我选择了随机数命令,因为它是一个没有授权或加密的简单命令,正确执行时应该总是返回。
struct TPM2_ {
EFI_HANDLE image;
EFI_BOOT_SERVICES *BS;
EFI_TCG2_PROTOCOL *prot;
UINT32 activePCRbanks;
};
struct TPM2_Rand_Read_Command {
TPMI_ST_COMMAND_TAG tag;
UINT32 commandSize;
TPM_CC commandCode;
UINT16 bytesRequested;
};
struct TPM2_Rand_Read_Response {
TPM_ST tag;
UINT32 responseSize;
TPM_RC responseCode;
TPM2B_DIGEST randomBytes;
};
UINTN tpm_get_random(TPM2 * tpm) {
struct TPM2_Rand_Read_Command cmd;
struct TPM2_Rand_Read_Response resp;
cmd.tag = __builtin_bswap16(TPM_ST_NO_SESSIONS); //x86 is little endian, TPM2 is big-endian, use bswap to convert!)
cmd.commandCode = __builtin_bswap32(TPM_CC_GetRandom);
cmd.commandSize = __builtin_bswap32(sizeof(struct TPM2_Rand_Read_Command));
cmd.bytesRequested = __builtin_bswap16(4);
EFI_STATUS stat = tpm->prot->SubmitCommand(tpm->prot,sizeof(struct TPM2_Rand_Read_Command), (UINT8*)&cmd,sizeof(struct TPM2_Rand_Read_Response),(UINT8*)&resp); //responds 0x15 || 21
Print(L"statreadrand: %x \t %d \r\n", stat, *((UINT32*)resp.randomBytes.buffer));
CHECK_STATUS(stat, L"SubmitReadCommand");
return 0;
}
TPM2* tpm_create(EFI_BOOT_SERVICES *BS, EFI_HANDLE image) {
TPM2* tpm = calloc(1, sizeof(TPM2));
EFI_GUID prot_guid = (EFI_GUID)EFI_TCG2_PROTOCOL_GUID;
tpm->BS = BS;
tpm->image = image;
EFI_STATUS stat = tpm->BS->LocateProtocol(&prot_guid, NULL, (void **)&tpm->prot);
CHECK_STATUS(stat, L"LocateTPMProtocol");
return tpm;
}
我希望 SubmitCommand 函数返回 EFI_SUCCESS (0) 并用 4 个随机字节填充响应结构。但函数返回 EFI_ABORTED (21)
有人知道怎么解决吗?
编辑:尝试了不同的工具链(GNU-EFI/plain GCC/EDK2)都给出了相同的行为。
【问题讨论】:
-
确认您确实拥有 TPM 2 芯片并且它已在您的 BIOS 中启用
-
我有一个 TPM2 并且它已启用,否则 getCapabilties 和 getEventlog 也不起作用。它是 IFX TPM20,固件版本为 5.62 TPM2.0 UEFI SPEC 设置为 TCG_2(选项为 TCG_1_2 和 TCG_2)物理存在规范为 1.3 版,接口类型为 TIS。
-
cmd.commandSize 被赋值为小端,不应该转换成大端吗?
-
@MiSimon 是的,但是翻转它并不能解决 ABORTED 错误...
-
发送到 TPM 的数据不能包含任何填充字节,在命令/响应结构上使用 #pragma pack 来实现这一点,无论如何这应该会导致 tpm 错误消息而不是 EFI_ABORTED