diff --git a/CMakeLists.txt b/CMakeLists.txt index b77a9df..b5e0c8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,8 +35,10 @@ set(TPM_SOURCES src/tpm2_tis.c src/tpm2_winapi.c src/tpm2_wrap.c + hal/tpm_io.c ) + # default to build shared library option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON) add_library(wolftpm ${TPM_SOURCES}) @@ -157,7 +159,6 @@ endif() if (WOLFTPM_EXAMPLES) add_library(tpm_test_lib STATIC - examples/tpm_io.c examples/tpm_test_keys.c ) target_link_libraries(tpm_test_lib wolftpm) diff --git a/Makefile.am b/Makefile.am index cd0a612..08716de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ include certs/include.am include tests/include.am include docs/include.am include wrapper/include.am +include hal/include.am EXTRA_DIST+= README.md EXTRA_DIST+= ChangeLog.md diff --git a/README.md b/README.md index 524c6d2..be9566c 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,15 @@ Acronyms: The examples in this library are written for use on a Raspberry Pi and use the `spi_dev` interface. -### IO Callback +### IO Callback (HAL) -For interfacing to your hardware platform see the example `examples/tpm_io.c` callback function `TPM2_IoCb`. Here you can modify or insert your own IO callback code for the TPM demo. +See the HAL manual in [`hal/README.md] (hal/README.md). -There are examples here for Linux, STM32 CubeMX, Atmel ASF, Xilinx, Infineon TriCore and BareBox. +For interfacing to your hardware interface (SPI/I2C) a single HAL callback is used and configuration on initialization when calling `TPM2_Init` or `wolfTPM2_Init`. -The advanced IO option (`--enable-advio`/`WOLFTPM_ADV_IO`) is required for I2C support because it adds the register and read/write flag as parameter to the IO callback. +There are HAL examples in `hal` directory for Linux, STM32 CubeMX, Atmel ASF, Xilinx, Infineon TriCore and BareBox. + +We also support an advanced IO option (`--enable-advio`/`WOLFTPM_ADV_IO`), which adds the register and read/write flag as parameter to the IO callback. This is required for I2C support. ### Hardware diff --git a/configure.ac b/configure.ac index 1f6de94..02cc9f4 100644 --- a/configure.ac +++ b/configure.ac @@ -387,6 +387,18 @@ then fi +# Example HAL implementations +AC_ARG_ENABLE([hal], + [AS_HELP_STRING([--enable-hal],[Enable example HAL interfaces (default: enabled)])], + [ ENABLED_EXAMPLE_HAL=$enableval ], + [ ENABLED_EXAMPLE_HAL=yes ] + ) +if test "x$ENABLED_EXAMPLE_HAL" = "xyes" +then + AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_EXAMPLE_HAL" +fi + + # TIS / SPI Check Wait State support # Required for all but Infineon only if test "x$ENABLED_CHECKWAITSTATE" = "xyes" || test "x$ENABLED_AUTODETECT" = "xyes" || test "x$ENABLED_INFINEON" = "xno" @@ -418,7 +430,7 @@ AM_CONDITIONAL([BUILD_WINAPI], [test "x$ENABLED_WINAPI" = "xyes"]) AM_CONDITIONAL([BUILD_NUVOTON], [test "x$ENABLED_NUVOTON" = "xyes"]) AM_CONDITIONAL([BUILD_CHECKWAITSTATE], [test "x$ENABLED_CHECKWAITSTATE" = "xyes"]) AM_CONDITIONAL([BUILD_AUTODETECT], [test "x$ENABLED_AUTODETECT" = "xyes"]) - +AM_CONDITIONAL([BUILD_HAL], [test "x$ENABLED_EXAMPLE_HAL" = "xyes"]) CREATE_HEX_VERSION diff --git a/docs/README.md b/docs/README.md index 44055b8..7f8b8ca 100644 --- a/docs/README.md +++ b/docs/README.md @@ -66,7 +66,7 @@ For detailed build instructions see [/README.md](/README.md#building). The wolfTPM library has TPM 2.0 wrapper tests, native tests, and a sample benchmark application that come ready-to-use after a successful installation of wolfTPM. Below are some instructions on how to run the sample applications yourself. -To interface with the hardware platform that is running these applications, please see the function "TPM2_IoCb" inside of examples/tpm_io.c. +To interface with the hardware platform that is running these applications, please see the function `TPM2_IoCb` inside of `hal/tpm_io.c`. ### Examples @@ -91,7 +91,7 @@ The general header files that should be included from wolfTPM is shown below: ### Example Design -Every example application that is included with wolfTPM includes the `tpm_io.h` header file, located in `/examples`. +Every example application that is included with wolfTPM includes the `tpm_io.h` header file, located in `/hal`. The `tpm_io.c` file sets up the example HAL IO callback necessary for testing and running the example applications with a Linux Kernel, STM32 CubeMX HAL or Atmel/Microchip ASF. The reference is easily modified, such that custom IO callbacks or different callbacks may be added or removed as desired. diff --git a/examples/attestation/include.am b/examples/attestation/include.am index 6d28907..ba7484f 100644 --- a/examples/attestation/include.am +++ b/examples/attestation/include.am @@ -8,13 +8,11 @@ noinst_PROGRAMS += examples/attestation/make_credential \ noinst_HEADERS += examples/attestation/credential.h examples_attestation_make_credential_SOURCES = examples/attestation/make_credential.c \ - examples/tpm_io.c \ examples/tpm_test_keys.c examples_attestation_make_credential_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_attestation_make_credential_DEPENDENCIES = src/libwolftpm.la examples_attestation_activate_credential_SOURCES = examples/attestation/activate_credential.c \ - examples/tpm_io.c \ examples/tpm_test_keys.c examples_attestation_activate_credential_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_attestation_activate_credential_DEPENDENCIES = src/libwolftpm.la diff --git a/examples/bench/include.am b/examples/bench/include.am index d762f27..eb7fca2 100644 --- a/examples/bench/include.am +++ b/examples/bench/include.am @@ -5,7 +5,6 @@ if BUILD_EXAMPLES noinst_PROGRAMS += examples/bench/bench noinst_HEADERS += examples/bench/bench.h examples_bench_bench_SOURCES = examples/bench/bench.c \ - examples/tpm_io.c \ examples/tpm_test_keys.c examples_bench_bench_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_bench_bench_DEPENDENCIES = src/libwolftpm.la diff --git a/examples/csr/include.am b/examples/csr/include.am index 649aac0..17e072d 100644 --- a/examples/csr/include.am +++ b/examples/csr/include.am @@ -5,8 +5,7 @@ if BUILD_EXAMPLES noinst_PROGRAMS += examples/csr/csr noinst_HEADERS += examples/csr/csr.h examples_csr_csr_SOURCES = examples/csr/csr.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_csr_csr_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_csr_csr_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/gpio/include.am b/examples/gpio/include.am index 06fdd6e..a716dd1 100644 --- a/examples/gpio/include.am +++ b/examples/gpio/include.am @@ -8,18 +8,15 @@ noinst_PROGRAMS += examples/gpio/gpio_config \ noinst_HEADERS += examples/gpio/gpio.h -examples_gpio_gpio_config_SOURCES = examples/gpio/gpio_config.c \ - examples/tpm_io.c +examples_gpio_gpio_config_SOURCES = examples/gpio/gpio_config.c examples_gpio_gpio_config_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_gpio_gpio_config_DEPENDENCIES = src/libwolftpm.la -examples_gpio_gpio_read_SOURCES = examples/gpio/gpio_read.c \ - examples/tpm_io.c +examples_gpio_gpio_read_SOURCES = examples/gpio/gpio_read.c examples_gpio_gpio_read_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_gpio_gpio_read_DEPENDENCIES = src/libwolftpm.la -examples_gpio_gpio_set_SOURCES = examples/gpio/gpio_set.c \ - examples/tpm_io.c +examples_gpio_gpio_set_SOURCES = examples/gpio/gpio_set.c examples_gpio_gpio_set_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_gpio_gpio_set_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/include.am b/examples/include.am index a671e71..3781e0f 100644 --- a/examples/include.am +++ b/examples/include.am @@ -17,16 +17,6 @@ include examples/seal/include.am include examples/attestation/include.am dist_example_DATA+= examples/README.md \ - examples/tpm_io.c \ - examples/tpm_io_atmel.c \ - examples/tpm_io_barebox.c \ - examples/tpm_io_linux.c \ - examples/tpm_io_infineon.c \ - examples/tpm_io_microchip.c \ - examples/tpm_io_st.c \ - examples/tpm_io_qnx.c \ - examples/tpm_io_xilinx.c \ - examples/tpm_io.h \ examples/tpm_test_keys.c \ examples/tpm_test_keys.h \ examples/tpm_test.h diff --git a/examples/keygen/include.am b/examples/keygen/include.am index 7061f74..b3b40ae 100644 --- a/examples/keygen/include.am +++ b/examples/keygen/include.am @@ -6,29 +6,25 @@ noinst_HEADERS += examples/keygen/keygen.h noinst_PROGRAMS += examples/keygen/create_primary examples_keygen_create_primary_SOURCES = examples/keygen/create_primary.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_keygen_create_primary_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_keygen_create_primary_DEPENDENCIES = src/libwolftpm.la noinst_PROGRAMS += examples/keygen/keyload examples_keygen_keyload_SOURCES = examples/keygen/keyload.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_keygen_keyload_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_keygen_keyload_DEPENDENCIES = src/libwolftpm.la noinst_PROGRAMS += examples/keygen/keygen examples_keygen_keygen_SOURCES = examples/keygen/keygen.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_keygen_keygen_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_keygen_keygen_DEPENDENCIES = src/libwolftpm.la noinst_PROGRAMS += examples/keygen/keyimport examples_keygen_keyimport_SOURCES = examples/keygen/keyimport.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_keygen_keyimport_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_keygen_keyimport_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/management/include.am b/examples/management/include.am index edf8fba..032337f 100644 --- a/examples/management/include.am +++ b/examples/management/include.am @@ -6,8 +6,7 @@ noinst_PROGRAMS += examples/management/flush noinst_HEADERS += examples/management/flush.h -examples_management_flush_SOURCES = examples/management/flush.c \ - examples/tpm_io.c +examples_management_flush_SOURCES = examples/management/flush.c examples_management_flush_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_management_flush_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/native/include.am b/examples/native/include.am index 728083d..191bc87 100644 --- a/examples/native/include.am +++ b/examples/native/include.am @@ -4,8 +4,7 @@ if BUILD_EXAMPLES noinst_PROGRAMS += examples/native/native_test noinst_HEADERS += examples/native/native_test.h -examples_native_native_test_SOURCES = examples/native/native_test.c \ - examples/tpm_io.c +examples_native_native_test_SOURCES = examples/native/native_test.c examples_native_native_test_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_native_native_test_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/nvram/include.am b/examples/nvram/include.am index e0b47aa..1efaf04 100644 --- a/examples/nvram/include.am +++ b/examples/nvram/include.am @@ -6,22 +6,19 @@ noinst_HEADERS += examples/nvram/nvram.h noinst_PROGRAMS += examples/nvram/store examples_nvram_store_SOURCES = examples/nvram/store.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_nvram_store_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_nvram_store_DEPENDENCIES = src/libwolftpm.la noinst_PROGRAMS += examples/nvram/read examples_nvram_read_SOURCES = examples/nvram/read.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_nvram_read_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_nvram_read_DEPENDENCIES = src/libwolftpm.la noinst_PROGRAMS += examples/nvram/counter examples_nvram_counter_SOURCES = examples/nvram/counter.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_nvram_counter_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_nvram_counter_DEPENDENCIES = src/libwolftpm.la diff --git a/examples/pcr/include.am b/examples/pcr/include.am index e847ff0..1905d55 100644 --- a/examples/pcr/include.am +++ b/examples/pcr/include.am @@ -11,23 +11,19 @@ noinst_HEADERS += examples/pcr/quote.h \ examples/pcr/pcr.h examples_pcr_quote_SOURCES = examples/pcr/quote.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_pcr_quote_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_pcr_quote_DEPENDENCIES = src/libwolftpm.la -examples_pcr_read_pcr_SOURCES = examples/pcr/read_pcr.c \ - examples/tpm_io.c +examples_pcr_read_pcr_SOURCES = examples/pcr/read_pcr.c examples_pcr_read_pcr_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_pcr_read_pcr_DEPENDENCIES = src/libwolftpm.la -examples_pcr_extend_SOURCES = examples/pcr/extend.c \ - examples/tpm_io.c +examples_pcr_extend_SOURCES = examples/pcr/extend.c examples_pcr_extend_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_pcr_extend_DEPENDENCIES = src/libwolftpm.la -examples_pcr_reset_SOURCES = examples/pcr/reset.c \ - examples/tpm_io.c +examples_pcr_reset_SOURCES = examples/pcr/reset.c examples_pcr_reset_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_pcr_reset_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/pkcs7/include.am b/examples/pkcs7/include.am index 5ee3e9e..117dcd7 100644 --- a/examples/pkcs7/include.am +++ b/examples/pkcs7/include.am @@ -5,8 +5,7 @@ if BUILD_EXAMPLES noinst_PROGRAMS += examples/pkcs7/pkcs7 noinst_HEADERS += examples/pkcs7/pkcs7.h examples_pkcs7_pkcs7_SOURCES = examples/pkcs7/pkcs7.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_pkcs7_pkcs7_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_pkcs7_pkcs7_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/seal/include.am b/examples/seal/include.am index 8bef275..6a98838 100644 --- a/examples/seal/include.am +++ b/examples/seal/include.am @@ -8,14 +8,12 @@ noinst_PROGRAMS += examples/seal/seal \ noinst_HEADERS += examples/seal/seal.h examples_seal_seal_SOURCES = examples/seal/seal.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_seal_seal_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_seal_seal_DEPENDENCIES = src/libwolftpm.la examples_seal_unseal_SOURCES = examples/seal/unseal.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_seal_unseal_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_seal_unseal_DEPENDENCIES = src/libwolftpm.la diff --git a/examples/timestamp/include.am b/examples/timestamp/include.am index c314ca6..3d030c5 100644 --- a/examples/timestamp/include.am +++ b/examples/timestamp/include.am @@ -5,16 +5,14 @@ if BUILD_EXAMPLES noinst_PROGRAMS += examples/timestamp/signed_timestamp noinst_HEADERS += examples/timestamp/signed_timestamp.h examples_timestamp_signed_timestamp_SOURCES = examples/timestamp/signed_timestamp.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_timestamp_signed_timestamp_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_timestamp_signed_timestamp_DEPENDENCIES = src/libwolftpm.la noinst_PROGRAMS += examples/timestamp/clock_set noinst_HEADERS += examples/timestamp/clock_set.h -examples_timestamp_clock_set_SOURCES = examples/timestamp/clock_set.c \ - examples/tpm_io.c +examples_timestamp_clock_set_SOURCES = examples/timestamp/clock_set.c examples_timestamp_clock_set_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_timestamp_clock_set_DEPENDENCIES = src/libwolftpm.la endif diff --git a/examples/tls/include.am b/examples/tls/include.am index 7d74cff..2d3fbc1 100644 --- a/examples/tls/include.am +++ b/examples/tls/include.am @@ -6,8 +6,7 @@ noinst_PROGRAMS += examples/tls/tls_client noinst_HEADERS += examples/tls/tls_client.h \ examples/tls/tls_common.h examples_tls_tls_client_SOURCES = examples/tls/tls_client.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_tls_tls_client_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_tls_tls_client_DEPENDENCIES = src/libwolftpm.la @@ -15,8 +14,7 @@ noinst_PROGRAMS += examples/tls/tls_client_notpm noinst_HEADERS += examples/tls/tls_client.h \ examples/tls/tls_common.h examples_tls_tls_client_notpm_SOURCES = examples/tls/tls_client_notpm.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_tls_tls_client_notpm_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_tls_tls_client_notpm_DEPENDENCIES = src/libwolftpm.la @@ -24,8 +22,7 @@ noinst_PROGRAMS += examples/tls/tls_server noinst_HEADERS += examples/tls/tls_server.h \ examples/tls/tls_common.h examples_tls_tls_server_SOURCES = examples/tls/tls_server.c \ - examples/tpm_test_keys.c \ - examples/tpm_io.c + examples/tpm_test_keys.c examples_tls_tls_server_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_tls_tls_server_DEPENDENCIES = src/libwolftpm.la diff --git a/examples/wrap/include.am b/examples/wrap/include.am index 6953c74..5aec5c5 100644 --- a/examples/wrap/include.am +++ b/examples/wrap/include.am @@ -4,8 +4,7 @@ if BUILD_EXAMPLES noinst_PROGRAMS += examples/wrap/wrap_test noinst_HEADERS += examples/wrap/wrap_test.h -examples_wrap_wrap_test_SOURCES = examples/wrap/wrap_test.c \ - examples/tpm_io.c +examples_wrap_wrap_test_SOURCES = examples/wrap/wrap_test.c examples_wrap_wrap_test_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) examples_wrap_wrap_test_DEPENDENCIES = src/libwolftpm.la endif diff --git a/hal/README.md b/hal/README.md new file mode 100644 index 0000000..fa84435 --- /dev/null +++ b/hal/README.md @@ -0,0 +1,61 @@ +# wolfTPM Hardware Interface Abstraction Layer (HAL) IO + +A single HAL callback must be registered to handle communication to the hardware. + +We distribute examples for several platforms to help with initial setup. + +If using one of the builtin system provided hardware interfaces then `NULL` can be supplied for the HAL IO callback. + +The available system TPM interfaces are: +* Linux `/dev/tpm0`: Enabled with `WOLFTPM_LINUX_DEV` or `--enable-devtpm`. +* Windows TBS: Enabled with `WOLFTPM_WINAPI` or `--enable-winapi`. +* Software TPM Simulator: Enabled with `WOLFTPM_SWTPM` or `--enable-swtpm`. + +If using a HAL IO callback it is registered on library initialization using: +* TPM2 Native API's: `TPM2_Init` +* wolfTPM Wrappers: `wolfTPM2_Init` + +## Example HAL Implementations + +| Platform | Example File | Build Option | +| -------- | ------------ | ------------ | +| Atmel ASF | `tpm_io_atmel.c` | `WOLFSSL_ATMEL` | +| Barebox | `tpm_io_barebox.c` | `__BAREBOX__` | +| Infineon | `tpm_io_infineon.c` | `WOLFTPM_INFINEON_TRICORE` | +| Linux | `tpm_io_linux.c` | `__linux__` | +| Microchip | `tpm_io_microchip.c` | `WOLFTPM_MICROCHIP` | +| QNX | `tpm_io_qnx.c` | `__QNX__` | +| ST Cube HAL | `tpm_io_st.c` | `WOLFSSL_STM32_CUBEMX` | +| Xilinx | `tpm_io_xilinx.c` | `__XILINX__` | + +## HAL IO Callback Function + +Here are the prototypes for the HAL callback function: + +```c +#ifdef WOLFTPM_ADV_IO +typedef int (*TPM2HalIoCb)(struct TPM2_CTX*, INT32 isRead, UINT32 addr, + BYTE* xferBuf, UINT16 xferSz, void* userCtx); +#else +typedef int (*TPM2HalIoCb)(struct TPM2_CTX*, const BYTE* txBuf, BYTE* rxBuf, + UINT16 xferSz, void* userCtx); +#endif +``` + +Here are example function definitions: + +```c +#ifdef WOLFTPM_ADV_IO +int TPM2_IoCb(TPM2_CTX*, int isRead, word32 addr, byte* buf, word16 size, + void* userCtx); +#else +int TPM2_IoCb(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, + word16 xferSz, void* userCtx); +#endif +``` + +## Additional Build options + +* `WOLFTPM_CHECK_WAIT_STATE`: Enables check of the wait state during a SPI transaction. Most TPM 2.0 chips require this and typically only require 0-2 wait cycles depending on the command. Only the Infineon TPM's guarantee no wait states. +* `WOLFTPM_ADV_IO`: Enables advanced IO callback mode that includes TIS register and read/write flag. This is requires for I2C, but can be used with SPI also. +* `WOLFTPM_DEBUG_IO`: Enable logging of the IO (if using the example HAL). diff --git a/hal/include.am b/hal/include.am new file mode 100644 index 0000000..c02041b --- /dev/null +++ b/hal/include.am @@ -0,0 +1,18 @@ +# vim:ft=automake +# All paths should be given relative to the root + +if BUILD_HAL +src_libwolftpm_la_SOURCES += \ + hal/tpm_io.c \ + hal/tpm_io_atmel.c \ + hal/tpm_io_barebox.c \ + hal/tpm_io_linux.c \ + hal/tpm_io_infineon.c \ + hal/tpm_io_microchip.c \ + hal/tpm_io_st.c \ + hal/tpm_io_qnx.c \ + hal/tpm_io_xilinx.c +endif + +nobase_include_HEADERS += hal/tpm_io.h +EXTRA_DIST += hal/README.md diff --git a/examples/tpm_io.c b/hal/tpm_io.c similarity index 100% rename from examples/tpm_io.c rename to hal/tpm_io.c diff --git a/examples/tpm_io.h b/hal/tpm_io.h similarity index 71% rename from examples/tpm_io.h rename to hal/tpm_io.h index 622f15b..c1b76a8 100644 --- a/examples/tpm_io.h +++ b/hal/tpm_io.h @@ -54,56 +54,68 @@ * */ -#if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SWTPM) || defined(WOLFTPM_WINAPI) +#if defined(WOLFTPM_LINUX_DEV) || defined(WOLFTPM_SWTPM) || \ + defined(WOLFTPM_WINAPI) + +/* HAL not required, so use NULL */ #define TPM2_IoCb NULL + #else +#ifdef WOLFTPM_EXAMPLE_HAL + #ifdef WOLFTPM_ADV_IO -int TPM2_IoCb(TPM2_CTX*, int isRead, word32 addr, byte* buf, word16 size, +WOLFTPM_API int TPM2_IoCb(TPM2_CTX*, int isRead, word32 addr, byte* buf, word16 size, void* userCtx); #else -int TPM2_IoCb(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, +WOLFTPM_API int TPM2_IoCb(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #endif -#endif /* !(WOLFTPM_LINUX_DEV || WOLFTPM_SWTPM || WOLFTPM_WINAPI) */ /* Platform support, in alphabetical order */ #ifdef WOLFTPM_I2C + #if defined(__linux__) -int TPM2_IoCb_Linux_I2C(TPM2_CTX* ctx, int isRead, word32 addr, byte* buf, +WOLFTPM_LOCAL int TPM2_IoCb_Linux_I2C(TPM2_CTX* ctx, int isRead, word32 addr, byte* buf, word16 size, void* userCtx); #elif defined(WOLFSSL_STM32_CUBEMX) -int TPM2_IoCb_STCubeMX_I2C(TPM2_CTX* ctx, int isRead, word32 addr, +WOLFTPM_LOCAL int TPM2_IoCb_STCubeMX_I2C(TPM2_CTX* ctx, int isRead, word32 addr, byte* buf, word16 size, void* userCtx); #endif /* __linux__ */ + #else /* SPI */ + #if defined(WOLFSSL_ATMEL) -int TPM2_IoCb_Atmel_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, +WOLFTPM_LOCAL int TPM2_IoCb_Atmel_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(__BAREBOX__) -int TPM2_IoCb_Barebox_SPI(TPM2_CTX* ctx, const byte* txBuf, +WOLFTPM_LOCAL int TPM2_IoCb_Barebox_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(__linux__) -int TPM2_IoCb_Linux_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, +WOLFTPM_LOCAL int TPM2_IoCb_Linux_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(WOLFSSL_STM32_CUBEMX) -int TPM2_IoCb_STCubeMX_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, +WOLFTPM_LOCAL int TPM2_IoCb_STCubeMX_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(__QNX__) || defined(__QNXTO__) -int TPM2_IoCb_QNX_SPI(TPM2_CTX* ctx, const byte* txBuf, +WOLFTPM_LOCAL int TPM2_IoCb_QNX_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(__XILINX__) -int TPM2_IoCb_Xilinx_SPI(TPM2_CTX* ctx, const byte* txBuf, +WOLFTPM_LOCAL int TPM2_IoCb_Xilinx_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(WOLFTPM_INFINEON_TRICORE) -int TPM2_IoCb_Infineon_TriCore_SPI(TPM2_CTX* ctx, const byte* txBuf, +WOLFTPM_LOCAL int TPM2_IoCb_Infineon_TriCore_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); #elif defined(WOLFTPM_MICROCHIP) -int TPM2_IoCb_Microchip_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, +WOLFTPM_LOCAL int TPM2_IoCb_Microchip_SPI(TPM2_CTX* ctx, const byte* txBuf, byte* rxBuf, word16 xferSz, void* userCtx); -#endif /* WOLFSSL_ATMEL */ +#endif + #endif /* WOLFTPM_I2C */ +#endif /* WOLFTPM_EXAMPLE_HAL */ +#endif /* !(WOLFTPM_LINUX_DEV || WOLFTPM_SWTPM || WOLFTPM_WINAPI) */ + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/examples/tpm_io_atmel.c b/hal/tpm_io_atmel.c similarity index 100% rename from examples/tpm_io_atmel.c rename to hal/tpm_io_atmel.c diff --git a/examples/tpm_io_barebox.c b/hal/tpm_io_barebox.c similarity index 100% rename from examples/tpm_io_barebox.c rename to hal/tpm_io_barebox.c diff --git a/examples/tpm_io_infineon.c b/hal/tpm_io_infineon.c similarity index 100% rename from examples/tpm_io_infineon.c rename to hal/tpm_io_infineon.c diff --git a/examples/tpm_io_linux.c b/hal/tpm_io_linux.c similarity index 100% rename from examples/tpm_io_linux.c rename to hal/tpm_io_linux.c diff --git a/examples/tpm_io_microchip.c b/hal/tpm_io_microchip.c similarity index 100% rename from examples/tpm_io_microchip.c rename to hal/tpm_io_microchip.c diff --git a/examples/tpm_io_qnx.c b/hal/tpm_io_qnx.c similarity index 100% rename from examples/tpm_io_qnx.c rename to hal/tpm_io_qnx.c diff --git a/examples/tpm_io_st.c b/hal/tpm_io_st.c similarity index 100% rename from examples/tpm_io_st.c rename to hal/tpm_io_st.c diff --git a/examples/tpm_io_xilinx.c b/hal/tpm_io_xilinx.c similarity index 100% rename from examples/tpm_io_xilinx.c rename to hal/tpm_io_xilinx.c diff --git a/src/tpm2_linux.c b/src/tpm2_linux.c index ea943d1..c1b2032 100644 --- a/src/tpm2_linux.c +++ b/src/tpm2_linux.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ +#include #ifdef WOLFTPM_LINUX_DEV #include diff --git a/src/tpm2_swtpm.c b/src/tpm2_swtpm.c index ea416a9..453c52d 100644 --- a/src/tpm2_swtpm.c +++ b/src/tpm2_swtpm.c @@ -32,6 +32,8 @@ * See docs/SWTPM.md */ +#include + #ifdef WOLFTPM_SWTPM #include #include diff --git a/src/tpm2_winapi.c b/src/tpm2_winapi.c index 3fc2fd9..fcd8a46 100644 --- a/src/tpm2_winapi.c +++ b/src/tpm2_winapi.c @@ -20,6 +20,8 @@ */ +#include + #ifdef WOLFTPM_WINAPI #include diff --git a/tests/include.am b/tests/include.am index 33884fb..1aac9bc 100644 --- a/tests/include.am +++ b/tests/include.am @@ -5,9 +5,7 @@ if BUILD_EXAMPLES check_PROGRAMS += tests/unit.test noinst_PROGRAMS += tests/unit.test -tests_unit_test_SOURCES = \ - tests/unit_tests.c \ - examples/tpm_io.c +tests_unit_test_SOURCES = tests/unit_tests.c tests_unit_test_CFLAGS = $(AM_CFLAGS) tests_unit_test_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD) tests_unit_test_DEPENDENCIES = src/libwolftpm.la