Skip to content

Commit 19a570c

Browse files
authored
Merge pull request #341 from BenReed161/log-parse-support-for-ftdc-parser-logs
Log parse support for FTDC binary logs
2 parents 0365f85 + 299c91f commit 19a570c

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

cli/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ static int log_parse(int argc, char **argv)
11311131
const struct argconfig_choice log_types[] = {
11321132
{"APP", SWITCHTEC_LOG_PARSE_TYPE_APP, "app log"},
11331133
{"MAILBOX", SWITCHTEC_LOG_PARSE_TYPE_MAILBOX, "mailbox log"},
1134+
{"FTDC", SWITCHTEC_LOG_PARSE_TYPE_FTDC, "ftdc"},
11341135
{}
11351136
};
11361137
const struct argconfig_choice device_gen[] = {
@@ -1209,7 +1210,7 @@ static int log_parse(int argc, char **argv)
12091210
fprintf(stderr, "\nParsed log saved to %s.\n",
12101211
cfg.parsed_log_filename);
12111212

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

inc/switchtec/switchtec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ enum switchtec_log_type {
209209
*/
210210
enum switchtec_log_parse_type {
211211
SWITCHTEC_LOG_PARSE_TYPE_APP,
212-
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX
212+
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX,
213+
SWITCHTEC_LOG_PARSE_TYPE_FTDC
213214
};
214215

215216
/**

lib/switchtec.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ static int write_parsed_log(struct log_a_data log_data[],
10691069
struct module_log_defs *mod_defs;
10701070

10711071
if (entry_idx == 0) {
1072-
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP)
1072+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
10731073
fputs(" #|Timestamp |Module |Severity |Event ID |Event\n",
10741074
log_file);
10751075
else
@@ -1094,7 +1094,7 @@ static int write_parsed_log(struct log_a_data log_data[],
10941094
hours = time % 24;
10951095
days = time / 24;
10961096

1097-
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP) {
1097+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC) {
10981098
/*
10991099
* app log: module ID and log severity are in the 3rd
11001100
* DWord
@@ -1155,7 +1155,7 @@ static int write_parsed_log(struct log_a_data log_data[],
11551155
if (ret < 0)
11561156
goto ret_print_error;
11571157

1158-
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP) {
1158+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC) {
11591159
/* print the module name and log severity */
11601160
if (fprintf(log_file, "%-12s |%-8s |0x%04x |",
11611161
mod_defs->mod_name, log_sev_strs[log_sev],
@@ -1219,6 +1219,23 @@ static int parse_def_header(FILE *log_def_file, uint32_t *fw_version,
12191219
return 0;
12201220
}
12211221

1222+
static int append_ftdc_log_header(int fd, uint32_t sdk_def_version,
1223+
uint32_t fw_def_version)
1224+
{
1225+
int ret;
1226+
char hdr_str_fmt[] = "##########################################\n"
1227+
"## Parsed with FTDC log file from definition:\n"
1228+
"## FW def version %08x\n"
1229+
"## SDK def version %08x\n"
1230+
"##########################################\n\n";
1231+
char hdr_str[512];
1232+
1233+
snprintf(hdr_str, 512, hdr_str_fmt, fw_def_version, sdk_def_version);
1234+
ret = write(fd, hdr_str, strlen(hdr_str));
1235+
1236+
return ret;
1237+
}
1238+
12221239
static int append_log_header(int fd, uint32_t sdk_version,
12231240
uint32_t fw_version, int binary)
12241241
{
@@ -1598,20 +1615,28 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
15981615
memset(info, 0, sizeof(*info));
15991616

16001617
if ((log_type != SWITCHTEC_LOG_PARSE_TYPE_APP) &&
1601-
(log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX)) {
1618+
(log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) &&
1619+
(log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)) {
16021620
errno = EINVAL;
16031621
return -errno;
16041622
}
16051623

1606-
ret = parse_log_header(bin_log_file, &fw_version_log,
1607-
&sdk_version_log);
1608-
if (ret)
1609-
return ret;
1624+
if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1625+
{
1626+
ret = parse_log_header(bin_log_file, &fw_version_log,
1627+
&sdk_version_log);
1628+
if (ret)
1629+
return ret;
1630+
}
1631+
16101632
ret = parse_def_header(log_def_file, &fw_version_def,
16111633
&sdk_version_def);
16121634
if (ret)
16131635
return ret;
16141636

1637+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1638+
fw_version_log = 0;
1639+
16151640
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) {
16161641
fw_version_log = fw_version_def;
16171642
sdk_version_log = sdk_version_def;
@@ -1625,16 +1650,21 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
16251650
info->log_sdk_version = sdk_version_log;
16261651
}
16271652
/* read the log definition file into defs */
1628-
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP)
1653+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
16291654
ret = read_app_log_defs(log_def_file, &defs);
16301655
else
16311656
ret = read_mailbox_log_defs(log_def_file, &defs);
16321657

16331658
if (ret < 0)
16341659
return ret;
16351660

1636-
ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1637-
fw_version_log, 0);
1661+
if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1662+
ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1663+
fw_version_log, 0);
1664+
else
1665+
ret = append_ftdc_log_header(fileno(parsed_log_file), sdk_version_def,
1666+
fw_version_def);
1667+
16381668
if (ret < 0)
16391669
return ret;
16401670

0 commit comments

Comments
 (0)