diff --git a/Makefile b/Makefile index a9445e7ab0..15ef63813c 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ export INCLUDES = -I$(FWDIR)/include -I$(FWDIR)/stub/include export BUILD = ${TOP}/build export FWLIB = ${BUILD}/vboot_fw.a -export HOSTLIB= ${BUILD}/vboot_host.a +export HOSTLIB = ${BUILD}/vboot_host.a SUBDIRS = firmware host utility cgpt tests tests/tpm_lite diff --git a/cgpt/Makefile b/cgpt/Makefile index 3984628c91..cd503ba7df 100644 --- a/cgpt/Makefile +++ b/cgpt/Makefile @@ -7,7 +7,7 @@ LDFLAGS += -luuid BUILD_ROOT := ${BUILD}/cgpt INCLUDES = -I$(FWDIR)/lib/cgptlib/include -I$(FWDIR)/include -LIBS = ${FWLIB} +LIBS = ${HOSTLIB} DESTDIR ?= /usr/bin diff --git a/firmware/Makefile b/firmware/Makefile index 99f33f216a..ea1f183bc0 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -40,17 +40,21 @@ LIB_SRCS = \ ./lib/vboot_firmware.c \ ./lib/vboot_kernel.c +LIB_OBJS = $(LIB_SRCS:%.c=${BUILD_ROOT}/%.o) + STUB_SRCS = \ ./stub/boot_device_stub.c \ ./stub/load_firmware_stub.c \ ./stub/tpm_lite_stub.c \ ./stub/utility_stub.c +STUB_OBJS = $(STUB_SRCS:%.c=${BUILD_ROOT}/%.o) + ALL_SRCS = ${LIB_SRCS} ${STUB_SRCS} version.c -test : $(FWLIB) update-version +test : $(STUB_OBJS) $(FWLIB) update-version $(CC) $(CFLAGS) $(INCLUDES) -o $(BUILD_ROOT)/a.out \ - $(TESTDIR)/main.c $(LIBS) + $(TESTDIR)/main.c $(STUB_OBJS) $(LIBS) # This is executed at every make, to see if anything has changed update-version : @@ -65,6 +69,6 @@ update-version : include ../common.mk -$(FWLIB) : $(ALL_OBJS) +$(FWLIB) : $(LIB_OBJS) rm -f $@ ar qc $@ $^ diff --git a/firmware/include/tlcl_stub.h b/firmware/include/tlcl_stub.h new file mode 100644 index 0000000000..72582af056 --- /dev/null +++ b/firmware/include/tlcl_stub.h @@ -0,0 +1,35 @@ +/* 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. + */ + +/* TPM Lightweight Command Library. + * + * A low-level library for interfacing to TPM hardware or an emulator. + */ + +#ifndef VBOOT_REFERENCE_TLCL_STUB_H_ +#define VBOOT_REFERENCE_TLCL_STUB_H_ + +#include "sysincludes.h" +#include "tss_constants.h" + +/*****************************************************************************/ +/* Functions to be implemented by the stub library */ + +/* Initialize the stub library */ +void TlclStubInit(void); + +/* 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 + * only by one process at a time. + */ +void TlclCloseDevice(void); +void TlclOpenDevice(void); + +/* Send data to the TPM and receive a response. Returns 0 if success, + * nonzero if error. */ +uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, + uint8_t* response, int max_length); + +#endif /* VBOOT_REFERENCE_TLCL_STUB_H_ */ diff --git a/firmware/lib/tpm_lite/include/tss_constants.h b/firmware/include/tss_constants.h similarity index 95% rename from firmware/lib/tpm_lite/include/tss_constants.h rename to firmware/include/tss_constants.h index 5bbc0921fe..00a7c033a7 100644 --- a/firmware/lib/tpm_lite/include/tss_constants.h +++ b/firmware/include/tss_constants.h @@ -6,8 +6,8 @@ * the firmware */ -#ifndef TPM_LITE_TSS_CONSTANTS_H_ -#define TPM_LITE_TSS_CONSTANTS_H_ +#ifndef VBOOT_REFERENCE_TSS_CONSTANTS_H_ +#define VBOOT_REFERENCE_TSS_CONSTANTS_H_ #include "sysincludes.h" @@ -87,4 +87,4 @@ typedef struct tdTPM_STCLEAR_FLAGS{ TSS_BOOL bGlobalLock; } TPM_STCLEAR_FLAGS; -#endif /* TPM_LITE_TSS_CONSTANTS_H_ */ +#endif /* VBOOT_REFERENCE_TSS_CONSTANTS_H_ */ diff --git a/firmware/lib/tpm_lite/include/tlcl.h b/firmware/lib/tpm_lite/include/tlcl.h index 5361540121..401a3ae31c 100644 --- a/firmware/lib/tpm_lite/include/tlcl.h +++ b/firmware/lib/tpm_lite/include/tlcl.h @@ -13,24 +13,7 @@ #include "sysincludes.h" #include "tss_constants.h" - -/*****************************************************************************/ -/* Functions to be implemented by the stub library */ - -/* Initialize the stub library */ -void TlclStubInit(void); - -/* 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 - * only by one process at a time. - */ -void TlclCloseDevice(void); -void TlclOpenDevice(void); - -/* Send data to the TPM and receive a response. Returns 0 if success, - * nonzero if error. */ -uint32_t TlclStubSendReceive(const uint8_t* request, int request_length, - uint8_t* response, int max_length); +#include "tlcl_stub.h" /*****************************************************************************/ /* Functions implemented in tlcl.c */ diff --git a/host/Makefile b/host/Makefile index 29b8231ca6..763eb37837 100644 --- a/host/Makefile +++ b/host/Makefile @@ -13,7 +13,7 @@ INCLUDES += \ -I$(FWDIR)/lib/cryptolib/include # find ./lib -iname '*.c' | sort -ALL_SRCS = \ +LIB_SRCS = \ ./lib/file_keys.c \ ./lib/host_common.c \ ./lib/host_key.c \ @@ -22,12 +22,22 @@ ALL_SRCS = \ ./lib/host_signature.c \ ./lib/signature_digest.c +STUB_SRCS = \ + ../firmware/stub/boot_device_stub.c \ + ../firmware/stub/load_firmware_stub.c \ + ../firmware/stub/tpm_lite_stub.c \ + ../firmware/stub/utility_stub.c + +ALL_SRCS = ${LIB_SRCS} ${STUB_SRCS} + test : $(HOSTLIB) $(CC) $(CFLAGS) $(INCLUDES) -o $(BUILD_ROOT)/a.out $(TESTDIR)/main.c \ - $(HOSTLIB) $(FWLIB) -lcrypto + $(HOSTLIB) -lcrypto include ../common.mk -$(HOSTLIB) : $(ALL_OBJS) - rm -f $@ - ar qc $@ $^ +$(HOSTLIB) : $(ALL_OBJS) $(FWLIB) + rm -rf $@ $(BUILD_ROOT)/.tmp + mkdir -p $(BUILD_ROOT)/.tmp + cd $(BUILD_ROOT)/.tmp ; ar x $(FWLIB) + ar qc $@ $^ $(BUILD_ROOT)/.tmp/*.o diff --git a/tests/Makefile b/tests/Makefile index 1286210a74..4994bdbc72 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -27,7 +27,7 @@ TEST_LIB_OBJS = $(TEST_LIB_SRCS:%.c=${BUILD_ROOT}/%.o) ALL_DEPS = $(addsuffix .d,${TEST_BINS} ${TEST_LIB_OBJS}) CFLAGS += -MMD -MF $@.d -LIBS := ${TEST_LIB} $(HOSTLIB) $(FWLIB) +LIBS := ${TEST_LIB} $(HOSTLIB) ifneq (${RUNTESTS},) EXTRA_TARGET = runtests @@ -44,9 +44,9 @@ ${TEST_LIB}: ${TEST_LIB_OBJS} ${BUILD_ROOT}/rollback_index_test.o : rollback_index_test.c $(CC) $(CFLAGS) -I/usr/include $(INCLUDES) -MMD -MF $@.d -c -o $@ $< -${BUILD_ROOT}/rollback_index_test: rollback_index_test.c ${HOSTLIB} ${FWLIB} +${BUILD_ROOT}/rollback_index_test: rollback_index_test.c ${HOSTLIB} $(CC) $(CFLAGS) -I/usr/include $(INCLUDES) $< -o $@ \ - -ltlcl ${HOSTLIB} ${FWLIB} -lcrypto -lrt + -ltlcl ${HOSTLIB} -lcrypto -lrt ${BUILD_ROOT}/%.o : %.c $(CC) $(CFLAGS) $(INCLUDES) -MMD -MF $@.d -c -o $@ $< diff --git a/tests/tpm_lite/Makefile b/tests/tpm_lite/Makefile index 6c4250f8dc..69e67f3965 100644 --- a/tests/tpm_lite/Makefile +++ b/tests/tpm_lite/Makefile @@ -31,7 +31,7 @@ SHARED_TEST_OBJ = $(BUILD_ROOT)/tlcl_tests.o ALL_DEPS = $(addsuffix .d,${TEST_BINS}) CFLAGS += -MMD -MF $@.d -LIBS := ${TEST_LIB} $(HOSTLIB) $(FWLIB) +LIBS := ${TEST_LIB} $(HOSTLIB) all: $(TEST_BINS) diff --git a/utility/Makefile b/utility/Makefile index af25ee244e..68975840b9 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -10,7 +10,7 @@ INCLUDES += -I./include \ -I$(HOSTDIR)/include CFLAGS += $(INCLUDES) CFLAGS += -MMD -MF $@.d -LIBS = $(HOSTLIB) $(FWLIB) +LIBS = $(HOSTLIB) HOSTCC = cc BUILD_ROOT = ${BUILD}/utility