@@ -677,7 +677,7 @@ static int TPM2_PCRs_Print(void)
677677 GetCapability_In capIn ;
678678 GetCapability_Out capOut ;
679679 TPML_PCR_SELECTION * pcrSel ;
680- char buffer [24 ];
680+ char algName [24 ];
681681
682682 /* List available PCR's */
683683 XMEMSET (& capIn , 0 , sizeof (capIn ));
@@ -691,7 +691,7 @@ static int TPM2_PCRs_Print(void)
691691 for (pcrCount = 0 ; pcrCount < (int )pcrSel -> count ; pcrCount ++ ) {
692692
693693 printf ("\t%s: " , wolfBoot_tpm2_get_alg_name (
694- pcrSel -> pcrSelections [pcrCount ].hash , buffer , sizeof (buffer )));
694+ pcrSel -> pcrSelections [pcrCount ].hash , algName , sizeof (algName )));
695695 for (pcrIndex = 0 ;
696696 pcrIndex < pcrSel -> pcrSelections [pcrCount ].sizeofSelect * 8 ;
697697 pcrIndex ++ ) {
@@ -711,7 +711,10 @@ static int cmd_tpm_info(const char *args)
711711 int rc ;
712712 WOLFTPM2_CAPS caps ;
713713 TPML_HANDLE handles ;
714- char error [100 ];
714+ #ifdef WOLFBOOT_MEASURED_PCR_A
715+ byte hashBuf [TPM_MAX_DIGEST_SIZE ];
716+ int hashSz ;
717+ #endif
715718
716719 printf ("Get TPM 2.0 module information\r\n" );
717720
@@ -731,11 +734,36 @@ static int cmd_tpm_info(const char *args)
731734 for (i = 0 ; i < (int )handles .count ; i ++ ) {
732735 printf ("\tHandle 0x%x\r\n" , (unsigned int )handles .handle [i ]);
733736 }
737+ rc = 0 ;
734738 }
735739
736740 /* Print the available PCR's */
737- rc = TPM2_PCRs_Print ();
741+ if (rc == 0 ) {
742+ rc = TPM2_PCRs_Print ();
743+ }
744+
745+ #ifdef WOLFBOOT_MEASURED_PCR_A
746+ /* Read measured boot PCR */
747+ if (rc == 0 ) {
748+ char algName [24 ];
749+ printf ("Measured boot: PCR %s %d\r\n" ,
750+ wolfBoot_tpm2_get_alg_name (WOLFBOOT_TPM_PCR_ALG , algName , sizeof (algName )),
751+ WOLFBOOT_MEASURED_PCR_A );
752+ hashSz = 0 ;
753+ rc = wolfBoot_tpm2_read_pcr (WOLFBOOT_MEASURED_PCR_A , hashBuf , & hashSz );
754+ if (rc == 0 ) {
755+ int i ;
756+ printf ("PCR (%d bytes): " , hashSz );
757+ for (i = 0 ; i < hashSz ; i ++ ) {
758+ printf ("%02x" , hashBuf [i ]);
759+ }
760+ printf ("\r\n" );
761+ }
762+ }
763+ #endif
764+
738765 if (rc != 0 ) {
766+ char error [100 ];
739767 printf ("TPM error 0x%x: %s\r\n" ,
740768 rc , wolfBoot_tpm2_get_rc_string (rc , error , sizeof (error )));
741769 }
0 commit comments