@@ -166,6 +166,8 @@ static int cmd_update_xmodem(const char *args);
166166static int cmd_reboot (const char * args );
167167#ifdef WOLFBOOT_TPM
168168static int cmd_tpm_info (const char * args );
169+ static int cmd_tpm_idevid (const char * args );
170+ static int cmd_tpm_iak (const char * args );
169171#endif
170172
171173
@@ -195,6 +197,8 @@ struct console_command COMMANDS[] =
195197 {cmd_reboot , "reboot" , "reboot the system" },
196198#ifdef WOLFBOOT_TPM
197199 {cmd_tpm_info , "tpm" , "get TPM capabilities" },
200+ {cmd_tpm_idevid , "idevid" , "show Initial Device Identification (IDevID) certificate" },
201+ {cmd_tpm_iak , "iak" , "show Initial Attestation Identification (IAK) certificate" },
198202#endif
199203 {NULL , "" , "" }
200204};
@@ -431,9 +435,47 @@ static const char *part_state_name(uint8_t state)
431435 }
432436}
433437
438+ #define LINE_LEN 16
439+ void print_hex (const uint8_t * buffer , uint32_t length , int dumpChars )
440+ {
441+ word32 i , sz ;
442+
443+ if (!buffer ) {
444+ printf ("\tNULL\n" );
445+ return ;
446+ }
447+
448+ while (length > 0 ) {
449+ sz = length ;
450+ if (sz > LINE_LEN )
451+ sz = LINE_LEN ;
452+
453+ printf ("\t" );
454+ for (i = 0 ; i < LINE_LEN ; i ++ ) {
455+ if (i < length )
456+ printf ("%02x " , buffer [i ]);
457+ else
458+ printf (" " );
459+ }
460+ if (dumpChars ) {
461+ printf ("| " );
462+ for (i = 0 ; i < sz ; i ++ ) {
463+ if (buffer [i ] > 31 && buffer [i ] < 127 )
464+ printf ("%c" , buffer [i ]);
465+ else
466+ printf ("." );
467+ }
468+ }
469+ printf ("\r\n" );
470+
471+ buffer += sz ;
472+ length -= sz ;
473+ }
474+ }
475+
434476static int cmd_info (const char * args )
435477{
436- int i , j ;
478+ int i ;
437479 uint32_t cur_fw_version , update_fw_version ;
438480 uint32_t n_keys ;
439481 uint16_t hdrSz ;
@@ -489,13 +531,7 @@ static int cmd_info(const char *args)
489531 printf (" Public Key #%d: size %lu, type %lx, mask %08lx\r\n" , i ,
490532 size , type , mask );
491533 printf (" ====================================\r\n " );
492- for (j = 0 ; j < size ; j ++ ) {
493- printf ("%02X " , keybuf [j ]);
494- if (j % 16 == 15 ) {
495- printf ("\r\n " );
496- }
497- }
498- printf ("\r\n" );
534+ print_hex (keybuf , size , 0 );
499535 }
500536 return 0 ;
501537}
@@ -770,7 +806,37 @@ static int cmd_tpm_info(const char *args)
770806
771807 return rc ;
772808}
773- #endif
809+
810+ static int cmd_tpm_idevid (const char * args )
811+ {
812+ int rc ;
813+ uint8_t cert [1024 ];
814+ uint32_t certSz = (uint32_t )sizeof (cert );
815+ uint32_t handle = TPM2_IDEVID_CERT_HANDLE ;
816+
817+ rc = wolfBoot_tpm2_read_cert (handle , cert , & certSz );
818+ if (rc == 0 ) {
819+ printf ("IDevID Handle 0x%x\r\n" , (unsigned int )handle );
820+ print_hex (cert , certSz , 1 );
821+ }
822+ return rc ;
823+ }
824+
825+ static int cmd_tpm_iak (const char * args )
826+ {
827+ int rc ;
828+ uint8_t cert [1024 ];
829+ uint32_t certSz = (uint32_t )sizeof (cert );
830+ uint32_t handle = TPM2_IAK_CERT_HANDLE ;
831+
832+ rc = wolfBoot_tpm2_read_cert (handle , cert , & certSz );
833+ if (rc == 0 ) {
834+ printf ("IAK Handle 0x%x\r\n" , (unsigned int )handle );
835+ print_hex (cert , certSz , 1 );
836+ }
837+ return rc ;
838+ }
839+ #endif /* WOLFBOOT_TPM */
774840
775841
776842static int parse_cmd (const char * cmd )
0 commit comments