FreeCalypso > hg > freecalypso-tools
changeset 540:27b5526ba1a8
dspdump target program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 28 Oct 2019 08:19:33 +0000 |
parents | 4f346c10f056 |
children | a58563d16e1d |
files | target-utils/dspdump/Makefile target-utils/dspdump/cmdtab.c target-utils/dspdump/dspops.c target-utils/dspdump/dumpagent.c target-utils/dspdump/dumpagent.h target-utils/dspdump/leadapi.h target-utils/dspdump/main.c target-utils/dspdump/mandump.c |
diffstat | 8 files changed, 277 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/Makefile Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,29 @@ +CC= arm-elf-gcc +CFLAGS= -Os -fno-builtin +CPPFLAGS=-I../include +LD= arm-elf-ld +OBJCOPY=arm-elf-objcopy + +PROG= dspdump +OBJS= crt0.o cmdtab.o dspops.o dumpagent.o main.o mandump.o +LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a \ + ../libc/libc.a +LIBGCC= `${CC} -print-file-name=libgcc.a` +LDS= ../env/iram.lds + +all: ${PROG}.srec + +crt0.S: + ln -s ../env/crt0.S . + +${PROG}.elf: ${OBJS} ${LIBS} ${LDS} + ${LD} -N --defsym Base_addr=0x800750 --defsym stack_bottom=0x83FFFC \ + -T ${LDS} -o $@ ${OBJS} ${LIBS} ${LIBGCC} + +${PROG}.srec: ${PROG}.elf + ${OBJCOPY} -O srec --srec-forceS3 --srec-len=30 $< $@ + +clean: + rm -f *.o *errs *core *.elf *.bin *.srec crt0.S + +FRC:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/cmdtab.c Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,33 @@ +#include "cmdtab.h" + +extern void cmd_abbr(); +extern void cmd_abbw(); +extern void cmd_dump(); +extern void cmd_jump(); +extern void cmd_r8(); +extern void cmd_r16(); +extern void cmd_r32(); +extern void cmd_w8(); +extern void cmd_w16(); +extern void cmd_w32(); + +extern void abb_init(); +extern void abb_power_off(); +extern void abb_unlock_page2(); + +const struct cmdtab cmdtab[] = { + {"abbinit", abb_init}, + {"abbpage2", abb_unlock_page2}, + {"abbr", cmd_abbr}, + {"abbw", cmd_abbw}, + {"dump", cmd_dump}, + {"jump", cmd_jump}, + {"poweroff", abb_power_off}, + {"r8", cmd_r8}, + {"r16", cmd_r16}, + {"r32", cmd_r32}, + {"w8", cmd_w8}, + {"w16", cmd_w16}, + {"w32", cmd_w32}, + {0, 0} +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/dspops.c Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,75 @@ +#include "types.h" +#include "leadapi.h" +#include "dumpagent.h" + +wait_for_dsp_ready() +{ + unsigned cnt; + + for (cnt = 0; cnt < 10000; cnt++) + if (DOWNLOAD_STATUS == LEAD_READY) + return(0); + return(-1); +} + +boot_dsp_dump_agent() +{ + const u16 *src; + volatile u16 *api; + unsigned n; + + /* put it into reset first */ + CLKM_CNTL_RST |= CLKM_LEAD_RST; + /* generous 1 ms for the reset pulse */ + wait_ARM_cycles(13000); + /* lift it out of reset */ + CLKM_CNTL_RST &= ~CLKM_LEAD_RST; + /* another generous 1 ms */ + wait_ARM_cycles(13000); + /* bootloader should be ready for us now */ + if (wait_for_dsp_ready() < 0) { + printf("ERROR: DSP bootloader not ready out of reset\n"); + return(-1); + } + /* upload the agent code */ + src = dsp_agent_code; + api = (volatile u16 *) APIF_ADDR; + for (n = 0; n < DSP_DUMPCODE_LEN; n++) + *api++ = *src++; + DOWNLOAD_EXT_PAGE = 0; + DOWNLOAD_SIZE = DSP_DUMPCODE_LEN; + DOWNLOAD_ADDR = DSP_DUMPCODE_START; + DOWNLOAD_STATUS = BLOCK_READY; + if (wait_for_dsp_ready() < 0) { + printf("ERROR: DSP bl not ready after block write\n"); + return(-1); + } + /* start it! */ + DOWNLOAD_EXT_PAGE = 0; + DOWNLOAD_SIZE = 0; + DOWNLOAD_ADDR = DSP_DUMPCODE_START; + DOWNLOAD_STATUS = BLOCK_READY; + if (wait_for_dsp_ready() < 0) { + printf("ERROR: DSP not ready after commanded jump to agent\n"); + return(-1); + } +} + +dsp_read_op(mode, addr, blklen) + u16 mode, blklen; + u32 addr; +{ + int rc; + + APIRAM_FIRST_WORD = mode; + DOWNLOAD_STATUS = PAGE_SELECTION; + rc = wait_for_dsp_ready(); + if (rc < 0) + return(rc); + DOWNLOAD_EXT_PAGE = addr >> 16; + DOWNLOAD_SIZE = blklen; + DOWNLOAD_ADDR = addr; + DOWNLOAD_STATUS = BLOCK_READY; + rc = wait_for_dsp_ready(); + return(rc); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/dumpagent.c Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,37 @@ +/* + * The following dump agent code has been taken from OsmocomBB. This code + * is run on the Calypso DSP by way of the DSP's bootloader, i.e., it is + * booted in the place of the ROM or production patch code, and it provides + * an API protocol to the ARM7 host by way of which we read out the ROM code. + * + * For the corresponding source for this DSP agent code, please refer to the + * OsmocomBB code repository - we have not modified it in FreeCalypso. + */ + +#include "types.h" + +u16 dsp_agent_code[0x5B] = { + 0x69f8, 0x0029, 0x0002, 0xea1f, + 0x7718, 0x1100, 0x7714, 0x0000, + 0x7712, 0x0800, 0x767f, 0x0001, + 0x607f, 0xffff, 0xf820, 0x1014, + 0xf273, 0x1008, 0x7682, 0x0100, + 0x607f, 0x0004, 0xf820, 0x101c, + 0xf273, 0x1008, 0x7214, 0x0800, + 0x607f, 0x0002, 0xf820, 0x100c, + 0x127e, 0x8813, 0x3c7c, 0x137d, + 0x8911, 0xf84c, 0x1028, 0xf4e2, + 0x7715, 0x0014, 0x963d, 0xfa30, + 0x104b, 0x6d89, 0x963f, 0xfa30, + 0x103f, 0x963e, 0xf495, 0xf830, + 0x103a, 0x47f8, 0x0011, 0x7f92, + 0xf073, 0x1008, 0x47f8, 0x0011, + 0x7e92, 0xf073, 0x1008, 0xf830, + 0x1046, 0x47f8, 0x0011, 0xe589, + 0xf073, 0x1008, 0x47f8, 0x0011, + 0xe598, 0xf073, 0x1008, 0x4911, + 0x891a, 0xf830, 0x1055, 0xf072, + 0x1052, 0xf074, 0x7213, 0xf073, + 0x1008, 0xf072, 0x1058, 0xf074, + 0xe4b8, 0xf073, 0x1008 +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/dumpagent.h Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,6 @@ +/* definitions for the DSP dump agent code */ + +#define DSP_DUMPCODE_START 0x1000 +#define DSP_DUMPCODE_LEN 0x5B + +extern u16 dsp_agent_code[];
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/leadapi.h Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,42 @@ +/* + * Definitions for the DSP boot and patch download mechanism, + * taken from leadapi.h in TCS211. This version has been + * further modified for the DSP dump application. + */ + +#define APIF_ADDR 0xFFD00000L + +#define APIRAM_FIRST_WORD *((volatile u16 *) APIF_ADDR) + +#define DOWNLOAD_EXT_PAGE *((volatile u16 *) (APIF_ADDR + 0x0FF8)) +#define DOWNLOAD_SIZE *((volatile u16 *) (APIF_ADDR + 0x0FFA)) +#define DOWNLOAD_ADDR *((volatile u16 *) (APIF_ADDR + 0x0FFC)) +#define DOWNLOAD_STATUS *((volatile u16 *) (APIF_ADDR + 0x0FFE)) + +/* Maximum size of a block which can be copied into the API RAM */ + +#define MAX_BLOCK_SIZE 0x7F0 + +/* Possible values for the download status */ + +#define LEAD_READY 1 +#define BLOCK_READY 2 +#define PROGRAM_DONE 3 +#define PAGE_SELECTION 4 + +/* DSP reset control register definitions */ + +#define MEM_CLKM_ADDR 0xfffffd00 /* CLKM registers addr. */ +#define CLKM_CNTL_RST *((volatile u16 *) (MEM_CLKM_ADDR + 4)) + +#define CLKM_LEAD_RST 0x0002 +#define CLKM_EXT_RST 0x0004 + +/* extensions provided by OsmocomBB's DSP dump agent */ + +#define BL_MODE_PROG_WRITE 0 +#define BL_MODE_DATA_WRITE 1 +#define BL_MODE_PROG_READ 2 +#define BL_MODE_DATA_READ 3 +#define BL_MODE_PROM_READ 4 +#define BL_MODE_DROM_READ 5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/main.c Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,13 @@ +#include "types.h" + +main() +{ + uart_select_init(); + printf("Calypso DSP dump program running\n"); + print_boot_rom_info(); + for (;;) { + putchar('='); + if (command_entry()) + command_dispatch(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/dspdump/mandump.c Mon Oct 28 08:19:33 2019 +0000 @@ -0,0 +1,42 @@ +/* manual dump command */ + +#include <sys/types.h> +#include "types.h" +#include "leadapi.h" + +void +cmd_dump(argbulk) + char *argbulk; +{ + char *argv[4]; + u_long mode, addr, len; + int rc; + volatile u16 *api; + unsigned n; + + if (parse_args(argbulk, 3, 3, argv, 0) < 0) + return; + if (parse_hexarg(argv[0], 4, &mode) < 0) { + printf("ERROR: mode must be a valid 16-bit hex value\n"); + return; + } + if (parse_hexarg(argv[1], 8, &addr) < 0) { + printf("ERROR: addr must be a valid 32-bit hex value\n"); + return; + } + if (parse_hexarg(argv[2], 4, &len) < 0) { + printf("ERROR: len must be a valid 16-bit hex value\n"); + return; + } + rc = boot_dsp_dump_agent(); + if (rc < 0) + return; /* error msg already printed */ + rc = dsp_read_op((u16)mode, (u32)addr, (u16)len); + if (rc < 0) { + printf("ERROR: DSP timeout on read operation\n"); + return; + } + api = (volatile u16 *) APIF_ADDR; + for (n = 0; n < len; n++) + printf("%04X\n", *api++); +}