summaryrefslogtreecommitdiff
path: root/firmware/stub
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2010-06-17 14:45:22 -0700
committerRandall Spangler <rspangler@chromium.org>2010-06-17 14:45:22 -0700
commit620c38cf34eadcd222535b01fb71c5e9fbc1cb80 (patch)
tree55c883fd01447b0ffdf6c121f4b7c6817cbc53b0 /firmware/stub
parentd52030f340d14f8039360a39ec6a938d31e083d0 (diff)
downloadvboot-620c38cf34eadcd222535b01fb71c5e9fbc1cb80.tar.gz
Remove unused files, and tidy the directory structure of the remaining ones.
Review URL: http://codereview.chromium.org/2815011
Diffstat (limited to 'firmware/stub')
-rw-r--r--firmware/stub/boot_device_stub.c17
-rw-r--r--firmware/stub/load_firmware_stub.c104
-rw-r--r--firmware/stub/tlcl.c38
-rw-r--r--firmware/stub/utility_stub.c72
4 files changed, 231 insertions, 0 deletions
diff --git a/firmware/stub/boot_device_stub.c b/firmware/stub/boot_device_stub.c
new file mode 100644
index 00000000..c7bb86f5
--- /dev/null
+++ b/firmware/stub/boot_device_stub.c
@@ -0,0 +1,17 @@
+/* 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
+ * found in the LICENSE file.
+ *
+ * Stub implementations of boot device functions.
+ */
+
+#include "boot_device.h"
+
+int BootDeviceReadLBA(uint64_t lba_start, uint64_t lba_count, void *buffer) {
+ return 1;
+}
+
+int BootDeviceWriteLBA(uint64_t lba_start, uint64_t lba_count,
+ const void *buffer) {
+ return 1;
+}
diff --git a/firmware/stub/load_firmware_stub.c b/firmware/stub/load_firmware_stub.c
new file mode 100644
index 00000000..9453856a
--- /dev/null
+++ b/firmware/stub/load_firmware_stub.c
@@ -0,0 +1,104 @@
+/* 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
+ * found in the LICENSE file.
+ *
+ * TEMPORARY stub for calling LoadFirmware() which looks like the old
+ * VerifyFirmwareDriver_f() call.
+ * (Firmware portion)
+ */
+
+#include "load_firmware_fw.h"
+#include "utility.h"
+
+#define BOOT_FIRMWARE_A_CONTINUE 1
+#define BOOT_FIRMWARE_B_CONTINUE 2
+#define BOOT_FIRMWARE_RECOVERY_CONTINUE 3
+
+typedef struct CallerInternal {
+ uint8_t *firmwareA;
+ uint64_t firmwareA_size;
+ uint8_t *firmwareB;
+ uint64_t firmwareB_size;
+} CallerInternal;
+
+int GetFirmwareBody(LoadFirmwareParams* params, uint64_t index) {
+
+ CallerInternal* ci = (CallerInternal*)params->caller_internal;
+ uint8_t *fw;
+ uint64_t size;
+
+ /* In a real implementation, GetFirmwareBody() should be what reads
+ * and decompresses the firmware volume. In this temporary hack, we
+ * just pass the pointer which we got from
+ * VerifyFirmwareDriver_Stub(). */
+ switch(index) {
+ case 0:
+ size = ci->firmwareA_size;
+ fw = ci->firmwareA;
+ case 1:
+ size = ci->firmwareB_size;
+ fw = ci->firmwareB;
+ default:
+ /* Anything else is invalid */
+ return 1;
+ }
+
+ /* Need to call UpdateFirmwareBodyHash() with the firmware volume
+ * data. In this temporary hack, the FV is already decompressed, so
+ * we pass in the entire volume at once. In a real implementation,
+ * you should call this as the FV is being decompressed. */
+ UpdateFirmwareBodyHash(params, fw, size);
+
+ /* Success */
+ return 0;
+}
+
+
+/* Where you're currently calling VerifyFirmwareDriver_f(), call this
+ * function instead. Because you still need to read in both firmware
+ * volumes, this call will still be slow. Once we reach feature
+ * complete, you should modify your code to call LoadImage()
+ * directly. */
+int VerifyFirmwareDriver_stub(uint8_t* root_key_blob,
+ uint8_t* verification_headerA,
+ uint8_t* firmwareA,
+ uint8_t* verification_headerB,
+ uint8_t* firmwareB) {
+
+ int rv;
+
+ CallerInternal ci;
+
+ /* Copy the firmware volume pointers to our global variables. */
+ ci.firmwareA = firmwareA;
+ ci.firmwareB = firmwareB;
+
+ /* TODO: YOU NEED TO PASS IN THE FIRMWARE VOLUME SIZES SOMEHOW */
+ ci.firmwareA_size = 0;
+ ci.firmwareB_size = 0;
+
+ /* Set up the params for LoadFirmware() */
+ LoadFirmwareParams p;
+ p.caller_internal = &ci;
+ p.firmware_root_key_blob = root_key_blob;
+ p.verification_block_0 = verification_headerA;
+ p.verification_block_1 = verification_headerB;
+
+ /* Allocate a key blob buffer */
+ p.kernel_sign_key_blob = Malloc(LOAD_FIRMWARE_KEY_BLOB_REC_SIZE);
+ p.kernel_sign_key_size = LOAD_FIRMWARE_KEY_BLOB_REC_SIZE;
+
+ /* Call LoadFirmware() */
+ rv = LoadFirmware(&p);
+ if (LOAD_FIRMWARE_SUCCESS == rv) {
+ /* TODO: YOU NEED TO KEEP TRACK OF p.kernel_sign_key_blob AND
+ * p.kernel_sign_key_size SO YOU CAN PASS THEM TO LoadKernel(). */
+
+ return (0 == p.firmware_index ? BOOT_FIRMWARE_A_CONTINUE :
+ BOOT_FIRMWARE_B_CONTINUE);
+
+ } else {
+ /* Error */
+ return BOOT_FIRMWARE_RECOVERY_CONTINUE;
+ }
+}
diff --git a/firmware/stub/tlcl.c b/firmware/stub/tlcl.c
new file mode 100644
index 00000000..23f0f09a
--- /dev/null
+++ b/firmware/stub/tlcl.c
@@ -0,0 +1,38 @@
+/* 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
+ * found in the LICENSE file.
+ *
+ * Stub implementations of TPM Lite Library.
+ */
+
+#include "tss_constants.h"
+
+void TlclLibInit(void) { return; }
+uint32_t TlclStartup(void) { return TPM_SUCCESS; }
+uint32_t TlclSelftestfull(void) { return TPM_SUCCESS; }
+uint32_t TlclContinueSelfTest(void) { return TPM_SUCCESS; }
+uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size) {
+ return TPM_SUCCESS;
+}
+uint32_t TlclWrite(uint32_t index, uint8_t *data, uint32_t length) {
+ return TPM_SUCCESS;
+}
+uint32_t TlclRead(uint32_t index, uint8_t *data, uint32_t length) {
+ return TPM_SUCCESS;
+}
+uint32_t TlclWriteLock(uint32_t index) { return TPM_SUCCESS; }
+uint32_t TlclReadLock(uint32_t index) { return TPM_SUCCESS; }
+uint32_t TlclAssertPhysicalPresence(void) { return TPM_SUCCESS; }
+uint32_t TlclLockPhysicalPresence(void) { return TPM_SUCCESS; }
+uint32_t TlclSetNvLocked(void) { return TPM_SUCCESS; }
+int TlclIsOwned(void) { return TPM_SUCCESS; }
+uint32_t TlclForceClear(void) { return TPM_SUCCESS; }
+uint32_t TlclSetEnable(void) { return TPM_SUCCESS; }
+uint32_t TlclSetDeactivated(int deactivated) { return TPM_SUCCESS; }
+uint32_t TlclSetGlobalLock(void) { return TPM_SUCCESS; }
+uint32_t TlclGetFlags(uint8_t* disable, uint8_t* deactivated) {
+ return TPM_SUCCESS;
+}
+uint32_t TlclGetPermissions(uint32_t index, uint32_t* permissions) {
+ return TPM_SUCCESS;
+}
diff --git a/firmware/stub/utility_stub.c b/firmware/stub/utility_stub.c
new file mode 100644
index 00000000..a41e3a3d
--- /dev/null
+++ b/firmware/stub/utility_stub.c
@@ -0,0 +1,72 @@
+/* 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
+ * found in the LICENSE file.
+ *
+ * Stub implementations of utility functions which call their linux-specific
+ * equivalents.
+ */
+
+#define _STUB_IMPLEMENTATION_
+#include "utility.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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, "WARNING: ");
+ 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, size_t n) {
+ return memcpy(dest, src, n);
+}
+
+void* Memset(void* dest, const uint8_t c, size_t n) {
+ while (n--) {
+ *((uint8_t*)dest++) = c;
+ }
+ return dest;
+}
+
+int SafeMemcmp(const void* s1, const void* s2, size_t n) {
+ int match = 0;
+ const unsigned char* us1 = s1;
+ const unsigned char* us2 = s2;
+ while (n--) {
+ if (*us1++ != *us2++)
+ match = 1;
+ }
+
+ return match;
+}