Skip to content

Commit 406d667

Browse files
author
root
committed
FTDC code added
1 parent 6ce53d0 commit 406d667

File tree

6 files changed

+99
-14
lines changed

6 files changed

+99
-14
lines changed

cli/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ static int log_dump(int argc, char **argv)
10191019
const struct argconfig_choice types[] = {
10201020
{"RAM", SWITCHTEC_LOG_RAM, "dump the app log from RAM"},
10211021
{"FLASH", SWITCHTEC_LOG_FLASH, "dump the app log from flash"},
1022+
{"FTDC", SWITCHTEC_LOG_FTDC, "dump the FTDC firmware log"},
10221023
{"MEMLOG", SWITCHTEC_LOG_MEMLOG,
10231024
"dump the Memlog info from flash in the last fatal error handling dump"},
10241025
{"REGS", SWITCHTEC_LOG_REGS,
@@ -1149,6 +1150,7 @@ static int log_parse(int argc, char **argv)
11491150
const struct argconfig_choice log_types[] = {
11501151
{"APP", SWITCHTEC_LOG_PARSE_TYPE_APP, "app log"},
11511152
{"MAILBOX", SWITCHTEC_LOG_PARSE_TYPE_MAILBOX, "mailbox log"},
1153+
{"FTDC", SWITCHTEC_LOG_PARSE_TYPE_FTDC, "ftdc"},
11521154
{}
11531155
};
11541156
const struct argconfig_choice device_gen[] = {
@@ -1227,7 +1229,7 @@ static int log_parse(int argc, char **argv)
12271229
fprintf(stderr, "\nParsed log saved to %s.\n",
12281230
cfg.parsed_log_filename);
12291231

1230-
if (info.version_mismatch) {
1232+
if (info.version_mismatch && cfg.log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC) {
12311233
fprintf(stderr, "\nWARNING: The two input files have different version numbers.\n");
12321234
fprintf(stderr, "\t\tFW Version\tSDK Version\n");
12331235
fprintf(stderr, "Log file:\t0x%08x\t0x%08x\n",

inc/switchtec/log.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,14 @@ struct log_b_retr_result {
8181
uint8_t data[MRPC_MAX_DATA_LEN - sizeof(struct log_b_retr_hdr)];
8282
};
8383

84+
struct log_ftdc_retr {
85+
uint8_t sub_cmd_id;
86+
uint8_t reserved;
87+
uint16_t req_seq;
88+
};
89+
90+
struct log_ftdc_retr_result {
91+
uint8_t data[MRPC_MAX_DATA_LEN];
92+
};
93+
8494
#endif

inc/switchtec/mrpc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ enum mrpc_cmd {
120120
MRPC_SJTAG_UNLOCK = 0x10F,
121121
MRPC_SECURITY_CONFIG_GET_GEN5 = 0x110,
122122
MRPC_SECURITY_CONFIG_SET_GEN5 = 0x111,
123-
MRPC_MAX_ID = 0x112,
123+
124+
MRPC_FTDC_LOG_DUMP = 0x147,
125+
MRPC_MAX_ID = 0x148,
124126
};
125127

126128
enum mrpc_bg_status {

inc/switchtec/switchtec.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ enum switchtec_bw_type {
229229
enum switchtec_log_type {
230230
SWITCHTEC_LOG_RAM,
231231
SWITCHTEC_LOG_FLASH,
232+
SWITCHTEC_LOG_FTDC,
232233
SWITCHTEC_LOG_MEMLOG,
233234
SWITCHTEC_LOG_REGS,
234235
SWITCHTEC_LOG_SYS_STACK,
@@ -242,7 +243,8 @@ enum switchtec_log_type {
242243
*/
243244
enum switchtec_log_parse_type {
244245
SWITCHTEC_LOG_PARSE_TYPE_APP,
245-
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX
246+
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX,
247+
SWITCHTEC_LOG_PARSE_TYPE_FTDC,
246248
};
247249

248250
/**

lib/platform/linux-uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int set_uart_attribs(int fd, int speed, int parity)
482482
uart_attribs.c_cflag |= (CLOCAL | CREAD);
483483
uart_attribs.c_cflag &= ~(PARENB | PARODD);
484484
uart_attribs.c_cflag |= parity;
485-
uart_attribs.c_cflag &= ~CSTOPB;
485+
uart_attribs.c_cflag |= CSTOPB;
486486
uart_attribs.c_cflag &= ~CRTSCTS;
487487
uart_attribs.c_cc[VMIN] = 0;
488488
uart_attribs.c_cc[VTIME] = 50;

lib/switchtec.c

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
12351252
static 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,42 @@ 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+
printf("calling ftdc MRPC command\n");
1501+
while ( !(res.data[1]) ) {
1502+
ret = switchtec_cmd(dev, MRPC_FTDC_LOG_DUMP, &cmd, sizeof(cmd),
1503+
&res, sizeof(res));
1504+
printf("ftdc ret %d\n", ret);
1505+
if (ret)
1506+
return -1;
1507+
1508+
ret = write(fd, res.data, (res.data[0]+1)*4);
1509+
if (ret < 0)
1510+
return ret;
1511+
1512+
read += length;
1513+
cmd.req_seq++;
1514+
1515+
}
1516+
1517+
return 0;
1518+
}
1519+
14671520
static int log_ram_flash_to_file(struct switchtec_dev *dev,
14681521
int gen5_cmd, int gen4_cmd, int gen4_cmd_lgcy,
14691522
int fd, FILE *log_def_file,
@@ -1522,6 +1575,8 @@ int switchtec_log_to_file(struct switchtec_dev *dev,
15221575
MRPC_FWLOGRD_FLASH_WITH_FLAG,
15231576
MRPC_FWLOGRD_FLASH,
15241577
fd, log_def_file, info);
1578+
case SWITCHTEC_LOG_FTDC:
1579+
return log_d_to_file(dev, MRPC_FWLOGRD_RAM, fd);
15251580
case SWITCHTEC_LOG_MEMLOG:
15261581
return log_b_to_file(dev, MRPC_FWLOGRD_MEMLOG, fd);
15271582
case SWITCHTEC_LOG_REGS:
@@ -1605,15 +1660,25 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
16051660
memset(info, 0, sizeof(*info));
16061661

16071662
if ((log_type != SWITCHTEC_LOG_PARSE_TYPE_APP) &&
1608-
(log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX)) {
1609-
errno = EINVAL;
1663+
(log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) &&
1664+
(log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)) {
1665+
errno = EINVAL;
16101666
return -errno;
16111667
}
16121668

16131669
ret = parse_log_header(bin_log_file, &fw_version_log,
16141670
&sdk_version_log);
16151671
if (ret)
16161672
return ret;
1673+
1674+
if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1675+
{
1676+
ret = parse_log_header(bin_log_file, &fw_version_log,
1677+
&sdk_version_log);
1678+
if (ret)
1679+
return ret;
1680+
}
1681+
16171682
ret = parse_def_header(log_def_file, &fw_version_def,
16181683
&sdk_version_def);
16191684
if (ret)
@@ -1632,13 +1697,17 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
16321697
info->log_sdk_version = sdk_version_log;
16331698
}
16341699
/* read the log definition file into defs */
1635-
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP)
1700+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
16361701
ret = read_app_log_defs(log_def_file, &defs);
16371702
else
16381703
ret = read_mailbox_log_defs(log_def_file, &defs);
16391704

1640-
ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1641-
fw_version_log, 0);
1705+
if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1706+
ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1707+
fw_version_log, 0);
1708+
else
1709+
ret = append_ftdc_log_header(fileno(parsed_log_file), sdk_version_def,
1710+
fw_version_def);
16421711
if (ret < 0)
16431712
return ret;
16441713

0 commit comments

Comments
 (0)