jtag-mpsse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 83aa34743767503bf7fda6e9113814003ec3e500
parent a156bc18e08a648a7c073008af3fa8b4aeb0ef3b
Author: Brian Swetland <swetland@frotz.net>
Date:   Wed,  7 May 2014 18:53:35 -0700

debug: handle "generic" debug interface

Diffstat:
MMakefile | 8++++++--
Adebug.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ CFLAGS := -g -Wall -O2 LIBS := -lusb-1.0 -all: jtag i2c wri2c rdi2c +all: jtag i2c wri2c rdi2c debug jtag.c: jtag.h jtag-mpsse.c: jtag.h @@ -22,5 +22,9 @@ RDI2C_OBJS := rdi2c.o i2c_core.o jtag-mpsse.o rdi2c: $(RDI2C_OBJS) $(CC) -o rdi2c $(RDI2C_OBJS) $(LIBS) +DEBUG_OBJS := debug.o jtag-mpsse.o +debug: $(DEBUG_OBJS) + $(CC) -o debug $(DEBUG_OBJS) $(LIBS) + clean:: - rm -f jtag *.o i2c wri2c rdi2c + rm -f jtag *.o i2c wri2c rdi2c debug diff --git a/debug.c b/debug.c @@ -0,0 +1,76 @@ +/* Copyright 2014 Brian Swetland <swetland@frotz.net> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "jtag.h" +#include "zynq.h" + +static JTAG *jtag; + +void jconnect(void) { + if (!(jtag = jtag_open())) { + fprintf(stderr, "jconnect: cannot open usb jtag ifc\n"); + exit(-1); + } + if (jtag_enumerate(jtag) <= 0) { + fprintf(stderr, "jconnect: cannot enumerate jtag devices\n"); + exit(-1); + } + if (jtag_select(jtag, 0x13722093)) { + fprintf(stderr, "jconnect: cannot connect to ZYNQ\n"); + exit(-1); + } + + jtag_ir_wr(jtag, XIL_USER4); +} + +u32 jrd(u32 addr) { + u64 u; + jtag_dr_io(jtag, 4, addr & 7, &u); + jtag_dr_io(jtag, 36, 0, &u); + return (u32) u; +} + +void jwr(u32 addr, u32 val) { + u64 u = ((u64)val) | (((u64) (addr & 7)) << 32) | 0x800000000ULL; + jtag_dr_io(jtag, 36, u, &u); +} + +int main(int argc, char **argv) { + + if (argc == 3) { + u32 addr = strtoul(argv[1], 0, 0); + u32 val = strtoul(argv[2], 0, 0); + jconnect(); + jwr(addr, val); + return 0; + } else if (argc == 2) { + u32 addr = strtoul(argv[1], 0, 0); + u32 val; + jconnect(); + val = jrd(addr); + printf("%08x\n", val); + return 0; + } else { + fprintf(stderr, + "usage:\n" + " write: debug <addr> <val>\n" + " read: debug <addr>\n"); + return -1; + } +}