Skip to content

Commit

Permalink
Merge pull request #251 from dgarske/microchip_harmony
Browse files Browse the repository at this point in the history
HAL refactor and added Microchip Harmony SPI HAL support
  • Loading branch information
jpbland1 authored Jan 20, 2023
2 parents 883fc1c + c05bf65 commit b4e439a
Show file tree
Hide file tree
Showing 70 changed files with 338 additions and 150 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -342,7 +344,7 @@ cmake --build .

## Running Examples

These examples demonstrate features of a TPM 2.0 module. The examples create RSA and ECC keys in NV for testing using handles defined in `./examples/tpm_io.h`. The PKCS #7 and TLS examples require generating CSR's and signing them using a test script. See `examples/README.md` for details on using the examples. To run the TLS sever and client on same machine you must build with `WOLFTPM_TIS_LOCK` to enable concurrent access protection.
These examples demonstrate features of a TPM 2.0 module. The examples create RSA and ECC keys in NV for testing using handles defined in `./hal/tpm_io.h`. The PKCS #7 and TLS examples require generating CSR's and signing them using a test script. See `examples/README.md` for details on using the examples. To run the TLS sever and client on same machine you must build with `WOLFTPM_TIS_LOCK` to enable concurrent access protection.

### TPM2 Wrapper Tests

Expand Down
14 changes: 13 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ./docs/README.md ./wolftpm/tpm2.h ./wolftpm/tpm2_wrap.h ./examples/tpm_io.h
INPUT = ./docs/README.md ./wolftpm/tpm2.h ./wolftpm/tpm2_wrap.h ./hal/tpm_io.h

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion examples/attestation/activate_credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef WOLFTPM2_NO_WRAPPER

#include <examples/attestation/credential.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
2 changes: 0 additions & 2 deletions examples/attestation/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/attestation/make_credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef WOLFTPM2_NO_WRAPPER

#include <examples/attestation/credential.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#if !defined(WOLFTPM2_NO_WRAPPER) && !defined(NO_TPM_BENCH)

#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>
#include <examples/bench/bench.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bench/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/csr/csr.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#if !defined(WOLFTPM2_NO_WRAPPER) && defined(WOLFTPM2_CERT_GEN)

#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>
#include <examples/csr/csr.h>
Expand Down
3 changes: 1 addition & 2 deletions examples/csr/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/gpio/gpio_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(defined(WOLFTPM_ST33) || defined(WOLFTPM_NUVOTON))

#include <examples/gpio/gpio.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/gpio/gpio_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/gpio/gpio.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/gpio/gpio_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/gpio/gpio.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>

#include <stdio.h>
Expand Down
9 changes: 3 additions & 6 deletions examples/gpio/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions examples/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +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_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
2 changes: 1 addition & 1 deletion examples/keygen/create_primary.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/keygen/keygen.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
12 changes: 4 additions & 8 deletions examples/keygen/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/keygen/keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/keygen/keygen.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/keygen/keyimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/keygen/keygen.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/keygen/keyload.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/keygen/keygen.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
2 changes: 1 addition & 1 deletion examples/management/flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/management/flush.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>

#include <stdio.h>
Expand Down
3 changes: 1 addition & 2 deletions examples/management/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/native/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/native/native_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <wolftpm/tpm2_param_enc.h>

#include <examples/native/native_test.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/nvram/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/nvram/nvram.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
9 changes: 3 additions & 6 deletions examples/nvram/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/nvram/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <wolftpm/tpm2_wrap.h>

#include <examples/nvram/nvram.h>
#include <examples/tpm_io.h>
#include <hal/tpm_io.h>
#include <examples/tpm_test.h>
#include <examples/tpm_test_keys.h>

Expand Down
Loading

0 comments on commit b4e439a

Please sign in to comment.