@@ -94,35 +94,26 @@ static const char* TPM2_IFX_GetOpModeStr(int opMode)
9494 return opModeStr ;
9595}
9696
97- static int TPM2_IFX_PrintInfo (WOLFTPM2_DEV * dev )
97+ static void TPM2_IFX_PrintInfo (WOLFTPM2_CAPS * caps )
9898{
99- int rc ;
100- WOLFTPM2_CAPS caps ;
101- rc = wolfTPM2_GetCapabilities (dev , & caps );
102- if (rc == TPM_RC_SUCCESS ) {
103- printf ("Mfg %s (%d), Vendor %s, Fw %u.%u (0x%x)\n" ,
104- caps .mfgStr , caps .mfg , caps .vendorStr , caps .fwVerMajor ,
105- caps .fwVerMinor , caps .fwVerVendor );
106- printf ("Operational mode: %s (0x%x)\n" ,
107- TPM2_IFX_GetOpModeStr (caps .opMode ), caps .opMode );
108- printf ("KeyGroupId 0x%x, FwCounter %d (%d same)\n" ,
109- caps .keyGroupId , caps .fwCounter , caps .fwCounterSame );
110- if (caps .keyGroupId == 0 ) {
111- printf ("Error getting key group id from TPM!\n" );
112- rc = -1 ;
113- }
114- }
115- return rc ;
99+ printf ("Mfg %s (%d), Vendor %s, Fw %u.%u (0x%x)\n" ,
100+ caps -> mfgStr , caps -> mfg , caps -> vendorStr , caps -> fwVerMajor ,
101+ caps -> fwVerMinor , caps -> fwVerVendor );
102+ printf ("Operational mode: %s (0x%x)\n" ,
103+ TPM2_IFX_GetOpModeStr (caps -> opMode ), caps -> opMode );
104+ printf ("KeyGroupId 0x%x, FwCounter %d (%d same)\n" ,
105+ caps -> keyGroupId , caps -> fwCounter , caps -> fwCounterSame );
116106}
117107
118108int TPM2_IFX_Firmware_Update (void * userCtx , int argc , char * argv [])
119109{
120110 int rc ;
121111 WOLFTPM2_DEV dev ;
112+ WOLFTPM2_CAPS caps ;
122113 const char * manifest_file = NULL ;
123114 const char * firmware_file = NULL ;
124115 fw_info_t fwinfo ;
125- int abandon = 0 ;
116+ int abandon = 0 , recovery = 0 ;
126117
127118 XMEMSET (& fwinfo , 0 , sizeof (fwinfo ));
128119
@@ -156,10 +147,18 @@ int TPM2_IFX_Firmware_Update(void* userCtx, int argc, char *argv[])
156147 goto exit ;
157148 }
158149
159- rc = TPM2_IFX_PrintInfo (& dev );
160- if (rc != 0 ) {
150+ rc = wolfTPM2_GetCapabilities (& dev , & caps );
151+ if (rc != TPM_RC_SUCCESS ) {
161152 goto exit ;
162153 }
154+ TPM2_IFX_PrintInfo (& caps );
155+ if (caps .keyGroupId == 0 ) {
156+ printf ("Error getting key group id from TPM!\n" );
157+ }
158+ if (caps .opMode == 0x02 || (caps .opMode & 0x80 )) {
159+ /* if opmode == 2 or 0x8x then we need to use recovery mode */
160+ recovery = 1 ;
161+ }
163162
164163 if (abandon ) {
165164 printf ("Firmware Update Abandon:\n" );
@@ -188,12 +187,21 @@ int TPM2_IFX_Firmware_Update(void* userCtx, int argc, char *argv[])
188187 & fwinfo .firmware_buf , & fwinfo .firmware_bufSz );
189188 }
190189 if (rc == 0 ) {
191- rc = wolfTPM2_FirmwareUpgrade (& dev ,
192- fwinfo .manifest_buf , (uint32_t )fwinfo .manifest_bufSz ,
193- TPM2_IFX_FwData_Cb , & fwinfo );
190+ if (recovery ) {
191+ printf ("Firmware Update (recovery mode):\n" );
192+ rc = wolfTPM2_FirmwareUpgradeRecover (& dev ,
193+ fwinfo .manifest_buf , (uint32_t )fwinfo .manifest_bufSz ,
194+ TPM2_IFX_FwData_Cb , & fwinfo );
195+ }
196+ else {
197+ printf ("Firmware Update (normal mode):\n" );
198+ rc = wolfTPM2_FirmwareUpgrade (& dev ,
199+ fwinfo .manifest_buf , (uint32_t )fwinfo .manifest_bufSz ,
200+ TPM2_IFX_FwData_Cb , & fwinfo );
201+ }
194202 }
195203 if (rc == 0 ) {
196- rc = TPM2_IFX_PrintInfo (& dev );
204+ TPM2_IFX_PrintInfo (& caps );
197205 }
198206
199207exit :
0 commit comments