Skip to content

Commit

Permalink
Merge pull request zephyrproject-rtos#6 from dcpleung/sof_zephyr
Browse files Browse the repository at this point in the history
Update code to boot on QEMU and UP Squared board
  • Loading branch information
Vudentz authored Aug 16, 2019
2 parents 6c2b616 + 5190276 commit 4a6dd9c
Show file tree
Hide file tree
Showing 30 changed files with 2,066 additions and 154 deletions.
33 changes: 33 additions & 0 deletions boards/xtensa/up_squared_adsp/tools/logtool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3

#FILE = "/dev/shm/qemu-bridge-hp-sram-mem"
FILE = "/sys/kernel/debug/sof/etrace"
#OFFSET = 0x8000
OFFSET = 0x0
MAGIC = 0x55aa
SLOT_NUM = 32
SLOT_LEN = 256

def read_id(f):
buf = f.read(2)
return int.from_bytes(buf, byteorder='little')

def read_magic(f):
buf = f.read(2)
return int.from_bytes(buf, byteorder='little')

def read_log_slot(f):
magic = read_magic(f)

if magic == MAGIC:
id = read_id(f)
slot = f.read(SLOT_LEN - 4)
logstr = slot.decode(errors='replace').split('\r', 1)[0]
print("id %d %s" % (id, logstr))

# Open a file
f = open(FILE, "rb")

for x in range(0, SLOT_NUM):
f.seek(OFFSET + x * SLOT_LEN)
read_log_slot(f)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zephyr_adsp_logger
*.o
14 changes: 14 additions & 0 deletions boards/xtensa/up_squared_adsp/tools/zephyr_adsp_logger/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: all clean
.SECONDARY:

CFLAGS = -march=native -O2 -g

EXECUTABLES = zephyr_adsp_logger

all: $(EXECUTABLES)

clean:
rm -f $(EXECUTABLES)

%.o: %.c
$(C) $(CFLAGS) -c $< -o $@
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#define MAGIC 0x55AA

struct config_t {
char *infile;

unsigned long int trace_size;
unsigned long int buf_size;

unsigned long int interval_usecs;
} cfg;

struct log_t {
uint16_t magic;
uint16_t id;
char log[0];
};

char *sof_etrace_path = "/sys/kernel/debug/sof/etrace";
char *qemu_etrace_path = "/dev/shm/qemu-bridge-etrace-mem";

unsigned long int default_trace_size = 0x2000;
unsigned long int default_buf_size = 256;

void usage(char *prog_name)
{
fprintf(stdout, "Usage: %s [options]\n\n", prog_name);
fprintf(stdout, "Options:\n");
fprintf(stdout, " -s : Use %s as input\n", sof_etrace_path);
fprintf(stdout, " -q : Use %s as input\n", qemu_etrace_path);
fprintf(stdout, " -i infile : Use infile as input\n");
fprintf(stdout, "\n");
fprintf(stdout,
" -t size : Size of the trace buffer (in bytes, default %lu)\n",
default_trace_size);
fprintf(stdout,
" -b size : Size of buffer of one log line (in bytes, default %lu)\n",
default_buf_size);
fprintf(stdout, "\n");
fprintf(stdout,
" -n usecs : Read logs with update interval (microseconds, default is to read once)\n");
}

int read_logs()
{
FILE *fd;
int ret;
unsigned long int offset;
struct log_t *log;
uint8_t *buf = NULL;
char *log_buf = NULL;
unsigned int max_log_strlen;

max_log_strlen = cfg.buf_size - sizeof(log->magic) - sizeof(log->id);

/* Open file */
fd = fopen(cfg.infile, "rb");
if (!fd) {
fprintf(stderr,
"[ERROR] Cannot open %s for reading!\n", cfg.infile);
ret = -1;
goto read_out;
}

/* Allocate buffers */
buf = malloc(cfg.trace_size);
if (!buf) {
fprintf(stderr,
"[ERROR] Cannot allocate trace buffer!\n");
ret = -2;
goto read_out;
}

log_buf = malloc(cfg.buf_size + 1);
if (!log_buf) {
fprintf(stderr,
"[ERROR] Cannot allocate log buffer!\n");
ret = -2;
goto read_out;
}

read_repeat:
fprintf(stdout, "\n");

/* Read everything in file */
rewind(fd);
ret = fread(buf, 1, cfg.trace_size, fd);
if (ret == 0) {
fprintf(stderr,
"[ERROR] Nothing to read?\n");
ret = -3;
goto read_out;
}

/* Go through each log line and display it */
offset = 0;
while ((offset + cfg.buf_size) <= cfg.trace_size) {
log = (struct log_t *)(buf + offset);

if (log->magic == MAGIC) {
/* Avoid non-null terminated strings */
ret = snprintf(log_buf, max_log_strlen,
"%s", &log->log[0]);
log_buf[max_log_strlen] = 0;

fprintf(stdout, "[ID:%5u] %s", log->id, log_buf);
}

/* Move to next log line */
offset += cfg.buf_size;
};

/* If interval is specified, wait and loop */
if (cfg.interval_usecs) {
usleep(cfg.interval_usecs);
goto read_repeat;
}

ret = 0;

read_out:
if (buf) {
free(buf);
}
if (log_buf) {
free(log_buf);
}
if (fd) {
fclose(fd);
}
return ret;
}

int main(int argc, char *argv[])
{
int opt, ret = 0;

/* Defaults */
cfg.infile = sof_etrace_path;
cfg.trace_size = default_trace_size;
cfg.buf_size = default_buf_size;
cfg.interval_usecs = 0;

/* Parse arguments */
while ((opt = getopt(argc, argv, "hsqi:t:b:n:")) != -1) {
switch (opt) {
case 's':
cfg.infile = sof_etrace_path;
break;
case 'q':
cfg.infile = qemu_etrace_path;
break;
case 'i':
cfg.infile = optarg;
break;
case 't':
cfg.trace_size = strtoul(optarg, NULL, 0);
if (cfg.trace_size == ULONG_MAX) {
fprintf(stderr, "[ERROR] Error parsing -t\n");
ret = errno;
goto main_out;
}
break;
case 'b':
cfg.buf_size = strtoul(optarg, NULL, 0);
if (cfg.buf_size == ULONG_MAX) {
fprintf(stderr, "[ERROR] Error parsing -b\n");
ret = errno;
goto main_out;
}
break;
case 'n':
cfg.interval_usecs = strtoul(optarg, NULL, 0);
if (cfg.interval_usecs == ULONG_MAX) {
fprintf(stderr, "[ERROR] Error parsing -n\n");
ret = errno;
goto main_out;
}
break;
case 'h':
default:
usage(argv[0]);
goto main_out;
}
}

fprintf(stdout, "[INFO ] Using %s as input file\n", cfg.infile);
fprintf(stdout, "[INFO ] Trace buffer size: %lu\n", cfg.trace_size);
fprintf(stdout, "[INFO ] Log line buffer size: %lu\n", cfg.buf_size);
if (cfg.interval_usecs == 0) {
fprintf(stdout, "[INFO ] Read once\n");
} else {
fprintf(stdout, "[INFO ] Update Interval: %lu\n",
cfg.interval_usecs);
}

ret = read_logs();

main_out:
return ret;
}
1 change: 1 addition & 0 deletions samples/audio/sof/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG_SOF=y
CONFIG_LOG=y
CONFIG_LOG_BACKEND_XTENSA_SIM=y
CONFIG_LOG_BACKEND_ADSP=y
CONFIG_LOG_IMMEDIATE=y
CONFIG_SOF_LOG_LEVEL=4
# SOF requires malloc/calloc
Expand Down
75 changes: 1 addition & 74 deletions samples/hello_world/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,7 @@
#include <zephyr.h>
#include <sys/printk.h>

#include <stdint.h>

#include <xtensa/config/core.h>
#include <xtensa/hal.h>

#define CONFIG_TRACE 1

/* SRAM window 0 FW "registers" */
#define SRAM_REG_ROM_STATUS 0x0
#define SRAM_REG_FW_STATUS 0x4
#define SRAM_REG_FW_TRACEP 0x8
#define SRAM_REG_FW_IPC_RECEIVED_COUNT 0xc
#define SRAM_REG_FW_IPC_PROCESSED_COUNT 0x10
#define SRAM_REG_FW_END 0x14

#define HP_SRAM_BASE 0xBE000000
#define HEAP_HP_BUFFER_BASE HP_SRAM_BASE
#define HEAP_HP_BUFFER_SIZE 0x8000
#define SRAM_WND_BASE (HEAP_HP_BUFFER_BASE + HEAP_HP_BUFFER_SIZE)
#define SRAM_SW_REG_BASE (SRAM_INBOX_BASE + SRAM_INBOX_SIZE)
#define MAILBOX_SW_REG_BASE SRAM_SW_REG_BASE

#define SRAM_TRACE_BASE SRAM_WND_BASE
#if CONFIG_TRACE
#define SRAM_TRACE_SIZE 0x2000
#else
#define SRAM_TRACE_SIZE 0
#endif
#define SRAM_DEBUG_BASE (SRAM_TRACE_BASE + SRAM_TRACE_SIZE)
#define SRAM_DEBUG_SIZE 0x800
#define SRAM_EXCEPT_BASE (SRAM_DEBUG_BASE + SRAM_DEBUG_SIZE)
#define SRAM_EXCEPT_SIZE 0x800
#define SRAM_STREAM_BASE (SRAM_EXCEPT_BASE + SRAM_EXCEPT_SIZE)
#define SRAM_STREAM_SIZE 0x1000
#define SRAM_INBOX_BASE (SRAM_STREAM_BASE + SRAM_STREAM_SIZE)
#define SRAM_INBOX_SIZE 0x2000

#define DCACHE_LINE_SIZE XCHAL_DCACHE_LINESIZE

static inline void dcache_writeback_region(void *addr, size_t size)
{
#if XCHAL_DCACHE_SIZE > 0
xthal_dcache_region_writeback(addr, size);
#endif
}

static inline void mailbox_sw_reg_write(size_t offset, uint32_t src)
{
*((volatile uint32_t*)(MAILBOX_SW_REG_BASE + offset)) = src;
dcache_writeback_region((void *)(MAILBOX_SW_REG_BASE + offset),
sizeof(src));
}

/* Platform defined trace code */
#define platform_trace_point(__x) \
mailbox_sw_reg_write(SRAM_REG_FW_TRACEP, (__x))


#define SHIM_BASE 0x00001000

static inline uint32_t shim_read(uint32_t reg)
{
return *((volatile uint32_t*)(SHIM_BASE + reg));
}

static inline void shim_write(uint32_t reg, uint32_t val)
{
*((volatile uint32_t*)(SHIM_BASE + reg)) = val;
}

void main(void)
{
mailbox_sw_reg_write(SRAM_REG_ROM_STATUS, 0xabbac0fe);
#if 0
platform_trace_point(0xabbac0ffe);
#endif
printk("Hello World! %s\n", CONFIG_BOARD);
}
1 change: 1 addition & 0 deletions soc/xtensa/intel_apl_adsp/include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "sof_config.h"
Loading

0 comments on commit 4a6dd9c

Please sign in to comment.