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-07-01 14:33:12 -0700
commitf8c65491595a8e849cf61b600b2371357ec75ff4 (patch)
tree511bc844457c2cb299f29ef428d7f5933be5e35d /firmware/stub
parenta7a879e0fbada0dd148781dfe325f4c7dc09c31b (diff)
downloadvboot-f8c65491595a8e849cf61b600b2371357ec75ff4.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.) This is a re-commit of the original; I've verified it compiles on both x86-alex and tegra2, for both vboot_reference and vboot_reference-firmware, now that the patch from 1c1a883bc746a6216bb634825d33d80562853020 is checked in. BUG=chromium-os:17006 TEST=make && make runtests, and emerged on both x86-alex and tegra2 Original-Change-Id: I771085dcdf79d9592de64f35e3b758111a80dd9f Original-Reviewed-on: http://gerrit.chromium.org/gerrit/3263 Original-Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org> (cherry picked from commit bd81b3a7d3b7fe4ca6179ade665e565800ab17fc) Change-Id: Iefdbfb3d10eb9aa385fb6dfc3bf0896f637cb64b Reviewed-on: http://gerrit.chromium.org/gerrit/3582 Reviewed-by: Bill Richardson <wfrichar@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);
-}