From 180d1ceb4b1e380911f63c601069c15a2bc95772 Mon Sep 17 00:00:00 2001 From: Derrick Gibelyou Date: Thu, 30 Jan 2020 13:29:50 -0700 Subject: [PATCH 1/6] Allow device node to be passed in as an argument --- src/user/verify_xilinx_xvc_driver.c | 12 ++++--- src/user/xvcServer.c | 56 +++++++++++++---------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/user/verify_xilinx_xvc_driver.c b/src/user/verify_xilinx_xvc_driver.c index 5749db8..3d23512 100644 --- a/src/user/verify_xilinx_xvc_driver.c +++ b/src/user/verify_xilinx_xvc_driver.c @@ -35,8 +35,6 @@ #include "xvc_ioctl.h" -static const char char_path[] = "/dev/xilinx_xvc_driver"; - #define BYTE_ALIGN(a) ((a + 7) / 8) #define MIN(a, b) (a < b ? a : b) #define MAX(a, b) (a > b ? a : b) @@ -157,11 +155,17 @@ int main(int argc, char **argv) unsigned test_lens[] = {32, 0}; unsigned test_index = 0; + if (argc < 2) + { + fprintf(stderr, "Error: supply the device name as an argument\n"); + return -1; + } + // try opening the driver - fd = open(char_path, O_RDWR | O_SYNC); + fd = open(argv[1], O_RDWR | O_SYNC); if (fd <= 0) { - printf("Could not open driver at %s\n", char_path); + printf("Could not open driver at %s\n", argv[1]); printf("Error: %s\n", strerror(errno)); return 0; } diff --git a/src/user/xvcServer.c b/src/user/xvcServer.c index 29c484e..1a6a440 100644 --- a/src/user/xvcServer.c +++ b/src/user/xvcServer.c @@ -35,7 +35,6 @@ typedef struct { #else /* USE_IOCTL */ #include #include "xvc_ioctl.h" -#define CHAR_DEV_PATH "/dev/xilinx_xvc_driver" #endif /* !USE_IOCTL */ static int verbose = 0; @@ -227,34 +226,7 @@ int main(int argc, char **argv) { int c; struct sockaddr_in address; char hostname[256]; - -#ifndef USE_IOCTL - int fd_uio; - volatile jtag_t* ptr = NULL; - - fd_uio = open(UIO_PATH, O_RDWR); - if (fd_uio < 1) { - fprintf(stderr, "Failed to open uio: %s\n", UIO_PATH); - return -1; - } - - ptr = (volatile jtag_t*) mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_uio, 0); - if (ptr == MAP_FAILED) { - fprintf(stderr, "MMAP Failed\n"); - return -1; - } - close(fd_uio); -#else /* USE_IOCTL */ - int fd_ioctl; - - fd_ioctl = open(CHAR_DEV_PATH, O_RDWR | O_SYNC); - if (fd_ioctl < 1) { - fprintf(stderr, "Failed to open xvc ioctl device driver: %s\n", CHAR_DEV_PATH); - return -1; - } - - display_driver_properties(fd_ioctl); -#endif /* !USE_IOCTL */ + char *device_name = NULL; opterr = 0; @@ -264,10 +236,30 @@ int main(int argc, char **argv) { verbose = 1; break; case '?': - fprintf(stderr, "usage: %s [-v]\n", *argv); + fprintf(stderr, "usage: %s [-v] device_node\n", *argv); return 1; } } + for (int index = optind; index < argc; index++) + device_name = argv[index]; + + int fd_dev = open(device_name, O_RDWR); + if (fd_dev < 1) { + fprintf(stderr, "Failed to open device: %s\n", device_name); + return -1; + } + +#ifndef USE_IOCTL + volatile jtag_t* ptr = NULL; + ptr = (volatile jtag_t*) mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_dev, 0); + if (ptr == MAP_FAILED) { + fprintf(stderr, "MMAP Failed\n"); + return -1; + } + close(fd_dev); +#else /* USE_IOCTL */ + display_driver_properties(fd_dev); +#endif /* !USE_IOCTL */ s = socket(AF_INET, SOCK_STREAM, 0); @@ -343,7 +335,7 @@ int main(int argc, char **argv) { #ifndef USE_IOCTL } else if (handle_data(fd, ptr)) { #else /* USE_IOCTL */ - } else if (handle_data(fd, fd_ioctl)) { + } else if (handle_data(fd, fd_dev)) { #endif /* !USE_IOCTL */ printf("connection closed - fd %d\n", fd); close(fd); @@ -362,7 +354,7 @@ int main(int argc, char **argv) { #ifndef USE_IOCTL munmap((void *) ptr, MAP_SIZE); #else /* USE_IOCTL */ - close(fd_ioctl); + close(fd_dev); #endif /* !USE_IOCTL */ return 0; From 9ed248d7aa554303307e3a265d478669e33848c7 Mon Sep 17 00:00:00 2001 From: Derrick Gibelyou Date: Thu, 30 Jan 2020 17:12:46 -0700 Subject: [PATCH 2/6] Add tcl commands to start hw_server --- src/user/xvcServer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/user/xvcServer.c b/src/user/xvcServer.c index 1a6a440..5405975 100644 --- a/src/user/xvcServer.c +++ b/src/user/xvcServer.c @@ -213,7 +213,6 @@ void display_driver_properties(int fd_ioctl) { return; } - printf("INFO: XVC driver character file: %s\n", CHAR_DEV_PATH); printf("INFO: debug_bridge base address: 0x%lX\n", props.debug_bridge_base_addr); printf("INFO: debug_bridge size: 0x%lX\n", props.debug_bridge_size); printf("INFO: debug_bridge device tree compatibility string: %s\n\n", props.debug_bridge_compat_string); @@ -234,6 +233,7 @@ int main(int argc, char **argv) { switch (c) { case 'v': verbose = 1; + printf("Enable verbose mode\n"); break; case '?': fprintf(stderr, "usage: %s [-v] device_node\n", *argv); @@ -291,7 +291,10 @@ int main(int argc, char **argv) { return 1; } - printf("INFO: To connect to this xvcServer instance, use url: TCP:%s:%u\n\n", hostname, XVC_PORT); + printf("INFO: To connect to this xvcServer instance, use url: %s:%u\n", hostname, XVC_PORT); + printf("INFO: e.g. tcl:\n"); + printf("connect_hw_server -url localhost:3121 -allow_non_jtag\n"); + printf("open_hw_target -xvc_url %s:%u\n\n", hostname, XVC_PORT); fd_set conn; int maxfd = 0; From 821096039862526c5003b5a86e145d95d998543c Mon Sep 17 00:00:00 2001 From: Derrick Gibelyou Date: Fri, 7 Feb 2020 16:39:11 -0700 Subject: [PATCH 3/6] Fix bug when shifting 19-31 bits --- src/user/xvcServer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/user/xvcServer.c b/src/user/xvcServer.c index 5405975..8810712 100644 --- a/src/user/xvcServer.c +++ b/src/user/xvcServer.c @@ -59,7 +59,7 @@ int handle_data(int fd, volatile jtag_t* ptr) { int handle_data(int fd, int fd_ioctl) { #endif /* !USE_IOCTL */ char xvcInfo[32]; - unsigned int bufferSize = 2048; + unsigned int bufferSize = 4096; sprintf(xvcInfo, "xvcServer_v1.0:%u\n", bufferSize); @@ -147,7 +147,7 @@ int handle_data(int fd, int fd_ioctl) { tdi = 0; tdo = 0; - if (bytesLeft < 4) { + if (bytesLeft <= 4) { shift_num_bits = bitsLeft; } shift_num_bytes = (shift_num_bits + 7) / 8; From 1937815aa7e260295ea3a8beb22e304cc9862d39 Mon Sep 17 00:00:00 2001 From: Derrick Gibelyou Date: Fri, 7 Feb 2020 16:43:01 -0700 Subject: [PATCH 4/6] Fix "listen()" call for new kernels --- src/user/xvcServer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/user/xvcServer.c b/src/user/xvcServer.c index 8810712..4391ec5 100644 --- a/src/user/xvcServer.c +++ b/src/user/xvcServer.c @@ -280,7 +280,7 @@ int main(int argc, char **argv) { return 1; } - if (listen(s, 0) < 0) { + if (listen(s, 1) < 0) { perror("listen"); return 1; } From 80709b9bb7e1bb26f1d3d26e9ae4b3f41a6af527 Mon Sep 17 00:00:00 2001 From: Derrick Gibelyou Date: Fri, 7 Feb 2020 17:29:52 -0700 Subject: [PATCH 5/6] Fix compiler warings --- src/user/xvcServer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/user/xvcServer.c b/src/user/xvcServer.c index 4391ec5..0bcc6ce 100644 --- a/src/user/xvcServer.c +++ b/src/user/xvcServer.c @@ -42,7 +42,7 @@ static int verbose = 0; #define XVC_PORT 2542 static int sread(int fd, void *target, int len) { - unsigned char *t = target; + unsigned char *t = (unsigned char*)target; while (len) { int r = read(fd, t, len); if (r <= 0) @@ -72,10 +72,11 @@ int handle_data(int fd, int fd_ioctl) { return 1; if (memcmp(cmd, "ge", 2) == 0) { + int len = strlen(xvcInfo); if (sread(fd, cmd, 6) != 1) return 1; - memcpy(result, xvcInfo, strlen(xvcInfo)); - if (write(fd, result, strlen(xvcInfo)) != strlen(xvcInfo)) { + memcpy(result, xvcInfo, len); + if (write(fd, result, len) != len) { perror("write"); return 1; } @@ -114,7 +115,7 @@ int handle_data(int fd, int fd_ioctl) { return 1; } - int nr_bytes = (len + 7) / 8; + unsigned int nr_bytes = (len + 7) / 8; if (nr_bytes * 2 > sizeof(buffer)) { fprintf(stderr, "buffer size exceeded\n"); return 1; @@ -192,7 +193,7 @@ int handle_data(int fd, int fd_ioctl) { return errsv; } #endif /* !USE_IOCTL */ - if (write(fd, result, nr_bytes) != nr_bytes) { + if (write(fd, result, nr_bytes) != (int)nr_bytes) { perror("write"); return 1; } From a4eb6805befb80ff2ea44958464f6d938dc59089 Mon Sep 17 00:00:00 2001 From: Derrick Gibelyou Date: Thu, 16 Sep 2021 17:49:43 -0600 Subject: [PATCH 6/6] Improve verbose messages --- src/user/xvcServer.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/user/xvcServer.c b/src/user/xvcServer.c index 0bcc6ce..c4ed27a 100644 --- a/src/user/xvcServer.c +++ b/src/user/xvcServer.c @@ -81,7 +81,7 @@ int handle_data(int fd, int fd_ioctl) { return 1; } if (verbose) { - printf("%u : Received command: 'getinfo'\n", (int)time(NULL)); + printf("%u : Received command: 'getinfo'", (int)time(NULL)); printf("\t Replied with %s\n", xvcInfo); } break; @@ -94,7 +94,7 @@ int handle_data(int fd, int fd_ioctl) { return 1; } if (verbose) { - printf("%u : Received command: 'settck'\n", (int)time(NULL)); + printf("%u : Received command: 'settck'", (int)time(NULL)); printf("\t Replied with '%.*s'\n\n", 4, cmd + 5); } break; @@ -102,7 +102,7 @@ int handle_data(int fd, int fd_ioctl) { if (sread(fd, cmd, 4) != 1) return 1; if (verbose) { - printf("%u : Received command: 'shift'\n", (int)time(NULL)); + printf("%u : Received command: 'shift'\t", (int)time(NULL)); } } else { fprintf(stderr, "invalid cmd '%s'\n", cmd); @@ -128,9 +128,8 @@ int handle_data(int fd, int fd_ioctl) { memset(result, 0, nr_bytes); if (verbose) { - printf("\tNumber of Bits : %d\n", len); + printf("\tNumber of Bits : %d\t", len); printf("\tNumber of Bytes : %d \n", nr_bytes); - printf("\n"); } #ifndef USE_IOCTL @@ -172,10 +171,11 @@ int handle_data(int fd, int fd_ioctl) { byteIndex += shift_num_bytes; if (verbose) { - printf("LEN : 0x%08x\n", shift_num_bits); - printf("TMS : 0x%08x\n", tms); - printf("TDI : 0x%08x\n", tdi); - printf("TDO : 0x%08x\n", tdo); + int mask = (1 << shift_num_bits) - 1; + printf("LEN : %8d\t", shift_num_bits); + printf("TMS : 0x%08x\t", tms); + printf("TDI : 0x%08x\t", tdi); + printf("TDO : 0x%08x\n", tdo & mask); } } #else /* USE_IOCTL */ @@ -197,6 +197,10 @@ int handle_data(int fd, int fd_ioctl) { perror("write"); return 1; } + + if (verbose) { + printf("\n"); + } } while (1); /* Note: Need to fix JTAG state updates, until then no exit is allowed */