Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
add_executable(sof-logger
logger.c
convert.c
filter.c
misc.c
)

target_compile_options(sof-logger PRIVATE
Expand Down
96 changes: 32 additions & 64 deletions tools/logger/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Author: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
// Artur Kloniecki <arturx.kloniecki@linux.intel.com>

#include <stdarg.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -16,6 +15,8 @@
#include <user/abi_dbg.h>
#include <user/trace.h>
#include "convert.h"
#include "filter.h"
#include "misc.h"

#define CEIL(a, b) ((a+b-1)/b)

Expand Down Expand Up @@ -52,67 +53,6 @@ struct proc_ldc_entry {

static const char *BAD_PTR_STR = "<bad uid ptr %x>";

char *vasprintf(const char *format, va_list args)
{
va_list args_copy;
int size;
char localbuf[1];
char *result;

va_copy(args_copy, args);
size = vsnprintf(localbuf, 1, format, args_copy);
va_end(args_copy);

result = calloc(1, size + 1);
if (result)
vsnprintf(result, size + 1, format, args);
return result;
}

char *asprintf(const char *format, ...)
{
va_list args;
char *result;

va_start(args, format);
result = vasprintf(format, args);
va_end(args);

return result;
}

static void log_err(FILE *out_fd, const char *fmt, ...)
{
static const char prefix[] = "error: ";
ssize_t needed_size;
va_list args, args_alloc;
char *buff;

va_start(args, fmt);

va_copy(args_alloc, args);
needed_size = vsnprintf(NULL, 0, fmt, args_alloc) + 1;
buff = malloc(needed_size);
va_end(args_alloc);

if (buff) {
vsprintf(buff, fmt, args);
fprintf(stderr, "%s%s", prefix, buff);

/* take care about out_fd validity and duplicated logging */
if (out_fd && out_fd != stderr && out_fd != stdout) {
fprintf(out_fd, "%s%s", prefix, buff);
fflush(out_fd);
}
free(buff);
} else {
fprintf(stderr, "%s", prefix);
vfprintf(stderr, fmt, args);
}

va_end(args);
}

char *format_uid_raw(const struct sof_uuid_entry *uid_entry, int use_colors,
int name_first)
{
Expand Down Expand Up @@ -141,6 +81,25 @@ get_uuid_entry(const struct snd_sof_uids_header *uids_dict, uint32_t uid_ptr)
uids_dict->base_address);
}

/*
* Use uids dictionary content, to convert address of uuid `entry` from logger
* memory space to corresponding uuid key address used in firmware trace system
* (with base UUID_ENTRY_ELF_BASE, 0x1FFFA000 as usual). Function get_uuid_entry
* works in oppopsite direction.
*/
uint32_t get_uuid_key(const struct snd_sof_uids_header *uids_dict,
const struct sof_uuid_entry *entry)
{
/*
* uids_dict->data_offset and uids_dict->base_address are both constants,
* related with given ldc file.
* Uuid address used in firmware, points unusable memory region,
* so its treated as key value.
*/
return (uintptr_t)entry - (uintptr_t)uids_dict -
uids_dict->data_offset + uids_dict->base_address;
}

const char *format_uid(const struct snd_sof_uids_header *uids_dict,
uint32_t uid_ptr,
int use_colors)
Expand Down Expand Up @@ -715,8 +674,7 @@ static int dump_ldc_info(struct convert_config *config,

while (remaining > 0) {
name = format_uid_raw(&uid_ptr[cnt], 0, 0);
uid_addr = (uintptr_t)&uid_ptr[cnt] - (uintptr_t)uids_dict -
uids_dict->data_offset + uids_dict->base_address;
uid_addr = get_uuid_key(uids_dict, &uid_ptr[cnt]);
fprintf(out_fd, "\t0x%lX %s\n", uid_addr, name);

if (name) {
Expand Down Expand Up @@ -806,5 +764,15 @@ int convert(struct convert_config *config)
if (config->dump_ldc)
return dump_ldc_info(config, &snd);

if (config->filter_config) {
ret = filter_update_firmware(config->uids_dict,
config->filter_config);
if (ret) {
log_err(config->out_fd,
"failed to apply trace filter, %d.\n", ret);
return ret;
}
}

return logger_read(config, &snd);
}
4 changes: 4 additions & 0 deletions tools/logger/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <stdio.h>
#include <ipc/info.h>
#include <smex/ldc.h>
#include <sof/lib/uuid.h>

#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
Expand All @@ -29,6 +30,7 @@ struct convert_config {
int trace;
const char *ldc_file;
FILE* ldc_fd;
char *filter_config;
int input_std;
int version_fw;
char *version_file;
Expand All @@ -42,4 +44,6 @@ struct convert_config {
struct snd_sof_uids_header *uids_dict;
};

uint32_t get_uuid_key(const struct snd_sof_uids_header *uids_dict,
const struct sof_uuid_entry *entry);
int convert(struct convert_config *config);
Loading