Implement support for wolfHAL I2C/SPI backends - #562
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new wolfHAL-based IO backend so wolfTPM can communicate with a TPM over SPI or I2C on targets that use wolfHAL for peripheral access. This fits into the existing hal/ example callback framework and extends the build system and docs to expose the new backend as a selectable option.
Changes:
- Add
hal/tpm_io_wolfhal.cimplementing SPI and I2C IO callbacks using wolfHAL and application-providedboard.hdefinitions. - Wire wolfHAL into the HAL selection chain and public HAL prototypes (
hal/tpm_io.c,hal/tpm_io.h). - Expose
--enable-wolfhalinconfigure.acand document usage/requirements in the root README andhal/README.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents wolfHAL as a supported platform and adds --enable-wolfhal configuration flag details. |
| hal/tpm_io.h | Adds wolfHAL callback prototypes for SPI and I2C builds. |
| hal/tpm_io.c | Adds wolfHAL to the platform selection chain and dispatches to wolfHAL callbacks. |
| hal/tpm_io_wolfhal.c | New wolfHAL SPI/I2C backend implementation relying on application board.h macros. |
| hal/README.md | Adds wolfHAL section explaining enablement and required BOARD_* definitions with examples. |
| hal/include.am | Adds the new source file to the HAL build sources. |
| configure.ac | Adds --enable-wolfhal option and includes it in the configure summary output. |
94bbc8b to
632031d
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #562
Scan targets checked: wolftpm-bugs, wolftpm-src
No new issues found in the changed files. ✅
632031d to
92e3e7d
Compare
92e3e7d to
0e7f312
Compare
| status = whal_I2c_ReadReg(BOARD_I2C_DEV, reg, buf, size); | ||
| else | ||
| status = whal_I2c_WriteReg(BOARD_I2C_DEV, reg, buf, size); | ||
| } while (status != WHAL_SUCCESS && --tries > 0); |
There was a problem hiding this comment.
Consider adding XSLEEP_MS(1); here?
| int timeout = TPM_SPI_WAIT_RETRY; | ||
| #endif | ||
|
|
||
| /* Assert chip select (active low) */ |
There was a problem hiding this comment.
Should whal_Spi_StartCom come before chip select assert?
| #error "wolfHAL: board.h must define BOARD_I2C_DEV (whal_I2c*)" | ||
| #endif | ||
| /* Carries the TPM target address (typically 0x2e) and bus speed. */ | ||
| #ifndef BOARD_I2C_COM_CFG |
There was a problem hiding this comment.
Could/should we use the existing TPM2_I2C_ADDR or maybe #error if that is set?
| } | ||
|
|
||
| (void)ctx; | ||
| (void)userCtx; |
There was a problem hiding this comment.
Should we support using "userCtx" for anything with wolfHAL?
| fi | ||
|
|
||
|
|
||
| # wolfHAL hardware abstraction layer |
There was a problem hiding this comment.
We should add this to CMakeList.txt at some point (doesn't have to be in this PR).
Add wolfHAL support
Adds a wolfHAL IO backend so wolfTPM can talk to a TPM over SPI or I2C on
targets using wolfHAL for peripheral access.
Usage
Board definitions
wolfTPM does not ship board definitions.
tpm_io_wolfhal.cincludes"board.h", which the application provides. A wolfHAL project already hasone, so usually only the TPM entries need adding:
BOARD_SPI_DEVwhal_Spi*BOARD_SPI_COM_CFGwhal_Spi_ComCfg*BOARD_GPIO_DEVwhal_Gpio*(chip select)BOARD_CS_PINBOARD_I2C_DEVwhal_I2c*BOARD_I2C_COM_CFGwhal_I2c_ComCfg*(carries the TPM address)A missing entry is reported at compile time, naming the macro required.
See
hal/README.mdfor details and examples.