vboot TPM stub functions return error codes

TlclStubInit, TlclCloseDevice, and TlclOpenDevice were void functions but
should return error codes.

BUG=chromium-os:6695
TEST=RUNTESTS=1 make && emerge successfully

Review URL: http://codereview.chromium.org/5796005

Change-Id: I8ddbf8b1f080d98ff6ed42c4a675fbda5b17eef1
This commit is contained in:
Che-Liang Chiou
2010-12-16 14:11:17 +08:00
parent 9880ca5a03
commit 5d9509cbde
6 changed files with 27 additions and 20 deletions

View File

@@ -17,15 +17,15 @@
/*****************************************************************************/ /*****************************************************************************/
/* Functions to be implemented by the stub library */ /* Functions to be implemented by the stub library */
/* Initialize the stub library */ /* Initialize the stub library. Returns 0 if success, nonzero if error. */
void TlclStubInit(void); uint32_t TlclStubInit(void);
/* Close and open the device. This is needed for running more complex commands /* Close and open the device. This is needed for running more complex commands
* at user level, such as TPM_TakeOwnership, since the TPM device can be opened * at user level, such as TPM_TakeOwnership, since the TPM device can be opened
* only by one process at a time. * only by one process at a time. Returns 0 if success, nonzero if error.
*/ */
void TlclCloseDevice(void); uint32_t TlclCloseDevice(void);
void TlclOpenDevice(void); uint32_t TlclOpenDevice(void);
/* Send data to the TPM and receive a response. Returns 0 if success, /* Send data to the TPM and receive a response. Returns 0 if success,
* nonzero if error. */ * nonzero if error. */

View File

@@ -22,6 +22,7 @@
#define TPM_E_AREA_LOCKED ((uint32_t)0x0000003c) #define TPM_E_AREA_LOCKED ((uint32_t)0x0000003c)
#define TPM_E_BADINDEX ((uint32_t)0x00000002) #define TPM_E_BADINDEX ((uint32_t)0x00000002)
#define TPM_E_BAD_PRESENCE ((uint32_t)0x0000002d) #define TPM_E_BAD_PRESENCE ((uint32_t)0x0000002d)
#define TPM_E_IOERROR ((uint32_t)0x0000001f)
#define TPM_E_INVALID_POSTINIT ((uint32_t)0x00000026) #define TPM_E_INVALID_POSTINIT ((uint32_t)0x00000026)
#define TPM_E_MAXNVWRITES ((uint32_t)0x00000048) #define TPM_E_MAXNVWRITES ((uint32_t)0x00000048)
#define TPM_E_OWNER_SET ((uint32_t)0x00000014) #define TPM_E_OWNER_SET ((uint32_t)0x00000014)

View File

@@ -197,8 +197,7 @@ uint32_t SetupTPM(int recovery_mode, int developer_mode,
g_rollback_recovery_mode = 1; /* Global variables are usable in g_rollback_recovery_mode = 1; /* Global variables are usable in
* recovery mode */ * recovery mode */
/* TODO: TlclLibInit() should be able to return failure */ RETURN_ON_FAILURE(TlclLibInit());
TlclLibInit();
RETURN_ON_FAILURE(TlclStartup()); RETURN_ON_FAILURE(TlclStartup());
/* Use ContinueSelfTest rather than SelfTestFull(). It enables /* Use ContinueSelfTest rather than SelfTestFull(). It enables
@@ -336,7 +335,7 @@ uint32_t RollbackKernelLock(void) {
uint32_t RollbackS3Resume(void) { uint32_t RollbackS3Resume(void) {
uint32_t result; uint32_t result;
TlclLibInit(); RETURN_ON_FAILURE(TlclLibInit());
result = TlclResume(); result = TlclResume();
if (result == TPM_E_INVALID_POSTINIT) { if (result == TPM_E_INVALID_POSTINIT) {
/* We're on a platform where the TPM maintains power in S3, so /* We're on a platform where the TPM maintains power in S3, so

View File

@@ -18,9 +18,9 @@
/*****************************************************************************/ /*****************************************************************************/
/* Functions implemented in tlcl.c */ /* Functions implemented in tlcl.c */
/* Call this first. /* Call this first. Returns 0 if success, nonzero if error.
*/ */
void TlclLibInit(void); uint32_t TlclLibInit(void);
/* Logs to stdout. Arguments like printf. /* Logs to stdout. Arguments like printf.
*/ */

View File

@@ -91,8 +91,8 @@ static uint32_t Send(const uint8_t* command) {
/* Exported functions. */ /* Exported functions. */
void TlclLibInit(void) { uint32_t TlclLibInit(void) {
TlclStubInit(); return TlclStubInit();
} }
uint32_t TlclStartup(void) { uint32_t TlclStartup(void) {

View File

@@ -99,22 +99,25 @@ POSSIBLY_UNUSED static INLINE int TpmResponseSize(const uint8_t* buffer) {
} }
void TlclStubInit(void) { uint32_t TlclStubInit(void) {
TlclOpenDevice(); return TlclOpenDevice();
} }
void TlclCloseDevice(void) { uint32_t TlclCloseDevice(void) {
if (tpm_fd != -1) {
close(tpm_fd); close(tpm_fd);
tpm_fd = -1; tpm_fd = -1;
}
return 0;
} }
void TlclOpenDevice(void) { uint32_t TlclOpenDevice(void) {
char* device_path; char* device_path;
if (tpm_fd >= 0) if (tpm_fd >= 0)
return; /* Already open */ return 0; /* Already open */
device_path = getenv("TPM_DEVICE_PATH"); device_path = getenv("TPM_DEVICE_PATH");
if (device_path == NULL) { if (device_path == NULL) {
@@ -123,8 +126,12 @@ void TlclOpenDevice(void) {
tpm_fd = open(device_path, O_RDWR); tpm_fd = open(device_path, O_RDWR);
if (tpm_fd < 0) { if (tpm_fd < 0) {
error("cannot open TPM device %s: %s\n", device_path, strerror(errno)); VBDEBUG(("TPM: Cannot open TPM device %s: %s\n", device_path,
strerror(errno)));
return TPM_E_IOERROR;
} }
return 0;
} }