@@ -1112,8 +1112,8 @@ static int write_parsed_log(struct log_a_data log_data[],
11121112 bool is_bl1 ;
11131113 struct module_log_defs * mod_defs ;
11141114
1115- if (entry_idx == 0 ) {
1116- if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP )
1115+ if (entry_idx == 0 ){
1116+ if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC )
11171117 fputs (" #|Timestamp |Module |Severity |Event ID |Event\n" ,
11181118 log_file );
11191119 else
@@ -1138,7 +1138,7 @@ static int write_parsed_log(struct log_a_data log_data[],
11381138 hours = time % 24 ;
11391139 days = time / 24 ;
11401140
1141- if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP ) {
1141+ if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC ) {
11421142 /*
11431143 * app log: module ID and log severity are in the 3rd
11441144 * DWord
@@ -1199,7 +1199,7 @@ static int write_parsed_log(struct log_a_data log_data[],
11991199 if (ret < 0 )
12001200 goto ret_print_error ;
12011201
1202- if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP ) {
1202+ if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC ) {
12031203 /* print the module name and log severity */
12041204 if (fprintf (log_file , "%-12s |%-8s |0x%04x |" ,
12051205 mod_defs -> mod_name , log_sev_strs [log_sev ],
@@ -1232,14 +1232,31 @@ static int write_parsed_log(struct log_a_data log_data[],
12321232 return -1 ;
12331233}
12341234
1235+ static int append_ftdc_log_header (int fd , uint32_t sdk_def_version ,
1236+ uint32_t fw_def_version )
1237+ {
1238+ int ret ;
1239+ char hdr_str_fmt [] = "##########################################\n"
1240+ "## Parsed with FTDC log file from definition:\n"
1241+ "## FW def version %08x\n"
1242+ "## SDK def version %08x\n"
1243+ "##########################################\n\n" ;
1244+ char hdr_str [512 ];
1245+
1246+ snprintf (hdr_str , 512 , hdr_str_fmt , fw_def_version , sdk_def_version );
1247+ ret = write (fd , hdr_str , strlen (hdr_str ));
1248+
1249+ return ret ;
1250+ }
1251+
12351252static int parse_def_header (FILE * log_def_file , uint32_t * fw_version ,
12361253 uint32_t * sdk_version )
12371254{
12381255 char line [512 ];
12391256 int i ;
12401257
12411258 * fw_version = 0 ;
1242- * sdk_version = 0 ;
1259+
12431260 while (fgets (line , sizeof (line ), log_def_file )) {
12441261 if (line [0 ] != '#' )
12451262 continue ;
@@ -1464,6 +1481,40 @@ static int log_c_to_file(struct switchtec_dev *dev, int sub_cmd_id, int fd)
14641481 return 0 ;
14651482}
14661483
1484+ static int log_d_to_file (struct switchtec_dev * dev , int sub_cmd_id , int fd )
1485+ {
1486+ int ret ;
1487+ int read = 0 ;
1488+
1489+ struct log_ftdc_retr_result res ;
1490+ struct log_ftdc_retr cmd = {
1491+ .sub_cmd_id = sub_cmd_id ,
1492+ .reserved = 0 ,
1493+ .req_seq = 0 ,
1494+ };
1495+ uint32_t length = sizeof (res .data );
1496+
1497+ cmd .req_seq = 0 ;
1498+ res .data [1 ] = 0 ;
1499+
1500+ while ( !(res .data [1 ]) ) {
1501+ ret = switchtec_cmd (dev , MRPC_FTDC_LOG_DUMP , & cmd , sizeof (cmd ),
1502+ & res , sizeof (res ));
1503+ if (ret )
1504+ return -1 ;
1505+
1506+ ret = write (fd , res .data , (res .data [0 ]+ 1 )* 4 );
1507+ if (ret < 0 )
1508+ return ret ;
1509+
1510+ read += length ;
1511+ cmd .req_seq ++ ;
1512+
1513+ }
1514+
1515+ return 0 ;
1516+ }
1517+
14671518static int log_ram_flash_to_file (struct switchtec_dev * dev ,
14681519 int gen5_cmd , int gen4_cmd , int gen4_cmd_lgcy ,
14691520 int fd , FILE * log_def_file ,
@@ -1522,6 +1573,8 @@ int switchtec_log_to_file(struct switchtec_dev *dev,
15221573 MRPC_FWLOGRD_FLASH_WITH_FLAG ,
15231574 MRPC_FWLOGRD_FLASH ,
15241575 fd , log_def_file , info );
1576+ case SWITCHTEC_LOG_FTDC :
1577+ return log_d_to_file (dev , MRPC_FWLOGRD_RAM , fd );
15251578 case SWITCHTEC_LOG_MEMLOG :
15261579 return log_b_to_file (dev , MRPC_FWLOGRD_MEMLOG , fd );
15271580 case SWITCHTEC_LOG_REGS :
@@ -1605,15 +1658,25 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
16051658 memset (info , 0 , sizeof (* info ));
16061659
16071660 if ((log_type != SWITCHTEC_LOG_PARSE_TYPE_APP ) &&
1608- (log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX )) {
1609- errno = EINVAL ;
1661+ (log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX ) &&
1662+ (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC )) {
1663+ errno = EINVAL ;
16101664 return - errno ;
16111665 }
16121666
16131667 ret = parse_log_header (bin_log_file , & fw_version_log ,
16141668 & sdk_version_log );
16151669 if (ret )
16161670 return ret ;
1671+
1672+ if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC )
1673+ {
1674+ ret = parse_log_header (bin_log_file , & fw_version_log ,
1675+ & sdk_version_log );
1676+ if (ret )
1677+ return ret ;
1678+ }
1679+
16171680 ret = parse_def_header (log_def_file , & fw_version_def ,
16181681 & sdk_version_def );
16191682 if (ret )
@@ -1632,13 +1695,17 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
16321695 info -> log_sdk_version = sdk_version_log ;
16331696 }
16341697 /* read the log definition file into defs */
1635- if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP )
1698+ if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC )
16361699 ret = read_app_log_defs (log_def_file , & defs );
16371700 else
16381701 ret = read_mailbox_log_defs (log_def_file , & defs );
16391702
1640- ret = append_log_header (fileno (parsed_log_file ), sdk_version_log ,
1641- fw_version_log , 0 );
1703+ if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC )
1704+ ret = append_log_header (fileno (parsed_log_file ), sdk_version_log ,
1705+ fw_version_log , 0 );
1706+ else
1707+ ret = append_ftdc_log_header (fileno (parsed_log_file ), sdk_version_def ,
1708+ fw_version_def );
16421709 if (ret < 0 )
16431710 return ret ;
16441711
0 commit comments