2019-06-01 03:43:36 +08:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//
|
|
|
|
// Copyright(c) 2018 Intel Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// Author: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
|
|
|
|
// Artur Kloniecki <arturx.kloniecki@linux.intel.com>
|
|
|
|
|
2016-09-28 00:29:55 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2017-09-04 23:35:01 +08:00
|
|
|
#include <ctype.h>
|
2019-01-09 18:03:57 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <termios.h>
|
2018-10-02 15:36:44 +08:00
|
|
|
#include "convert.h"
|
2018-06-25 12:59:07 +08:00
|
|
|
|
2018-10-12 20:56:41 +08:00
|
|
|
#define APP_NAME "sof-logger"
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2019-07-10 19:25:08 +08:00
|
|
|
#ifndef ARRAY_SIZE
|
2016-09-28 00:29:55 +08:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
2019-07-10 19:25:08 +08:00
|
|
|
#endif
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2017-02-28 19:51:55 +08:00
|
|
|
static const char *debugfs[] = {
|
2018-03-06 22:11:13 +08:00
|
|
|
"dmac0", "dmac1", "ssp0", "ssp1",
|
|
|
|
"ssp2", "iram", "dram", "shim",
|
|
|
|
"mbox", "etrace",
|
2019-06-07 17:53:16 +08:00
|
|
|
"hda", "pp", "dsp",
|
2016-09-28 00:29:55 +08:00
|
|
|
};
|
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "Usage %s <option(s)> <file(s)>\n", APP_NAME);
|
|
|
|
fprintf(stdout, "%s:\t \t\t\tDisplay mailbox contents\n", APP_NAME);
|
2019-10-31 18:22:30 +08:00
|
|
|
fprintf(stdout, "%s:\t -i infile -o outfile\tDump infile contents "
|
|
|
|
"to outfile\n", APP_NAME);
|
2020-04-02 19:57:38 +08:00
|
|
|
fprintf(stdout, "%s:\t -l *.ldc_file\t\t*.ldc files generated by smex\n",
|
|
|
|
APP_NAME);
|
2018-10-15 17:08:06 +08:00
|
|
|
fprintf(stdout, "%s:\t -p \t\t\tInput from stdin\n", APP_NAME);
|
2019-10-31 18:22:30 +08:00
|
|
|
fprintf(stdout, "%s:\t -e \t\t\tEnable checking firmware version with "
|
|
|
|
"default verification file\n", APP_NAME);
|
|
|
|
fprintf(stdout, "%s:\t -v ver_file\t\tEnable checking firmware version "
|
|
|
|
"with ver_file file\n", APP_NAME);
|
2020-03-25 21:39:39 +08:00
|
|
|
fprintf(stdout, "%s:\t -c clock\t\tSet timestamp clock in MHz\n",
|
|
|
|
APP_NAME);
|
2019-10-31 18:22:30 +08:00
|
|
|
fprintf(stdout, "%s:\t -s state_name\t\tTake a snapshot of state\n",
|
|
|
|
APP_NAME);
|
2018-10-02 15:36:44 +08:00
|
|
|
fprintf(stdout, "%s:\t -t\t\t\tDisplay trace data\n", APP_NAME);
|
2019-01-09 18:03:57 +08:00
|
|
|
fprintf(stdout, "%s:\t -u baud\t\tInput data from a UART\n", APP_NAME);
|
2019-10-31 18:22:30 +08:00
|
|
|
fprintf(stdout, "%s:\t -r\t\t\tLess formatted output for "
|
|
|
|
"chained log processors\n",
|
|
|
|
APP_NAME);
|
2020-05-04 21:23:34 +08:00
|
|
|
fprintf(stdout, "%s:\t -L\t\t\tHide log location in source code\n",
|
|
|
|
APP_NAME);
|
2020-05-04 22:09:36 +08:00
|
|
|
fprintf(stdout, "%s:\t -f precision\t\t\tset timestamp precision\n",
|
|
|
|
APP_NAME);
|
2020-03-24 21:54:25 +08:00
|
|
|
fprintf(stdout, "%s:\t -d\t\t\tDump ldc information\n", APP_NAME);
|
2018-10-02 15:36:44 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2016-09-28 00:29:55 +08:00
|
|
|
static int snapshot(const char *name)
|
|
|
|
{
|
2017-10-13 23:41:29 +08:00
|
|
|
const char *path = "/sys/kernel/debug/sof";
|
2016-09-28 00:29:55 +08:00
|
|
|
uint32_t val, addr;
|
|
|
|
char pinname[64], poutname[64], buffer[128];
|
|
|
|
FILE *in_fd, *out_fd;
|
|
|
|
int i, count;
|
|
|
|
|
2020-03-23 20:58:16 +08:00
|
|
|
if (!name) {
|
2017-02-28 19:51:55 +08:00
|
|
|
fprintf(stderr, "error: need snapshot name\n");
|
2016-09-28 00:29:55 +08:00
|
|
|
return -EINVAL;
|
2017-02-28 19:51:55 +08:00
|
|
|
}
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2017-02-28 19:51:55 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(debugfs); i++) {
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2017-02-28 19:51:55 +08:00
|
|
|
sprintf(pinname, "%s/%s", path, debugfs[i]);
|
|
|
|
sprintf(poutname, "%s.%s.txt", name, debugfs[i]);
|
2016-09-28 00:29:55 +08:00
|
|
|
|
|
|
|
/* open debugfs for reading */
|
2019-01-31 18:11:57 +08:00
|
|
|
in_fd = fopen(pinname, "rb");
|
2020-03-23 20:58:16 +08:00
|
|
|
if (!in_fd) {
|
2016-09-28 00:29:55 +08:00
|
|
|
fprintf(stderr, "error: unable to open %s for reading %d\n",
|
|
|
|
pinname, errno);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-31 18:22:30 +08:00
|
|
|
/* open outfile for writing */
|
2019-01-31 18:11:57 +08:00
|
|
|
out_fd = fopen(poutname, "wb");
|
2020-03-23 20:58:16 +08:00
|
|
|
if (!out_fd) {
|
2016-09-28 00:29:55 +08:00
|
|
|
fprintf(stderr, "error: unable to open %s for writing %d\n",
|
|
|
|
poutname, errno);
|
|
|
|
fclose(in_fd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stdout, "processing %s...\n", pinname);
|
|
|
|
addr = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
count = fread(&val, 1, 4, in_fd);
|
|
|
|
if (count != 4)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sprintf(buffer, "0x%6.6x: 0x%8.8x\n", addr, val);
|
|
|
|
|
|
|
|
count = fwrite(buffer, 1, strlen(buffer), out_fd);
|
|
|
|
|
|
|
|
addr += 4;
|
|
|
|
}
|
|
|
|
|
2017-06-15 21:36:24 +08:00
|
|
|
fclose(in_fd);
|
|
|
|
fclose(out_fd);
|
2016-09-28 00:29:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-09 18:03:57 +08:00
|
|
|
static int configure_uart(const char *file, unsigned int baud)
|
|
|
|
{
|
|
|
|
struct termios tio = {};
|
|
|
|
int ret, fd = open(file, O_RDWR | O_NOCTTY);
|
|
|
|
if (fd < 0)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
cfsetspeed(&tio, 115200);
|
|
|
|
cfmakeraw(&tio);
|
|
|
|
|
|
|
|
tio.c_iflag |= IGNBRK;
|
|
|
|
|
|
|
|
tio.c_cflag |= CLOCAL | CREAD | HUPCL;
|
|
|
|
|
|
|
|
tio.c_cc[VTIME] = 1;
|
|
|
|
tio.c_cc[VMIN] = 1;
|
|
|
|
|
|
|
|
ret = tcsetattr(fd, TCSANOW, &tio);
|
|
|
|
return ret < 0 ? -errno : fd;
|
|
|
|
}
|
|
|
|
|
2016-09-28 00:29:55 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2018-10-02 15:36:44 +08:00
|
|
|
struct convert_config config;
|
2019-01-09 18:03:57 +08:00
|
|
|
unsigned int baud = 0;
|
2019-04-15 15:49:28 +08:00
|
|
|
const char *snapshot_file = 0;
|
2018-11-10 00:38:59 +08:00
|
|
|
int opt, ret = 0;
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
config.trace = 0;
|
|
|
|
config.clock = 19.2;
|
|
|
|
config.in_file = NULL;
|
|
|
|
config.out_file = NULL;
|
|
|
|
config.out_fd = NULL;
|
|
|
|
config.in_fd = NULL;
|
|
|
|
config.ldc_file = NULL;
|
2018-10-24 21:17:33 +08:00
|
|
|
config.ldc_fd = NULL;
|
2018-10-08 20:18:08 +08:00
|
|
|
config.input_std = 0;
|
2018-10-24 21:17:33 +08:00
|
|
|
/* checking fw version is disabled by default */
|
|
|
|
config.version_file = NULL;
|
|
|
|
config.version_fd = NULL;
|
|
|
|
config.version_fw = 0;
|
2018-12-04 00:45:42 +08:00
|
|
|
config.use_colors = 1;
|
2019-01-09 18:03:57 +08:00
|
|
|
config.serial_fd = -EINVAL;
|
2019-03-29 23:15:04 +08:00
|
|
|
config.raw_output = 0;
|
2020-03-24 21:54:25 +08:00
|
|
|
config.dump_ldc = 0;
|
2020-05-04 21:23:34 +08:00
|
|
|
config.hide_location = 0;
|
2020-05-04 22:09:36 +08:00
|
|
|
config.float_precision = 6;
|
2018-10-02 15:36:44 +08:00
|
|
|
|
2020-05-04 22:09:36 +08:00
|
|
|
while ((opt = getopt(argc, argv, "ho:i:l:ps:c:u:tev:rdLf:")) != -1) {
|
2016-09-28 00:29:55 +08:00
|
|
|
switch (opt) {
|
|
|
|
case 'o':
|
2018-10-02 15:36:44 +08:00
|
|
|
config.out_file = optarg;
|
2016-09-28 00:29:55 +08:00
|
|
|
break;
|
|
|
|
case 'i':
|
2018-10-02 15:36:44 +08:00
|
|
|
config.in_file = optarg;
|
2016-09-28 00:29:55 +08:00
|
|
|
break;
|
2017-10-12 21:17:09 +08:00
|
|
|
case 't':
|
2018-10-02 15:36:44 +08:00
|
|
|
config.trace = 1;
|
2017-10-12 21:17:09 +08:00
|
|
|
break;
|
2017-06-09 21:55:36 +08:00
|
|
|
case 'c':
|
2018-10-02 15:36:44 +08:00
|
|
|
config.clock = atof(optarg);
|
2017-06-09 21:55:36 +08:00
|
|
|
break;
|
2016-09-28 00:29:55 +08:00
|
|
|
case 's':
|
2019-04-15 15:49:28 +08:00
|
|
|
snapshot_file = optarg;
|
2019-01-09 18:03:57 +08:00
|
|
|
break;
|
2018-10-02 15:36:44 +08:00
|
|
|
case 'l':
|
|
|
|
config.ldc_file = optarg;
|
|
|
|
break;
|
2018-10-08 20:18:08 +08:00
|
|
|
case 'p':
|
|
|
|
config.input_std = 1;
|
|
|
|
break;
|
2018-10-24 21:17:33 +08:00
|
|
|
case 'e':
|
|
|
|
/* enabling checking fw version with default verification
|
|
|
|
* file
|
|
|
|
*/
|
|
|
|
config.version_fw = 1;
|
|
|
|
config.version_file = "/sys/kernel/debug/sof/fw_version";
|
|
|
|
break;
|
2019-01-09 18:03:57 +08:00
|
|
|
case 'u':
|
|
|
|
baud = atoi(optarg);
|
|
|
|
break;
|
2019-03-29 23:15:04 +08:00
|
|
|
case 'r':
|
|
|
|
config.raw_output = 1;
|
|
|
|
break;
|
2018-10-24 21:17:33 +08:00
|
|
|
case 'v':
|
|
|
|
/* enabling checking fw version with ver_file file */
|
|
|
|
config.version_fw = 1;
|
|
|
|
config.version_file = optarg;
|
|
|
|
break;
|
2020-05-04 21:23:34 +08:00
|
|
|
case 'L':
|
|
|
|
config.hide_location = 1;
|
|
|
|
break;
|
2020-05-04 22:09:36 +08:00
|
|
|
case 'f':
|
|
|
|
config.float_precision = atoi(optarg);
|
|
|
|
if (config.float_precision < 0) {
|
|
|
|
usage();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
2020-03-24 21:54:25 +08:00
|
|
|
case 'd':
|
|
|
|
config.dump_ldc = 1;
|
|
|
|
break;
|
2016-09-28 00:29:55 +08:00
|
|
|
case 'h':
|
|
|
|
default: /* '?' */
|
2018-10-02 15:36:44 +08:00
|
|
|
usage();
|
2016-09-28 00:29:55 +08:00
|
|
|
}
|
|
|
|
}
|
2019-01-09 18:03:57 +08:00
|
|
|
|
2019-04-15 15:49:28 +08:00
|
|
|
if (snapshot_file)
|
|
|
|
return baud ? EINVAL : -snapshot(snapshot_file);
|
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
if (!config.ldc_file) {
|
2018-10-24 21:17:33 +08:00
|
|
|
fprintf(stderr, "error: Missing ldc file\n");
|
2018-10-02 15:36:44 +08:00
|
|
|
usage();
|
2018-03-06 22:11:13 +08:00
|
|
|
}
|
2017-10-13 23:41:29 +08:00
|
|
|
|
2019-01-31 18:11:57 +08:00
|
|
|
config.ldc_fd = fopen(config.ldc_file, "rb");
|
2018-10-02 15:36:44 +08:00
|
|
|
if (!config.ldc_fd) {
|
|
|
|
fprintf(stderr, "error: Unable to open ldc file %s\n",
|
|
|
|
config.ldc_file);
|
2019-01-09 17:44:41 +08:00
|
|
|
ret = errno;
|
2018-10-02 15:36:44 +08:00
|
|
|
goto out;
|
2016-09-28 00:29:55 +08:00
|
|
|
}
|
2018-10-24 21:17:33 +08:00
|
|
|
|
|
|
|
if (config.version_fw) {
|
2019-01-31 18:11:57 +08:00
|
|
|
config.version_fd = fopen(config.version_file, "rb");
|
2018-10-24 21:17:33 +08:00
|
|
|
if (!config.version_fd) {
|
2019-02-01 18:59:45 +08:00
|
|
|
fprintf(stderr, "error: Unable to open version file %s\n",
|
2018-10-24 21:17:33 +08:00
|
|
|
config.version_file);
|
2019-01-09 17:44:41 +08:00
|
|
|
ret = errno;
|
2018-10-24 21:17:33 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2018-10-02 15:36:44 +08:00
|
|
|
|
|
|
|
if (config.out_file) {
|
|
|
|
config.out_fd = fopen(config.out_file, "w");
|
|
|
|
if (!config.out_fd) {
|
|
|
|
fprintf(stderr, "error: Unable to open out file %s\n",
|
|
|
|
config.out_file);
|
2019-01-09 17:44:41 +08:00
|
|
|
ret = errno;
|
2018-10-02 15:36:44 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
config.out_fd = stdout;
|
2016-09-28 00:29:55 +08:00
|
|
|
}
|
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
/* trace requested ? */
|
|
|
|
if (config.trace)
|
|
|
|
config.in_file = "/sys/kernel/debug/sof/trace";
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
/* default option with no infile is to dump errors/debug data */
|
|
|
|
if (!config.in_file)
|
|
|
|
config.in_file = "/sys/kernel/debug/sof/etrace";
|
|
|
|
|
2018-10-08 20:18:08 +08:00
|
|
|
if (config.input_std) {
|
|
|
|
config.in_fd = stdin;
|
2019-01-09 18:03:57 +08:00
|
|
|
} else if (baud) {
|
|
|
|
config.serial_fd = configure_uart(config.in_file, baud);
|
|
|
|
if (config.serial_fd < 0) {
|
|
|
|
ret = -config.serial_fd;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-11-19 18:40:05 +08:00
|
|
|
} else {
|
2019-01-31 18:11:57 +08:00
|
|
|
config.in_fd = fopen(config.in_file, "rb");
|
2018-10-02 15:36:44 +08:00
|
|
|
if (!config.in_fd) {
|
|
|
|
fprintf(stderr, "error: Unable to open in file %s\n",
|
|
|
|
config.in_file);
|
2019-01-09 17:44:41 +08:00
|
|
|
ret = errno;
|
2018-10-02 15:36:44 +08:00
|
|
|
goto out;
|
2017-10-12 21:17:09 +08:00
|
|
|
}
|
2018-10-02 15:36:44 +08:00
|
|
|
}
|
2018-12-04 00:45:42 +08:00
|
|
|
if (isatty(fileno(config.out_fd)) != 1)
|
|
|
|
config.use_colors = 0;
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2019-01-09 17:44:41 +08:00
|
|
|
ret = -convert(&config);
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
out:
|
|
|
|
/* close files */
|
2018-10-11 17:34:14 +08:00
|
|
|
if (config.out_fd)
|
2018-10-02 15:36:44 +08:00
|
|
|
fclose(config.out_fd);
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
if (config.in_fd)
|
|
|
|
fclose(config.in_fd);
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
if (config.ldc_fd)
|
|
|
|
fclose(config.ldc_fd);
|
2018-11-19 18:40:05 +08:00
|
|
|
|
2018-10-24 21:17:33 +08:00
|
|
|
if (config.version_fd)
|
|
|
|
fclose(config.version_fd);
|
2016-09-28 00:29:55 +08:00
|
|
|
|
2018-10-02 15:36:44 +08:00
|
|
|
return ret;
|
2016-09-28 00:29:55 +08:00
|
|
|
}
|