Skip to content

Commit 299c91f

Browse files
committed
Added support for FTDC bin log parse
Added a new option for the log-parse command to specify FTDC option for parsing. FTDC logs do not contain the magic string that is present in other switchtec logs. Fixes issue to append correct version number in FTDC logs txt output
1 parent 1c0ced0 commit 299c91f

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
@@ -1130,6 +1130,7 @@ static int log_parse(int argc, char **argv)
11301130
const struct argconfig_choice log_types[] = {
11311131
{"APP", SWITCHTEC_LOG_PARSE_TYPE_APP, "app log"},
11321132
{"MAILBOX", SWITCHTEC_LOG_PARSE_TYPE_MAILBOX, "mailbox log"},
1133+
{"FTDC", SWITCHTEC_LOG_PARSE_TYPE_FTDC, "ftdc"},
11331134
{}
11341135
};
11351136
const struct argconfig_choice device_gen[] = {
@@ -1208,7 +1209,7 @@ static int log_parse(int argc, char **argv)
12081209
fprintf(stderr, "\nParsed log saved to %s.\n",
12091210
cfg.parsed_log_filename);
12101211

1211-
if (info.version_mismatch) {
1212+
if (info.version_mismatch && cfg.log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC) {
12121213
fprintf(stderr, "\nWARNING: The two input files have different version numbers.\n");
12131214
fprintf(stderr, "\t\tFW Version\tSDK Version\n");
12141215
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
@@ -208,7 +208,8 @@ enum switchtec_log_type {
208208
*/
209209
enum switchtec_log_parse_type {
210210
SWITCHTEC_LOG_PARSE_TYPE_APP,
211-
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX
211+
SWITCHTEC_LOG_PARSE_TYPE_MAILBOX,
212+
SWITCHTEC_LOG_PARSE_TYPE_FTDC
212213
};
213214

214215
/**

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
{
@@ -1562,20 +1579,28 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
15621579
memset(info, 0, sizeof(*info));
15631580

15641581
if ((log_type != SWITCHTEC_LOG_PARSE_TYPE_APP) &&
1565-
(log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX)) {
1582+
(log_type != SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) &&
1583+
(log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)) {
15661584
errno = EINVAL;
15671585
return -errno;
15681586
}
15691587

1570-
ret = parse_log_header(bin_log_file, &fw_version_log,
1571-
&sdk_version_log);
1572-
if (ret)
1573-
return ret;
1588+
if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1589+
{
1590+
ret = parse_log_header(bin_log_file, &fw_version_log,
1591+
&sdk_version_log);
1592+
if (ret)
1593+
return ret;
1594+
}
1595+
15741596
ret = parse_def_header(log_def_file, &fw_version_def,
15751597
&sdk_version_def);
15761598
if (ret)
15771599
return ret;
15781600

1601+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1602+
fw_version_log = 0;
1603+
15791604
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_MAILBOX) {
15801605
fw_version_log = fw_version_def;
15811606
sdk_version_log = sdk_version_def;
@@ -1589,16 +1614,21 @@ int switchtec_parse_log(FILE *bin_log_file, FILE *log_def_file,
15891614
info->log_sdk_version = sdk_version_log;
15901615
}
15911616
/* read the log definition file into defs */
1592-
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP)
1617+
if (log_type == SWITCHTEC_LOG_PARSE_TYPE_APP || log_type == SWITCHTEC_LOG_PARSE_TYPE_FTDC)
15931618
ret = read_app_log_defs(log_def_file, &defs);
15941619
else
15951620
ret = read_mailbox_log_defs(log_def_file, &defs);
15961621

15971622
if (ret < 0)
15981623
return ret;
15991624

1600-
ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1601-
fw_version_log, 0);
1625+
if (log_type != SWITCHTEC_LOG_PARSE_TYPE_FTDC)
1626+
ret = append_log_header(fileno(parsed_log_file), sdk_version_log,
1627+
fw_version_log, 0);
1628+
else
1629+
ret = append_ftdc_log_header(fileno(parsed_log_file), sdk_version_def,
1630+
fw_version_def);
1631+
16021632
if (ret < 0)
16031633
return ret;
16041634

0 commit comments

Comments
 (0)