Revert "Verified boot wrapper - replace utility functions"

This reverts commit 0184886c8cb35e8e01d610622df448a7cb063e06

(This works with uboot-next, but not uboot, which doesn't implement its half of the new wrapper API.  So rolling back to leave uboot working.

Change-Id: I1f9e3c63e5bbdb20b9195cd68787bef89f24afee
Reviewed-on: http://gerrit.chromium.org/gerrit/3588
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Randall Spangler
2011-07-01 15:35:43 -07:00
parent f8c6549159
commit cfd841d3c2
15 changed files with 137 additions and 83 deletions

View File

@@ -14,7 +14,7 @@
/* Debug and error output */ /* Debug and error output */
#ifdef VBOOT_DEBUG #ifdef VBOOT_DEBUG
#define VBDEBUG(params) VbExDebug params #define VBDEBUG(params) debug params
#else #else
#define VBDEBUG(params) #define VBDEBUG(params)
#endif #endif
@@ -35,10 +35,16 @@
#define VBPERFEND(name) #define VBPERFEND(name)
#endif #endif
/* Outputs an error message and quits. */
void error(const char* format, ...);
/* Outputs debug/warning messages. */
void debug(const char* format, ...);
#ifdef VBOOT_DEBUG #ifdef VBOOT_DEBUG
#define VbAssert(expr) do { if (!(expr)) { \ #define VbAssert(expr) do { if (!(expr)) { \
VbExError("assert fail: %s at %s:%d\n", \ error("assert fail: %s at %s:%d\n", \
#expr, __FILE__, __LINE__); }} while(0) #expr, __FILE__, __LINE__); }} while(0)
#else #else
#define VbAssert(expr) #define VbAssert(expr)
#endif #endif
@@ -51,6 +57,14 @@
/* Return the minimum of (a) or (b). */ /* Return the minimum of (a) or (b). */
#define Min(a, b) (((a) < (b)) ? (a) : (b)) #define Min(a, b) (((a) < (b)) ? (a) : (b))
/* Allocate [size] bytes and return a pointer to the allocated memory. Abort
* on error.
*/
void* Malloc(size_t size);
/* Free memory pointed by [ptr] previously allocated by Malloc(). */
void Free(void* ptr);
/* Compare [n] bytes in [src1] and [src2] /* Compare [n] bytes in [src1] and [src2]
* Returns an integer less than, equal to, or greater than zero if the first [n] * Returns an integer less than, equal to, or greater than zero if the first [n]
* bytes of [src1] is found, respectively, to be less than, to match, or be * bytes of [src1] is found, respectively, to be less than, to match, or be
@@ -82,4 +96,18 @@ int SafeMemcmp(const void* s1, const void* s2, size_t n);
#define memset _do_not_use_standard_memset #define memset _do_not_use_standard_memset
#endif #endif
/* Read a high-resolution timer. */
uint64_t VbGetTimer(void);
/* Return the maximum frequency for the high-resolution timer, in Hz.
*
* Note that this call MUST be fast; the implementation must not
* attempt to actually measure the frequency. This function need only
* return an upper bound for the timer frequency, so that minimum
* delays can be established. For example, if the same BIOS can run
* on CPUs where the timer frequency varies between 1.2GHz and 1.8GHz,
* return 1800000000 (or even 2000000000). */
uint64_t VbGetTimerMaxFreq(void);
#endif /* VBOOT_REFERENCE_UTILITY_H_ */ #endif /* VBOOT_REFERENCE_UTILITY_H_ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010-2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
@@ -8,7 +8,6 @@
#include "crc32.h" #include "crc32.h"
#include "gpt.h" #include "gpt.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
int GptInit(GptData *gpt) { int GptInit(GptData *gpt) {
int retval; int retval;

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
@@ -107,7 +107,7 @@ typedef struct DigestContext {
/* Initialize a digest context for use with signature algorithm [algorithm]. */ /* Initialize a digest context for use with signature algorithm [algorithm]. */
void DigestInit(DigestContext* ctx, int sig_algorithm); void DigestInit(DigestContext* ctx, int sig_algorithm);
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len); void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len);
/* Caller owns the returned digest and must free it. */ /* Caller owns the returned digest and must free it. */
uint8_t* DigestFinal(DigestContext* ctx); uint8_t* DigestFinal(DigestContext* ctx);

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
*/ */
@@ -9,7 +9,6 @@
*/ */
#include "cryptolib.h" #include "cryptolib.h"
#include "vboot_api.h"
#include "utility.h" #include "utility.h"
/* a[] -= mod */ /* a[] -= mod */
@@ -78,9 +77,9 @@ static void montMul(const RSAPublicKey *key,
*/ */
static void modpowF4(const RSAPublicKey *key, static void modpowF4(const RSAPublicKey *key,
uint8_t* inout) { uint8_t* inout) {
uint32_t* a = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t)); uint32_t* a = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
uint32_t* aR = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t)); uint32_t* aR = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
uint32_t* aaR = (uint32_t*) VbExMalloc(key->len * sizeof(uint32_t)); uint32_t* aaR = (uint32_t*) Malloc(key->len * sizeof(uint32_t));
uint32_t* aaa = aaR; /* Re-use location. */ uint32_t* aaa = aaR; /* Re-use location. */
int i; int i;
@@ -117,9 +116,9 @@ static void modpowF4(const RSAPublicKey *key,
*inout++ = (uint8_t)(tmp >> 0); *inout++ = (uint8_t)(tmp >> 0);
} }
VbExFree(a); Free(a);
VbExFree(aR); Free(aR);
VbExFree(aaR); Free(aaR);
} }
/* Verify a RSA PKCS1.5 signature against an expected hash. /* Verify a RSA PKCS1.5 signature against an expected hash.
@@ -153,7 +152,7 @@ int RSAVerify(const RSAPublicKey *key,
return 0; return 0;
} }
buf = (uint8_t*) VbExMalloc(sig_len); buf = (uint8_t*) Malloc(sig_len);
if (!buf) if (!buf)
return 0; return 0;
Memcpy(buf, sig, sig_len); Memcpy(buf, sig, sig_len);
@@ -178,7 +177,7 @@ int RSAVerify(const RSAPublicKey *key,
VBDEBUG(("In RSAVerify(): Hash check failed!\n")); VBDEBUG(("In RSAVerify(): Hash check failed!\n"));
success = 0; success = 0;
} }
VbExFree(buf); Free(buf);
return success; return success;
} }

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -8,12 +8,11 @@
#include "cryptolib.h" #include "cryptolib.h"
#include "stateful_util.h" #include "stateful_util.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) { uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
int key_len; /* Key length in bytes. (int type matches siglen_map) */ uint64_t key_len; /* Key length in bytes. */
if (algorithm < kNumAlgorithms) { if (algorithm < kNumAlgorithms) {
key_len = siglen_map[algorithm]; key_len = siglen_map[algorithm];
/* Total size needed by a RSAPublicKey structure is = /* Total size needed by a RSAPublicKey structure is =
* 2 * key_len bytes for the n and rr arrays * 2 * key_len bytes for the n and rr arrays
* + sizeof len + sizeof n0inv. * + sizeof len + sizeof n0inv.
@@ -25,7 +24,7 @@ uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
} }
RSAPublicKey* RSAPublicKeyNew(void) { RSAPublicKey* RSAPublicKeyNew(void) {
RSAPublicKey* key = (RSAPublicKey*) VbExMalloc(sizeof(RSAPublicKey)); RSAPublicKey* key = (RSAPublicKey*) Malloc(sizeof(RSAPublicKey));
key->n = NULL; key->n = NULL;
key->rr = NULL; key->rr = NULL;
return key; return key;
@@ -33,9 +32,9 @@ RSAPublicKey* RSAPublicKeyNew(void) {
void RSAPublicKeyFree(RSAPublicKey* key) { void RSAPublicKeyFree(RSAPublicKey* key) {
if (key) { if (key) {
VbExFree(key->n); Free(key->n);
VbExFree(key->rr); Free(key->rr);
VbExFree(key); Free(key);
} }
} }
@@ -60,8 +59,8 @@ RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, uint64_t len) {
return NULL; return NULL;
} }
key->n = (uint32_t*) VbExMalloc(key_len); key->n = (uint32_t*) Malloc(key_len);
key->rr = (uint32_t*) VbExMalloc(key_len); key->rr = (uint32_t*) Malloc(key_len);
StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv)); StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv));
StatefulMemcpy(&st, key->n, key_len); StatefulMemcpy(&st, key->n, key_len);
@@ -107,7 +106,7 @@ int RSAVerifyBinary_f(const uint8_t* key_blob,
success = RSAVerify(verification_key, sig, (uint32_t)sig_size, success = RSAVerify(verification_key, sig, (uint32_t)sig_size,
(uint8_t)algorithm, digest); (uint8_t)algorithm, digest);
VbExFree(digest); Free(digest);
if (!key) if (!key)
RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */ RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */
return success; return success;

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -7,27 +7,26 @@
#include "cryptolib.h" #include "cryptolib.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
void DigestInit(DigestContext* ctx, int sig_algorithm) { void DigestInit(DigestContext* ctx, int sig_algorithm) {
ctx->algorithm = hash_type_map[sig_algorithm]; ctx->algorithm = hash_type_map[sig_algorithm];
switch(ctx->algorithm) { switch(ctx->algorithm) {
case SHA1_DIGEST_ALGORITHM: case SHA1_DIGEST_ALGORITHM:
ctx->sha1_ctx = (SHA1_CTX*) VbExMalloc(sizeof(SHA1_CTX)); ctx->sha1_ctx = (SHA1_CTX*) Malloc(sizeof(SHA1_CTX));
SHA1_init(ctx->sha1_ctx); SHA1_init(ctx->sha1_ctx);
break; break;
case SHA256_DIGEST_ALGORITHM: case SHA256_DIGEST_ALGORITHM:
ctx->sha256_ctx = (SHA256_CTX*) VbExMalloc(sizeof(SHA256_CTX)); ctx->sha256_ctx = (SHA256_CTX*) Malloc(sizeof(SHA256_CTX));
SHA256_init(ctx->sha256_ctx); SHA256_init(ctx->sha256_ctx);
break; break;
case SHA512_DIGEST_ALGORITHM: case SHA512_DIGEST_ALGORITHM:
ctx->sha512_ctx = (SHA512_CTX*) VbExMalloc(sizeof(SHA512_CTX)); ctx->sha512_ctx = (SHA512_CTX*) Malloc(sizeof(SHA512_CTX));
SHA512_init(ctx->sha512_ctx); SHA512_init(ctx->sha512_ctx);
break; break;
}; };
} }
void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint32_t len) { void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len) {
switch(ctx->algorithm) { switch(ctx->algorithm) {
case SHA1_DIGEST_ALGORITHM: case SHA1_DIGEST_ALGORITHM:
SHA1_update(ctx->sha1_ctx, data, len); SHA1_update(ctx->sha1_ctx, data, len);
@@ -45,27 +44,26 @@ uint8_t* DigestFinal(DigestContext* ctx) {
uint8_t* digest = NULL; uint8_t* digest = NULL;
switch(ctx->algorithm) { switch(ctx->algorithm) {
case SHA1_DIGEST_ALGORITHM: case SHA1_DIGEST_ALGORITHM:
digest = (uint8_t*) VbExMalloc(SHA1_DIGEST_SIZE); digest = (uint8_t*) Malloc(SHA1_DIGEST_SIZE);
Memcpy(digest, SHA1_final(ctx->sha1_ctx), SHA1_DIGEST_SIZE); Memcpy(digest, SHA1_final(ctx->sha1_ctx), SHA1_DIGEST_SIZE);
VbExFree(ctx->sha1_ctx); Free(ctx->sha1_ctx);
break; break;
case SHA256_DIGEST_ALGORITHM: case SHA256_DIGEST_ALGORITHM:
digest = (uint8_t*) VbExMalloc(SHA256_DIGEST_SIZE); digest = (uint8_t*) Malloc(SHA256_DIGEST_SIZE);
Memcpy(digest, SHA256_final(ctx->sha256_ctx), SHA256_DIGEST_SIZE); Memcpy(digest, SHA256_final(ctx->sha256_ctx), SHA256_DIGEST_SIZE);
VbExFree(ctx->sha256_ctx); Free(ctx->sha256_ctx);
break; break;
case SHA512_DIGEST_ALGORITHM: case SHA512_DIGEST_ALGORITHM:
digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE); digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE);
Memcpy(digest, SHA512_final(ctx->sha512_ctx), SHA512_DIGEST_SIZE); Memcpy(digest, SHA512_final(ctx->sha512_ctx), SHA512_DIGEST_SIZE);
VbExFree(ctx->sha512_ctx); Free(ctx->sha512_ctx);
break; break;
}; };
return digest; return digest;
} }
uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) { uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm) {
/* Allocate enough space for the largest digest */ uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Use the max. */
uint8_t* digest = (uint8_t*) VbExMalloc(SHA512_DIGEST_SIZE);
/* Define an array mapping [sig_algorithm] to function pointers to the /* Define an array mapping [sig_algorithm] to function pointers to the
* SHA{1|256|512} functions. * SHA{1|256|512} functions.
*/ */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010-2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -7,11 +7,11 @@
*/ */
#include "rollback_index.h" #include "rollback_index.h"
#include "tlcl.h" #include "tlcl.h"
#include "tpm_bootmode.h" #include "tpm_bootmode.h"
#include "tss_constants.h" #include "tss_constants.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
static int g_rollback_recovery_mode = 0; static int g_rollback_recovery_mode = 0;

View File

@@ -9,7 +9,6 @@
#include "tlcl.h" #include "tlcl.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
/* TPM PCR to use for storing boot mode measurements. */ /* TPM PCR to use for storing boot mode measurements. */
#define BOOT_MODE_PCR 0 #define BOOT_MODE_PCR 0

View File

@@ -19,7 +19,6 @@
#include "tlcl_internal.h" #include "tlcl_internal.h"
#include "tlcl_structures.h" #include "tlcl_structures.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
/* Sets the size field of a TPM command. */ /* Sets the size field of a TPM command. */
static INLINE void SetTpmCommandSize(uint8_t* buffer, uint32_t size) { static INLINE void SetTpmCommandSize(uint8_t* buffer, uint32_t size) {

View File

@@ -7,7 +7,6 @@
*/ */
#include "vboot_api.h"
#include "vboot_common.h" #include "vboot_common.h"
#include "utility.h" #include "utility.h"
@@ -232,7 +231,7 @@ int KeyBlockVerify(const VbKeyBlockHeader* block, uint64_t size,
SHA512_DIGEST_ALGORITHM); SHA512_DIGEST_ALGORITHM);
rv = SafeMemcmp(header_checksum, GetSignatureDataC(sig), rv = SafeMemcmp(header_checksum, GetSignatureDataC(sig),
SHA512_DIGEST_SIZE); SHA512_DIGEST_SIZE);
VbExFree(header_checksum); Free(header_checksum);
if (rv) { if (rv) {
VBDEBUG(("Invalid key block hash.\n")); VBDEBUG(("Invalid key block hash.\n"));
return VBOOT_KEY_BLOCK_HASH; return VBOOT_KEY_BLOCK_HASH;

View File

@@ -11,7 +11,6 @@
#include "rollback_index.h" #include "rollback_index.h"
#include "tpm_bootmode.h" #include "tpm_bootmode.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
#include "vboot_common.h" #include "vboot_common.h"
#include "vboot_nvstorage.h" #include "vboot_nvstorage.h"
@@ -78,7 +77,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
recovery = VBNV_RECOVERY_RO_SHARED_DATA; recovery = VBNV_RECOVERY_RO_SHARED_DATA;
goto LoadFirmwareExit; goto LoadFirmwareExit;
} }
shared->timer_load_firmware_enter = VbExGetTimer(); shared->timer_load_firmware_enter = VbGetTimer();
/* Handle test errors */ /* Handle test errors */
VbNvGet(vnc, VBNV_TEST_ERROR_FUNC, &test_err); VbNvGet(vnc, VBNV_TEST_ERROR_FUNC, &test_err);
@@ -137,7 +136,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
} }
/* Allocate our internal data */ /* Allocate our internal data */
lfi = (VbLoadFirmwareInternal*)VbExMalloc(sizeof(VbLoadFirmwareInternal)); lfi = (VbLoadFirmwareInternal*)Malloc(sizeof(VbLoadFirmwareInternal));
if (!lfi) if (!lfi)
return LOAD_FIRMWARE_RECOVERY; return LOAD_FIRMWARE_RECOVERY;
@@ -276,7 +275,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
VBDEBUG(("Firmware body verification failed.\n")); VBDEBUG(("Firmware body verification failed.\n"));
*check_result = VBSD_LF_CHECK_VERIFY_BODY; *check_result = VBSD_LF_CHECK_VERIFY_BODY;
RSAPublicKeyFree(data_key); RSAPublicKeyFree(data_key);
VbExFree(body_digest); Free(body_digest);
VBPERFEND("VB_VFD"); VBPERFEND("VB_VFD");
continue; continue;
} }
@@ -284,7 +283,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
/* Done with the digest and data key, so can free them now */ /* Done with the digest and data key, so can free them now */
RSAPublicKeyFree(data_key); RSAPublicKeyFree(data_key);
VbExFree(body_digest); Free(body_digest);
/* If we're still here, the firmware is valid. */ /* If we're still here, the firmware is valid. */
VBDEBUG(("Firmware %d is valid.\n", index)); VBDEBUG(("Firmware %d is valid.\n", index));
@@ -328,7 +327,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
} }
/* Free internal data */ /* Free internal data */
VbExFree(lfi); Free(lfi);
params->load_firmware_internal = NULL; params->load_firmware_internal = NULL;
/* Handle finding good firmware */ /* Handle finding good firmware */
@@ -391,7 +390,7 @@ LoadFirmwareExit:
recovery : VBNV_RECOVERY_NOT_REQUESTED); recovery : VBNV_RECOVERY_NOT_REQUESTED);
VbNvTeardown(vnc); VbNvTeardown(vnc);
shared->timer_load_firmware_exit = VbExGetTimer(); shared->timer_load_firmware_exit = VbGetTimer();
/* Note that we don't reduce params->shared_data_size to shared->data_used, /* Note that we don't reduce params->shared_data_size to shared->data_used,
* since we want to leave space for LoadKernel() to add to the shared data * since we want to leave space for LoadKernel() to add to the shared data

View File

@@ -6,6 +6,8 @@
* (Firmware portion) * (Firmware portion)
*/ */
#include "vboot_kernel.h"
#include "boot_device.h" #include "boot_device.h"
#include "cgptlib.h" #include "cgptlib.h"
#include "cgptlib_internal.h" #include "cgptlib_internal.h"
@@ -13,9 +15,7 @@
#include "load_kernel_fw.h" #include "load_kernel_fw.h"
#include "rollback_index.h" #include "rollback_index.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
#include "vboot_common.h" #include "vboot_common.h"
#include "vboot_kernel.h"
#define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */ #define KBUF_SIZE 65536 /* Bytes to read at start of kernel partition */
#define LOWEST_TPM_VERSION 0xffffffff #define LOWEST_TPM_VERSION 0xffffffff
@@ -40,10 +40,10 @@ int AllocAndReadGptData(GptData* gptdata) {
gptdata->modified = 0; gptdata->modified = 0;
/* Allocate all buffers */ /* Allocate all buffers */
gptdata->primary_header = (uint8_t*)VbExMalloc(gptdata->sector_bytes); gptdata->primary_header = (uint8_t*)Malloc(gptdata->sector_bytes);
gptdata->secondary_header = (uint8_t*)VbExMalloc(gptdata->sector_bytes); gptdata->secondary_header = (uint8_t*)Malloc(gptdata->sector_bytes);
gptdata->primary_entries = (uint8_t*)VbExMalloc(TOTAL_ENTRIES_SIZE); gptdata->primary_entries = (uint8_t*)Malloc(TOTAL_ENTRIES_SIZE);
gptdata->secondary_entries = (uint8_t*)VbExMalloc(TOTAL_ENTRIES_SIZE); gptdata->secondary_entries = (uint8_t*)Malloc(TOTAL_ENTRIES_SIZE);
if (gptdata->primary_header == NULL || gptdata->secondary_header == NULL || if (gptdata->primary_header == NULL || gptdata->secondary_header == NULL ||
gptdata->primary_entries == NULL || gptdata->secondary_entries == NULL) gptdata->primary_entries == NULL || gptdata->secondary_entries == NULL)
@@ -79,7 +79,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
if (0 != BootDeviceWriteLBA(1, 1, gptdata->primary_header)) if (0 != BootDeviceWriteLBA(1, 1, gptdata->primary_header))
return 1; return 1;
} }
VbExFree(gptdata->primary_header); Free(gptdata->primary_header);
} }
if (gptdata->primary_entries) { if (gptdata->primary_entries) {
@@ -89,7 +89,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
gptdata->primary_entries)) gptdata->primary_entries))
return 1; return 1;
} }
VbExFree(gptdata->primary_entries); Free(gptdata->primary_entries);
} }
if (gptdata->secondary_entries) { if (gptdata->secondary_entries) {
@@ -99,7 +99,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
entries_sectors, gptdata->secondary_entries)) entries_sectors, gptdata->secondary_entries))
return 1; return 1;
} }
VbExFree(gptdata->secondary_entries); Free(gptdata->secondary_entries);
} }
if (gptdata->secondary_header) { if (gptdata->secondary_header) {
@@ -109,7 +109,7 @@ int WriteAndFreeGptData(GptData* gptdata) {
gptdata->secondary_header)) gptdata->secondary_header))
return 1; return 1;
} }
VbExFree(gptdata->secondary_header); Free(gptdata->secondary_header);
} }
/* Success */ /* Success */
@@ -142,7 +142,7 @@ int LoadKernel(LoadKernelParams* params) {
int retval = LOAD_KERNEL_RECOVERY; int retval = LOAD_KERNEL_RECOVERY;
int recovery = VBNV_RECOVERY_RO_UNSPECIFIED; int recovery = VBNV_RECOVERY_RO_UNSPECIFIED;
uint64_t timer_enter = VbExGetTimer(); uint64_t timer_enter = VbGetTimer();
/* Setup NV storage */ /* Setup NV storage */
VbNvSetup(vnc); VbNvSetup(vnc);
@@ -300,7 +300,7 @@ int LoadKernel(LoadKernelParams* params) {
} }
/* Allocate kernel header buffers */ /* Allocate kernel header buffers */
kbuf = (uint8_t*)VbExMalloc(KBUF_SIZE); kbuf = (uint8_t*)Malloc(KBUF_SIZE);
if (!kbuf) if (!kbuf)
break; break;
@@ -585,7 +585,7 @@ int LoadKernel(LoadKernelParams* params) {
/* Free kernel buffer */ /* Free kernel buffer */
if (kbuf) if (kbuf)
VbExFree(kbuf); Free(kbuf);
/* Write and free GPT data */ /* Write and free GPT data */
WriteAndFreeGptData(&gpt); WriteAndFreeGptData(&gpt);
@@ -665,7 +665,7 @@ LoadKernelExit:
/* Save timer values */ /* Save timer values */
shared->timer_load_kernel_enter = timer_enter; shared->timer_load_kernel_enter = timer_enter;
shared->timer_load_kernel_exit = VbExGetTimer(); shared->timer_load_kernel_exit = VbGetTimer();
/* Store how much shared data we used, if any */ /* Store how much shared data we used, if any */
params->shared_data_size = shared->data_used; params->shared_data_size = shared->data_used;
} }

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -9,7 +9,6 @@
#include "load_firmware_fw.h" #include "load_firmware_fw.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
#define BOOT_FIRMWARE_A_CONTINUE 1 #define BOOT_FIRMWARE_A_CONTINUE 1
#define BOOT_FIRMWARE_B_CONTINUE 2 #define BOOT_FIRMWARE_B_CONTINUE 2
@@ -100,7 +99,7 @@ int VerifyFirmwareDriver_stub(uint8_t* gbb_data,
p.nv_context = &vnc; p.nv_context = &vnc;
/* Allocate a shared data buffer */ /* Allocate a shared data buffer */
p.shared_data_blob = VbExMalloc(VB_SHARED_DATA_REC_SIZE); p.shared_data_blob = Malloc(VB_SHARED_DATA_REC_SIZE);
p.shared_data_size = VB_SHARED_DATA_REC_SIZE; p.shared_data_size = VB_SHARED_DATA_REC_SIZE;
/* TODO: YOU NEED TO SET THE BOOT FLAGS SOMEHOW */ /* TODO: YOU NEED TO SET THE BOOT FLAGS SOMEHOW */

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. * found in the LICENSE file.
* *
@@ -10,7 +10,6 @@
#include "tlcl.h" #include "tlcl.h"
#include "tlcl_internal.h" #include "tlcl_internal.h"
#include "utility.h" #include "utility.h"
#include "vboot_api.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@@ -57,22 +56,22 @@ static void TpmExecute(const uint8_t *in, const uint32_t in_len,
uint8_t *out, uint32_t *pout_len) { uint8_t *out, uint32_t *pout_len) {
uint8_t response[TPM_MAX_COMMAND_SIZE]; uint8_t response[TPM_MAX_COMMAND_SIZE];
if (in_len <= 0) { if (in_len <= 0) {
VbExError("invalid command length %d for command 0x%x\n", in_len, in[9]); error("invalid command length %d for command 0x%x\n", in_len, in[9]);
} else if (tpm_fd < 0) { } else if (tpm_fd < 0) {
VbExError("the TPM device was not opened. Forgot to call TlclLibInit?\n"); error("the TPM device was not opened. Forgot to call TlclLibInit?\n");
} else { } else {
int n = write(tpm_fd, in, in_len); int n = write(tpm_fd, in, in_len);
if (n != in_len) { if (n != in_len) {
VbExError("write failure to TPM device: %s\n", strerror(errno)); error("write failure to TPM device: %s\n", strerror(errno));
} }
n = read(tpm_fd, response, sizeof(response)); n = read(tpm_fd, response, sizeof(response));
if (n == 0) { if (n == 0) {
VbExError("null read from TPM device\n"); error("null read from TPM device\n");
} else if (n < 0) { } else if (n < 0) {
VbExError("read failure from TPM device: %s\n", strerror(errno)); error("read failure from TPM device: %s\n", strerror(errno));
} else { } else {
if (n > *pout_len) { if (n > *pout_len) {
VbExError("TPM response too long for output buffer\n"); error("TPM response too long for output buffer\n");
} else { } else {
*pout_len = n; *pout_len = n;
Memcpy(out, response, n); Memcpy(out, response, n);
@@ -127,8 +126,7 @@ uint32_t TlclOpenDevice(void) {
tpm_fd = open(device_path, O_RDWR); tpm_fd = open(device_path, O_RDWR);
if (tpm_fd < 0) { if (tpm_fd < 0) {
VbExError("TPM: Cannot open TPM device %s: %s\n", device_path, error("TPM: Cannot open TPM device %s: %s\n", device_path, strerror(errno));
strerror(errno));
} }
return 0; return 0;

View File

@@ -15,12 +15,50 @@
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
void error(const char *format, ...) {
va_list ap;
va_start(ap, format);
fprintf(stderr, "ERROR: ");
vfprintf(stderr, format, ap);
va_end(ap);
exit(1);
}
void debug(const char *format, ...) {
va_list ap;
va_start(ap, format);
fprintf(stderr, "DEBUG: ");
vfprintf(stderr, format, ap);
va_end(ap);
}
void* Malloc(size_t size) {
void* p = malloc(size);
if (!p) {
/* Fatal Error. We must abort. */
abort();
}
return p;
}
void Free(void* ptr) {
free(ptr);
}
int Memcmp(const void* src1, const void* src2, size_t n) { int Memcmp(const void* src1, const void* src2, size_t n) {
return memcmp(src1, src2, n); return memcmp(src1, src2, n);
} }
void* Memcpy(void* dest, const void* src, uint64_t n) { void* Memcpy(void* dest, const void* src, uint64_t n) {
return memcpy(dest, src, (size_t)n); return memcpy(dest, src, (size_t)n);
} }
uint64_t VbGetTimer(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
}
uint64_t VbGetTimerMaxFreq(void) {
return UINT64_C(1000000);
}