summaryrefslogtreecommitdiff
path: root/firmware/stub
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2011-06-27 13:57:28 -0700
committerRandall Spangler <rspangler@chromium.org>2011-06-27 14:57:50 -0700
commitbd81b3a7d3b7fe4ca6179ade665e565800ab17fc (patch)
treeb00cfcca6c31901b205adbec04df7a449c4720fd /firmware/stub
parent32a6526d25d4bf9a1c137fc3d275d1c68935d184 (diff)
downloadvboot-bd81b3a7d3b7fe4ca6179ade665e565800ab17fc.tar.gz
Verified boot wrapper - replace utility functions
This is part 3 of the vboot wrapper API refactoring. It replaces the function calls to utility.c functions with new API calls. (It also fixes up some integer type mismatches in cryptolib that were causing warnings on the H2C build; those had been fixed a while ago in H2C but hadn't been propagated across.) BUG=chromium-os:17006 TEST=make && make runtests Change-Id: I771085dcdf79d9592de64f35e3b758111a80dd9f Reviewed-on: http://gerrit.chromium.org/gerrit/3263 Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'firmware/stub')
-rw-r--r--firmware/stub/load_firmware_stub.c5
-rw-r--r--firmware/stub/tpm_lite_stub.c18
-rw-r--r--firmware/stub/utility_stub.c40
3 files changed, 14 insertions, 49 deletions
diff --git a/firmware/stub/load_firmware_stub.c b/firmware/stub/load_firmware_stub.c
index 26ce3d50..bdae981c 100644
--- a/firmware/stub/load_firmware_stub.c
+++ b/firmware/stub/load_firmware_stub.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -9,6 +9,7 @@
#include "load_firmware_fw.h"
#include "utility.h"
+#include "vboot_api.h"
#define BOOT_FIRMWARE_A_CONTINUE 1
#define BOOT_FIRMWARE_B_CONTINUE 2
@@ -99,7 +100,7 @@ int VerifyFirmwareDriver_stub(uint8_t* gbb_data,
p.nv_context = &vnc;
/* Allocate a shared data buffer */
- p.shared_data_blob = Malloc(VB_SHARED_DATA_REC_SIZE);
+ p.shared_data_blob = VbExMalloc(VB_SHARED_DATA_REC_SIZE);
p.shared_data_size = VB_SHARED_DATA_REC_SIZE;
/* TODO: YOU NEED TO SET THE BOOT FLAGS SOMEHOW */
diff --git a/firmware/stub/tpm_lite_stub.c b/firmware/stub/tpm_lite_stub.c
index ddb5d222..0317f933 100644
--- a/firmware/stub/tpm_lite_stub.c
+++ b/firmware/stub/tpm_lite_stub.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -10,6 +10,7 @@
#include "tlcl.h"
#include "tlcl_internal.h"
#include "utility.h"
+#include "vboot_api.h"
#include <errno.h>
#include <fcntl.h>
@@ -56,22 +57,22 @@ static void TpmExecute(const uint8_t *in, const uint32_t in_len,
uint8_t *out, uint32_t *pout_len) {
uint8_t response[TPM_MAX_COMMAND_SIZE];
if (in_len <= 0) {
- error("invalid command length %d for command 0x%x\n", in_len, in[9]);
+ VbExError("invalid command length %d for command 0x%x\n", in_len, in[9]);
} else if (tpm_fd < 0) {
- error("the TPM device was not opened. Forgot to call TlclLibInit?\n");
+ VbExError("the TPM device was not opened. Forgot to call TlclLibInit?\n");
} else {
int n = write(tpm_fd, in, in_len);
if (n != in_len) {
- error("write failure to TPM device: %s\n", strerror(errno));
+ VbExError("write failure to TPM device: %s\n", strerror(errno));
}
n = read(tpm_fd, response, sizeof(response));
if (n == 0) {
- error("null read from TPM device\n");
+ VbExError("null read from TPM device\n");
} else if (n < 0) {
- error("read failure from TPM device: %s\n", strerror(errno));
+ VbExError("read failure from TPM device: %s\n", strerror(errno));
} else {
if (n > *pout_len) {
- error("TPM response too long for output buffer\n");
+ VbExError("TPM response too long for output buffer\n");
} else {
*pout_len = n;
Memcpy(out, response, n);
@@ -126,7 +127,8 @@ uint32_t TlclOpenDevice(void) {
tpm_fd = open(device_path, O_RDWR);
if (tpm_fd < 0) {
- error("TPM: Cannot open TPM device %s: %s\n", device_path, strerror(errno));
+ VbExError("TPM: Cannot open TPM device %s: %s\n", device_path,
+ strerror(errno));
}
return 0;
diff --git a/firmware/stub/utility_stub.c b/firmware/stub/utility_stub.c
index 2d56f72b..489b0f72 100644
--- a/firmware/stub/utility_stub.c
+++ b/firmware/stub/utility_stub.c
@@ -15,50 +15,12 @@
#include <string.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) {
return memcmp(src1, src2, n);
}
+
void* Memcpy(void* dest, const void* src, uint64_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);
-}