Skip to content

Commit 5dc6817

Browse files
authored
Merge pull request #12 from MicrochipTech/feature/ftdc_command
Feature/ftdc command
2 parents 1f0ea41 + c3838d0 commit 5dc6817

File tree

6 files changed

+97
-13
lines changed

6 files changed

+97
-13
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
@@ -230,6 +230,7 @@ enum switchtec_bw_type {
230230
enum switchtec_log_type {
231231
SWITCHTEC_LOG_RAM,
232232
SWITCHTEC_LOG_FLASH,
233+
SWITCHTEC_LOG_FTDC,
233234
SWITCHTEC_LOG_MEMLOG,
234235
SWITCHTEC_LOG_REGS,
235236
SWITCHTEC_LOG_SYS_STACK,
@@ -243,7 +244,8 @@ enum switchtec_log_type {
243244
*/
244245
enum switchtec_log_parse_type {
245246
SWITCHTEC_LOG_PARSE_TYPE_APP,
246-
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX
247+
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX,
248+
SWITCHTEC_LOG_PARSE_TYPE_FTDC,
247249
};
248250

249251
/**

lib/platform/gasops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static const struct no_retry_struct gasop_noretry_cmds[] = {
6565
[MRPC_DBG_UNLOCK] = {1, 0, NULL},
6666
[MRPC_SECURITY_CONFIG_SET_GEN5] = {1, 0, NULL},
6767
[MRPC_FW_TX] = {1, 1, fw_toggle_noretry_subcmds},
68+
[MRPC_FTDC_LOG_DUMP] = {0, 0, NULL},
6869
};
6970
static const int gasop_noretry_cmds_count = (sizeof(gasop_noretry_cmds)) /
7071
(sizeof(char));

lib/switchtec.c

Lines changed: 77 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,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+
14671518
static 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

Comments
 (0)