logger: add firmware verification capability

I've added two logger flags for firmware version verification:
-e		- enables checking fw version with default file
-v ver_file	- enables checking fw version with ver_file file

Signed-off-by: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
This commit is contained in:
Bartosz Kokoszko 2018-10-24 15:17:33 +02:00
parent 937032fb5f
commit a73c4f63ca
5 changed files with 1102 additions and 13 deletions

14
README
View File

@ -65,11 +65,25 @@ Usage sof-logger <option(s)> <file(s)>
-p Get traces from stdin, instead of the default -p Get traces from stdin, instead of the default
"/sys/kernel/debug/sof/etrace" "/sys/kernel/debug/sof/etrace"
-c Set timestamp clock in MHz -c Set timestamp clock in MHz
-e Enable checking firmware version with default verification file
"/sys/kernel/debug/sof/fw_version"
-v ver_file Enable checking firmware version with ver_file file,
instead of default: "/sys/kernel/debug/sof/fw_version"
-s Take a snapshot of state -s Take a snapshot of state
Examples: Examples:
- Get traces from "/sys/kernel/debug/sof/etrace" file, verifies fw_version with
"/sys/kernel/debug/sof/fw_version" and prints logs to stdout
$ sof-logger -l ldc_file -e
- Get traces from "/sys/kernel/debug/sof/etrace" file, verifies fw_version with
ver_file file and prints logs to stdout
$ sof-logger -l ldc_file -v ver_file
- Get traces from "/sys/kernel/debug/sof/etrace" file and prints logs to stdout - Get traces from "/sys/kernel/debug/sof/etrace" file and prints logs to stdout
$ sof-logger -l ldc_file $ sof-logger -l ldc_file

View File

@ -36,6 +36,9 @@ struct convert_config {
const char *ldc_file; const char *ldc_file;
FILE* ldc_fd; FILE* ldc_fd;
int input_std; int input_std;
int version_fw;
char *version_file;
FILE *version_fd;
#endif #endif
}; };

View File

@ -19,7 +19,7 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include <sof/uapi/ipc.h>
#include "convert.h" #include "convert.h"
#define CEIL(a, b) ((a+b-1)/b) #define CEIL(a, b) ((a+b-1)/b)
@ -32,15 +32,15 @@
#define SND_SOF_LOGS_SIG_SIZE 4 #define SND_SOF_LOGS_SIG_SIZE 4
#define SND_SOF_LOGS_SIG "Logs" #define SND_SOF_LOGS_SIG "Logs"
/*
* Logs dictionary file header.
*/
struct snd_sof_logs_header { struct snd_sof_logs_header {
/* "Logs" */ unsigned char sig[SND_SOF_LOGS_SIG_SIZE]; /* "Logs" */
unsigned char sig[SND_SOF_LOGS_SIG_SIZE]; uint32_t base_address; /* address of log entries section */
/* address of log entries section */ uint32_t data_length; /* amount of bytes following this header */
uint32_t base_address; uint32_t data_offset; /* offset to first entry in this file */
/* amount of bytes following this header */ struct sof_ipc_fw_version version;
uint32_t data_length;
/* offset to first entry in this file */
uint32_t data_offset;
}; };
struct ldc_entry_header { struct ldc_entry_header {
@ -145,7 +145,7 @@ static void print_entry_params(FILE *out_fd, struct dma_log dma_log,
entry.params[2], entry.params[3]); entry.params[2], entry.params[3]);
break; break;
} }
fprintf(out_fd, "\n"); fprintf(out_fd, "%s\n", KNRM);
fflush(out_fd); fflush(out_fd);
} }
@ -319,5 +319,25 @@ int convert(struct convert_config *config) {
return -EINVAL; return -EINVAL;
} }
/* fw verification */
if (config->version_fd) {
struct sof_ipc_fw_version ver;
int i;
/* here fw verification should be exploited */
count = fread(&ver, sizeof(ver), 1, config->version_fd);
if (!count) {
fprintf(stderr, "Error while reading %s. \n", config->version_file);
return -ferror(config->version_fd);
}
ret = memcmp(&ver, &snd.version, sizeof(struct sof_ipc_fw_version));
if (ret) {
fprintf(stderr, "Error: fw version in %s file "
"does not coincide with fw version in "
"%s file. \n", config->ldc_file, config->version_file);
return -EINVAL;
}
}
return logger_read(config, &snd); return logger_read(config, &snd);
} }

View File

@ -43,6 +43,8 @@ static void usage(void)
#ifdef LOGGER_FORMAT #ifdef LOGGER_FORMAT
fprintf(stdout, "%s:\t -l *.ldc_file\t\t*.ldc files generated by rimage\n", APP_NAME); fprintf(stdout, "%s:\t -l *.ldc_file\t\t*.ldc files generated by rimage\n", APP_NAME);
fprintf(stdout, "%s:\t -p \t\t\tInput from stdin\n", APP_NAME); fprintf(stdout, "%s:\t -p \t\t\tInput from stdin\n", APP_NAME);
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);
#endif #endif
fprintf(stdout, "%s:\t -c\t\t\tSet timestamp clock in MHz\n", APP_NAME); fprintf(stdout, "%s:\t -c\t\t\tSet timestamp clock in MHz\n", APP_NAME);
fprintf(stdout, "%s:\t -s\t\t\tTake a snapshot of state\n", APP_NAME); fprintf(stdout, "%s:\t -s\t\t\tTake a snapshot of state\n", APP_NAME);
@ -123,11 +125,16 @@ int main(int argc, char *argv[])
config.in_fd = NULL; config.in_fd = NULL;
#ifdef LOGGER_FORMAT #ifdef LOGGER_FORMAT
config.ldc_file = NULL; config.ldc_file = NULL;
config.ldc_fd = NULL;
config.input_std = 0; config.input_std = 0;
/* checking fw version is disabled by default */
config.version_file = NULL;
config.version_fd = NULL;
config.version_fw = 0;
#endif #endif
#ifdef LOGGER_FORMAT #ifdef LOGGER_FORMAT
while ((opt = getopt(argc, argv, "ho:i:l:ps:m:c:t")) != -1) { while ((opt = getopt(argc, argv, "ho:i:l:ps:m:c:tev:")) != -1) {
#else #else
while ((opt = getopt(argc, argv, "ho:i:s:m:c:t")) != -1) { while ((opt = getopt(argc, argv, "ho:i:s:m:c:t")) != -1) {
#endif #endif
@ -153,6 +160,18 @@ int main(int argc, char *argv[])
case 'p': case 'p':
config.input_std = 1; config.input_std = 1;
break; break;
case 'e':
/* enabling checking fw version with default verification
* file
*/
config.version_fw = 1;
config.version_file = "/sys/kernel/debug/sof/fw_version";
break;
case 'v':
/* enabling checking fw version with ver_file file */
config.version_fw = 1;
config.version_file = optarg;
break;
#endif #endif
case 'h': case 'h':
default: /* '?' */ default: /* '?' */
@ -161,8 +180,9 @@ int main(int argc, char *argv[])
} }
#ifdef LOGGER_FORMAT #ifdef LOGGER_FORMAT
if (!config.ldc_file) { if (!config.ldc_file) {
fprintf(stderr, "error: Missing ldc file"); fprintf(stderr, "error: Missing ldc file\n");
usage(); usage();
} }
@ -173,6 +193,16 @@ int main(int argc, char *argv[])
ret = -errno; ret = -errno;
goto out; goto out;
} }
if (config.version_fw) {
config.version_fd = fopen(config.version_file, "r");
if (!config.version_fd) {
fprintf(stderr, "error: Unable to open ver file %s\n",
config.version_file);
ret = -errno;
goto out;
}
}
#endif #endif
if (config.out_file) { if (config.out_file) {
@ -223,6 +253,8 @@ out:
#ifdef LOGGER_FORMAT #ifdef LOGGER_FORMAT
if (config.ldc_fd) if (config.ldc_fd)
fclose(config.ldc_fd); fclose(config.ldc_fd);
if (config.version_fd)
fclose(config.version_fd);
#endif #endif
return ret; return ret;

1020
rmbox/sof/uapi/ipc.h Normal file

File diff suppressed because it is too large Load Diff