Skip to content

Commit

Permalink
Refactor and Update the tcti-x-helper
Browse files Browse the repository at this point in the history
- Moved common transmit/receive FIFO protocol code to tcti-helper-common.
- Refined the FIFO protocol implementation.
- Updated unit test implementation so that changes to the FIFO protocol
  no longer require modifications to all dependent unit tests.

Signed-off-by: wenxin.leong <[email protected]>
  • Loading branch information
wxleong committed Sep 25, 2024
1 parent f5ee2b6 commit 29712c9
Show file tree
Hide file tree
Showing 18 changed files with 3,603 additions and 2,436 deletions.
71 changes: 53 additions & 18 deletions Makefile-test.am
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ endif
if ENABLE_TCTI_CMD
TESTS_UNIT += test/unit/tcti-cmd
endif
if ENABLE_TCTI_HELPER_COMMON
TESTS_UNIT += test/unit/tcti-helper-common
endif
if ENABLE_TCTI_SPI_HELPER
TESTS_UNIT += test/unit/tcti-spi-helper
endif
Expand Down Expand Up @@ -531,16 +534,30 @@ test_unit_tcti_cmd_SOURCES = test/unit/tcti-cmd.c \
test/helper/cmocka_all.h
endif

if ENABLE_TCTI_HELPER_COMMON
test_unit_tcti_helper_common_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_helper_common_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_helper_common) $(libtss2_mu) $(libutil)
test_unit_tcti_helper_common_SOURCES = test/unit/tcti-helper-common.c \
src/tss2-tcti/tcti-common.c \
test/helper/cmocka_all.h
endif

if ENABLE_TCTI_SPI_HELPER
test_unit_tcti_spi_helper_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_spi_helper_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_spi_helper)
test_unit_tcti_spi_helper_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil)
test_unit_tcti_spi_helper_LDFLAGS = -Wl,--wrap=Tss2_Tcti_Helper_Common_Init \
-Wl,--wrap=Tss2_Tcti_Helper_Common_Transmit \
-Wl,--wrap=Tss2_Tcti_Helper_Common_Receive
test_unit_tcti_spi_helper_SOURCES = test/unit/tcti-spi-helper.c \
test/helper/cmocka_all.h
test/helper/cmocka_all.h \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-helper-common.h \
src/tss2-tcti/tcti-spi-helper.c
endif

if ENABLE_TCTI_SPI_LTT2GO
test_unit_tcti_spi_ltt2go_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_spi_ltt2go_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_spi_helper)
test_unit_tcti_spi_ltt2go_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil)
test_unit_tcti_spi_ltt2go_LDFLAGS = -Wl,--wrap=libusb_bulk_transfer \
-Wl,--wrap=libusb_claim_interface \
-Wl,--wrap=libusb_open \
Expand All @@ -560,49 +577,63 @@ test_unit_tcti_spi_ltt2go_LDFLAGS = -Wl,--wrap=libusb_bulk_transfer \
-Wl,--wrap=libusb_set_auto_detach_kernel_driver \
-Wl,--wrap=libusb_strerror \
-Wl,--wrap=select \
-Wl,--wrap=gettimeofday
-Wl,--wrap=gettimeofday \
-Wl,--wrap=Tss2_Tcti_Spi_Helper_Init
test_unit_tcti_spi_ltt2go_SOURCES = test/unit/tcti-spi-ltt2go.c \
src/tss2-tcti/tcti-spi-ltt2go.c test/helper/cmocka_all.h
test/helper/cmocka_all.h \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-spi-helper.h \
src/tss2-tcti/tcti-spi-ltt2go.c
endif

if ENABLE_TCTI_SPIDEV
test_unit_tcti_spidev_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_spidev_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_spi_helper)
test_unit_tcti_spidev_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil)
test_unit_tcti_spidev_LDFLAGS = -Wl,--wrap=open \
-Wl,--wrap=close \
-Wl,--wrap=ioctl \
-Wl,--wrap=select \
-Wl,--wrap=gettimeofday
-Wl,--wrap=gettimeofday \
-Wl,--wrap=Tss2_Tcti_Spi_Helper_Init
test_unit_tcti_spidev_SOURCES = test/unit/tcti-spidev.c \
src/tss2-tcti/tcti-spidev.c test/helper/cmocka_all.h
src/tss2-tcti/tcti-spidev.c test/helper/cmocka_all.h \
src/tss2-tcti/tcti-common.c src/tss2-tcti/tcti-spi-helper.h
endif

if ENABLE_TCTI_SPI_FTDI
test_unit_tcti_spi_ftdi_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_spi_ftdi_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_spi_helper)
test_unit_tcti_spi_ftdi_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil)
test_unit_tcti_spi_ftdi_LDFLAGS = -Wl,--wrap=Close \
-Wl,--wrap=MPSSE \
-Wl,--wrap=PinHigh \
-Wl,--wrap=PinLow \
-Wl,--wrap=Start \
-Wl,--wrap=Stop \
-Wl,--wrap=Transfer \
-Wl,--wrap=select \
-Wl,--wrap=gettimeofday
-Wl,--wrap=gettimeofday \
-Wl,--wrap=Tss2_Tcti_Spi_Helper_Init
test_unit_tcti_spi_ftdi_SOURCES = test/unit/tcti-spi-ftdi.c \
src/tss2-tcti/tcti-spi-ftdi.c test/helper/cmocka_all.h
test/helper/cmocka_all.h \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-spi-helper.h \
src/tss2-tcti/tcti-spi-ftdi.c
endif

if ENABLE_TCTI_I2C_HELPER
test_unit_tcti_i2c_helper_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_i2c_helper_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_i2c_helper)
test_unit_tcti_i2c_helper_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil)
test_unit_tcti_i2c_helper_LDFLAGS = -Wl,--wrap=Tss2_Tcti_Helper_Common_Init \
-Wl,--wrap=Tss2_Tcti_Helper_Common_Transmit \
-Wl,--wrap=Tss2_Tcti_Helper_Common_Receive
test_unit_tcti_i2c_helper_SOURCES = test/unit/tcti-i2c-helper.c \
test/helper/cmocka_all.h
test/helper/cmocka_all.h \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-helper-common.h \
src/tss2-tcti/tcti-i2c-helper.c
endif

if ENABLE_TCTI_I2C_FTDI
test_unit_tcti_i2c_ftdi_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
test_unit_tcti_i2c_ftdi_LDADD = $(CMOCKA_LIBS) $(libtss2_tcti_i2c_helper)
test_unit_tcti_i2c_ftdi_LDADD = $(CMOCKA_LIBS) $(libtss2_mu) $(libutil)
test_unit_tcti_i2c_ftdi_LDFLAGS = -Wl,--wrap=MPSSE \
-Wl,--wrap=Start \
-Wl,--wrap=Stop \
Expand All @@ -613,9 +644,13 @@ test_unit_tcti_i2c_ftdi_LDFLAGS = -Wl,--wrap=MPSSE \
-Wl,--wrap=SendAcks \
-Wl,--wrap=SendNacks \
-Wl,--wrap=select \
-Wl,--wrap=gettimeofday
-Wl,--wrap=gettimeofday \
-Wl,--wrap=Tss2_Tcti_I2c_Helper_Init
test_unit_tcti_i2c_ftdi_SOURCES = test/unit/tcti-i2c-ftdi.c \
src/tss2-tcti/tcti-i2c-ftdi.c test/helper/cmocka_all.h
test/helper/cmocka_all.h \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-i2c-helper.h \
src/tss2-tcti/tcti-i2c-ftdi.c
endif

test_unit_tctildr_CFLAGS = $(CMOCKA_CFLAGS) $(TESTS_CFLAGS)
Expand Down
11 changes: 9 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ endif # ENABLE_TCTI_CMD
EXTRA_DIST += lib/tss2-tcti-cmd.map \
lib/tss2-tcti-cmd.def

if ENABLE_TCTI_HELPER_COMMON
libtss2_tcti_helper_common = src/tss2-tcti/libtss2-tcti-helper-common.la
noinst_LTLIBRARIES += $(libtss2_tcti_helper_common)
src_tss2_tcti_libtss2_tcti_helper_common_la_SOURCES = \
src/tss2-tcti/tcti-helper-common.c
endif

# tcti library for spi connected tpms
if ENABLE_TCTI_SPI_HELPER
libtss2_tcti_spi_helper = src/tss2-tcti/libtss2-tcti-spi-helper.la
Expand All @@ -434,7 +441,7 @@ if !UNIT
src_tss2_tcti_libtss2_tcti_spi_helper_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-spi-helper.map
endif # UNIT
endif # HAVE_LD_VERSION_SCRIPT
src_tss2_tcti_libtss2_tcti_spi_helper_la_LIBADD = $(libutil) $(libtss2_mu)
src_tss2_tcti_libtss2_tcti_spi_helper_la_LIBADD = $(libutil) $(libtss2_mu) $(libtss2_tcti_helper_common)
src_tss2_tcti_libtss2_tcti_spi_helper_la_SOURCES = \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-spi-helper.c \
Expand Down Expand Up @@ -521,7 +528,7 @@ if !UNIT
src_tss2_tcti_libtss2_tcti_i2c_helper_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-i2c-helper.map
endif # UNIT
endif # HAVE_LD_VERSION_SCRIPT
src_tss2_tcti_libtss2_tcti_i2c_helper_la_LIBADD = $(libutil) $(libtss2_mu)
src_tss2_tcti_libtss2_tcti_i2c_helper_la_LIBADD = $(libutil) $(libtss2_mu) $(libtss2_tcti_helper_common)
src_tss2_tcti_libtss2_tcti_i2c_helper_la_SOURCES = \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-i2c-helper.c \
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ AM_CONDITIONAL([ENABLE_TCTI_I2C_FTDI], [test "x$enable_tcti_i2c_ftdi" != xno])
AS_IF([test "x$enable_tcti_i2c_ftdi" = "xyes"],
AC_DEFINE([TCTI_I2C_FTDI],[1], [TCTI FOR USB BASED ACCESS TO I2C BASED TPM OVER THE FTDI MPSSE USB TO I2C BRIDGE]))

AM_CONDITIONAL([ENABLE_TCTI_HELPER_COMMON],
[test "x$enable_tcti_spi_helper" = "xyes" || test "x$enable_tcti_i2c_helper" = "xyes"])

AC_ARG_ENABLE([tcti-fuzzing],
[AS_HELP_STRING([--enable-tcti-fuzzing],
[build the tcti-fuzzing module])],,
Expand Down
Loading

0 comments on commit 29712c9

Please sign in to comment.