|
| 1 | +# wolfTPM Support For Das U-boot |
| 2 | + |
| 3 | +wolfTPM provides experimental support for U-Boot with the following key features: |
| 4 | + |
| 5 | +- Utilizes SOFT SPI driver in U-Boot for TPM communication |
| 6 | +- Implements TPM 2.0 driver functionality through its internal TIS layer |
| 7 | +- Provides native API access to all TPM 2.0 commands |
| 8 | +- Includes wrapper API for common TPM 2.0 operations |
| 9 | +- Supports two integration paths: |
| 10 | + - `__linux__`: Uses existing tpm interface via tpm2_linux.c |
| 11 | + - `__UBOOT__`: Direct SPI communication through tpm_io_uboot.c |
| 12 | + |
| 13 | +## wolfTPM U-Boot Commands |
| 14 | + |
| 15 | +The following commands are available through the `wolftpm` interface: |
| 16 | + |
| 17 | +### Basic Commands |
| 18 | + |
| 19 | +- `help` - Show help text |
| 20 | +- `device [num device]` - Show all devices or set the specified device |
| 21 | +- `info` - Show information about the TPM |
| 22 | +- `state` - Show internal state from the TPM (if available) |
| 23 | +- `autostart` - Initialize the TPM, perform a Startup(clear) and run a full selftest sequence |
| 24 | +- `init` - Initialize the software stack (must be first command) |
| 25 | +- `startup <mode> [<op>]` - Issue a TPM2_Startup command |
| 26 | + - `<mode>`: TPM2_SU_CLEAR (reset state) or TPM2_SU_STATE (preserved state) |
| 27 | + - `[<op>]`: optional shutdown with "off" |
| 28 | +- `self_test <type>` - Test TPM capabilities |
| 29 | + - `<type>`: "full" (all tests) or "continue" (untested tests only) |
| 30 | + |
| 31 | +### PCR Operations |
| 32 | + |
| 33 | +- `pcr_extend <pcr> <digest_addr> [<digest_algo>]` - Extend PCR with digest |
| 34 | +- `pcr_read <pcr> <digest_addr> [<digest_algo>]` - Read PCR to memory |
| 35 | +- `pcr_allocate <algorithm> <on/off> [<password>]` - Reconfig PCR bank algorithm |
| 36 | +- `pcr_setauthpolicy | pcr_setauthvalue <pcr> <key> [<password>]` - Change PCR access key |
| 37 | +- `pcr_print` - Print current PCR state |
| 38 | + |
| 39 | +### Security Management |
| 40 | + |
| 41 | +- `clear <hierarchy>` - Issue TPM2_Clear command |
| 42 | + - `<hierarchy>`: TPM2_RH_LOCKOUT or TPM2_RH_PLATFORM |
| 43 | +- `change_auth <hierarchy> <new_pw> [<old_pw>]` - Change hierarchy password |
| 44 | + - `<hierarchy>`: TPM2_RH_LOCKOUT, TPM2_RH_ENDORSEMENT, TPM2_RH_OWNER, or TPM2_RH_PLATFORM |
| 45 | +- `dam_reset [<password>]` - Reset internal error counter |
| 46 | +- `dam_parameters <max_tries> <recovery_time> <lockout_recovery> [<password>]` - Set DAM parameters |
| 47 | +- `caps` - Show TPM capabilities and info |
| 48 | + |
| 49 | +### Firmware Management |
| 50 | + |
| 51 | +- `firmware_update <manifest_addr> <manifest_sz> <firmware_addr> <firmware_sz>` - Update TPM firmware |
| 52 | +- `firmware_cancel` - Cancel TPM firmware update |
| 53 | + |
| 54 | +## Enabling wolfTPM in U-Boot |
| 55 | + |
| 56 | +Enable wolfTPM support in U-Boot by adding these options to your board's defconfig: |
| 57 | + |
| 58 | +``` |
| 59 | +CONFIG_TPM=y |
| 60 | +CONFIG_TPM_V2=y |
| 61 | +CONFIG_TPM_WOLF=y |
| 62 | +CONFIG_CMD_WOLFTPM=y |
| 63 | +``` |
| 64 | + |
| 65 | +Or use `make menuconfig` and enable: |
| 66 | +- Device Drivers → TPM → TPM 2.0 Support |
| 67 | +- Device Drivers → TPM → wolfTPM Support |
| 68 | +- Command line interface → Security commands → Enable wolfTPM commands |
| 69 | + |
| 70 | +## Building and Running wolfTPM with U-Boot using QEMU |
| 71 | + |
| 72 | +To build and run wolfTPM with U-Boot using QEMU and a tpm simulator, follow these steps: |
| 73 | + |
| 74 | +1. Install swtpm: |
| 75 | +``` |
| 76 | +git clone git@github.com:stefanberger/swtpm.git |
| 77 | +cd swtpm |
| 78 | +./autogen.sh |
| 79 | +make |
| 80 | +``` |
| 81 | + |
| 82 | +2. Build U-Boot: |
| 83 | +``` |
| 84 | +make distclean |
| 85 | +export CROSS_COMPILE=aarch64-linux-gnu- |
| 86 | +export ARCH=aarch64 |
| 87 | +make qemu_arm64_defconfig |
| 88 | +make -j4 |
| 89 | +``` |
| 90 | + |
| 91 | +3. Create TPM directory: |
| 92 | +``` |
| 93 | +mkdir -p ./tmp/mytpm1 |
| 94 | +``` |
| 95 | + |
| 96 | +4. Start swtpm (in first terminal): |
| 97 | +``` |
| 98 | +swtpm socket --tpm2 --tpmstate dir=./tmp/mytpm1 --ctrl type=unixio,path=./tmp/mytpm1/swtpm-sock --log level=20 |
| 99 | +``` |
| 100 | + |
| 101 | +5. Start QEMU (in second terminal): |
| 102 | +``` |
| 103 | +qemu-system-aarch64 -machine virt -nographic -cpu cortex-a57 -bios u-boot.bin -chardev socket,id=chrtpm,path=./tmp/mytpm1/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis-device,tpmdev=tpm0 |
| 104 | +``` |
| 105 | + |
| 106 | +6. Exiting the QEMU: |
| 107 | +Press Ctrl-A followed by X |
0 commit comments