source:
rtems-source-builder/source-builder/patches/texane-stlink-3494c11-2.diff
@
eaab26a
Last change on this file since eaab26a was c80560d, checked in by Chris Johns <chrisj@…>, on 11/05/12 at 23:09:40 | |
---|---|
|
|
File size: 17.2 KB |
-
configure.ac
diff --git a/configure.ac b/configure.ac index 1f00f3a..eb140e5 100644
a b AC_CHECK_HEADERS(sys/poll.h) 21 21 AC_REPLACE_FUNCS(mmap) 22 22 23 23 # Checks for libraries. 24 PKG_CHECK_MODULES(USB, libusb-1.0 >= 1.0.0,, 25 AC_MSG_ERROR([*** Required libusb-1.0 >= 1.0.0 not installed ***])) 26 AC_CHECK_LIB([usbpath],[usb_path2devnum],,,-lusb) 24 AC_CHECK_HEADER([libusb.h], [USB_LIBS="-lusb-1.0"]) 27 25 28 26 LIBS="$LIBS $USB_LIBS" 29 27 CFLAGS="$CFLAGS $USB_CFLAGS" -
gdbserver/gdb-server.c
diff --git a/gdbserver/gdb-server.c b/gdbserver/gdb-server.c index 9d27ae4..fd25e8b 100644
a b 1 1 /* -*- tab-width:8 -*- */ 2 #define DEBUG 0 2 3 3 /* 4 4 Copyright (C) 2011 Peter Zotov <whitequark@whitequark.org> 5 5 Use of this source code is governed by a BSD-style 6 6 license that can be found in the LICENSE file. 7 7 */ 8 8 9 #include <stdarg.h> 9 10 #include <getopt.h> 10 11 #include <stdio.h> 11 12 #include <string.h> … … 18 19 #include <sys/socket.h> 19 20 #include <netinet/in.h> 20 21 #include <arpa/inet.h> 21 #include <signal.h>22 22 #endif 23 #include <signal.h> 23 24 24 25 #include <stlink-common.h> 25 26 26 27 #include "gdb-remote.h" 27 28 28 #define DEFAULT_LOGGING_LEVEL 50 29 #define DEFAULT_LOGGING_LEVEL 0 30 #define LOGGING_LEVEL_GDBSERVER 2 29 31 #define DEFAULT_GDB_LISTEN_PORT 4242 30 32 31 33 #define STRINGIFY_inner(name) #name … … static const char hex[] = "0123456789abcdef"; 40 42 41 43 static const char* current_memory_map = NULL; 42 44 45 FILE *my_stderr; 46 FILE *my_stdout; 47 43 48 typedef struct _st_state_t { 44 // things from command line, bleh 45 int stlink_version; 46 // "/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTE531X6-if00-port0" is only 58 chars 47 char devicename[100]; 48 int logging_level; 49 // things from command line, bleh 50 int pipe; 51 int stlink_version; 52 // "/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTE531X6-if00-port0" is only 58 chars 53 char devicename[100]; 54 int logging_level; 49 55 int listen_port; 50 56 } st_state_t; 51 57 58 int logging_level = DEFAULT_LOGGING_LEVEL; 59 60 int remote_desc = -1; 61 int remote_piping = 0; 52 62 53 int serve(stlink_t *sl, int port); 63 int remote_open(int port); 64 int serve(stlink_t *sl); 54 65 char* make_memory_map(stlink_t *sl); 55 66 67 /* 68 * Own printf and redirect when piping. 69 */ 70 int 71 printf (const char *format,...) 72 { 73 int ret; 74 va_list args; 75 va_start (args, format); 76 ret = vfprintf (my_stdout, format, args); 77 fflush (my_stdout); 78 return ret; 79 } 56 80 57 81 int parse_options(int argc, char** argv, st_state_t *st) { 58 82 static struct option long_options[] = { 59 83 {"help", no_argument, NULL, 'h'}, 60 84 {"verbose", optional_argument, NULL, 'v'}, 85 {"pipe", no_argument, NULL, 'P'}, 61 86 {"device", required_argument, NULL, 'd'}, 62 87 {"stlink_version", required_argument, NULL, 's'}, 63 88 {"stlinkv1", no_argument, NULL, '1'}, … … int parse_options(int argc, char** argv, st_state_t *st) { 78 103 "(default port: " STRINGIFY(DEFAULT_GDB_LISTEN_PORT) ")\n" 79 104 ; 80 105 81 82 106 int option_index = 0; 83 107 int c; 84 108 int q; 85 while ((c = getopt_long(argc, argv, "hv::d:s:1 p:", long_options, &option_index)) != -1) {109 while ((c = getopt_long(argc, argv, "hv::d:s:1Pp:", long_options, &option_index)) != -1) { 86 110 switch (c) { 87 111 case 0: 88 112 printf("XXXXX Shouldn't really normally come here, only if there's no corresponding option\n"); … … int parse_options(int argc, char** argv, st_state_t *st) { 96 120 printf(help_str, argv[0]); 97 121 exit(EXIT_SUCCESS); 98 122 break; 123 case 'P': 124 st->pipe = 1; 125 break; 99 126 case 'v': 100 127 if (optarg) { 101 128 st->logging_level = atoi(optarg); 102 129 } else { 103 130 st->logging_level = DEFAULT_LOGGING_LEVEL; 104 131 } 132 logging_level = st->logging_level; 105 133 break; 106 134 case 'd': 107 135 if (strlen(optarg) > sizeof (st->devicename)) { … … int main(int argc, char** argv) { 149 177 st_state_t state; 150 178 memset(&state, 0, sizeof(state)); 151 179 // set defaults... 180 state.pipe = 0; 152 181 state.stlink_version = 2; 153 182 state.logging_level = DEFAULT_LOGGING_LEVEL; 154 183 state.listen_port = DEFAULT_GDB_LISTEN_PORT; 155 184 parse_options(argc, argv, &state); 185 186 my_stdout = stdout; 187 my_stderr = stderr; 188 189 if (state.pipe) { 190 my_stdout = my_stderr = stderr; 191 state.listen_port = 0; 192 remote_piping = 1; 193 } 194 156 195 switch (state.stlink_version) { 157 196 case 2: 158 197 sl = stlink_open_usb(state.logging_level); … … int main(int argc, char** argv) { 162 201 sl = stlink_v1_open(state.logging_level); 163 202 if(sl == NULL) return 1; 164 203 break; 165 } 204 } 205 206 #ifdef __MINGW32__ 207 if (!remote_piping) { 208 WSADATA wsadata; 209 if (WSAStartup(MAKEWORD(2,2),&wsadata) !=0 ) { 210 goto winsock_error; 211 } 212 } 213 #endif 214 215 remote_open(state.listen_port); 166 216 167 217 printf("Chip ID is %08x, Core ID is %08x.\n", sl->chip_id, sl->core_id); 168 218 … … int main(int argc, char** argv) { 170 220 171 221 current_memory_map = make_memory_map(sl); 172 222 173 #ifdef __MINGW32__ 174 WSADATA wsadata; 175 if (WSAStartup(MAKEWORD(2,2),&wsadata) !=0 ) { 176 goto winsock_error; 177 } 178 #endif 179 180 while(serve(sl, state.listen_port) == 0); 223 while(serve(sl) == 0); 181 224 182 225 #ifdef __MINGW32__ 226 if (!remote_piping) { 183 227 winsock_error: 184 WSACleanup(); 228 WSACleanup(); 229 } 185 230 #endif 186 231 187 232 /* Switch back to mass storage mode before closing. */ … … struct code_hw_watchpoint { 342 387 struct code_hw_watchpoint data_watches[DATA_WATCH_NUM]; 343 388 344 389 static void init_data_watchpoints(stlink_t *sl) { 345 #ifdef DEBUG 346 printf("init watchpoints\n"); 347 #endif 390 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 391 printf("init watchpoints\n"); 348 392 349 393 // set trcena in debug command to turn on dwt unit 350 394 stlink_write_debug32(sl, 0xE000EDFC, … … static int add_data_watchpoint(stlink_t *sl, enum watchfun wf, stm32_addr_t addr 377 421 for(i = 0; i < DATA_WATCH_NUM; i++) { 378 422 // is this an empty slot ? 379 423 if(data_watches[i].fun == WATCHDISABLED) { 380 #ifdef DEBUG 381 printf("insert watchpoint %d addr %x wf %u mask %u len %d\n", i, addr, wf, mask, len); 382 #endif 424 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 425 printf("insert watchpoint %d addr %x wf %u mask %u len %d\n", i, addr, wf, mask, len); 383 426 384 427 data_watches[i].fun = wf; 385 428 data_watches[i].addr = addr; … … static int add_data_watchpoint(stlink_t *sl, enum watchfun wf, stm32_addr_t addr 401 444 } 402 445 } 403 446 404 #ifdef DEBUG 405 printf("failure: add watchpoints addr %x wf %u len %u\n", addr, wf, len); 406 #endif 447 448 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 449 printf("failure: add watchpoints addr %x wf %u len %u\n", addr, wf, len); 450 407 451 return -1; 408 452 } 409 453 … … static int delete_data_watchpoint(stlink_t *sl, stm32_addr_t addr) 413 457 414 458 for(i = 0 ; i < DATA_WATCH_NUM; i++) { 415 459 if((data_watches[i].addr == addr) && (data_watches[i].fun != WATCHDISABLED)) { 416 #ifdef DEBUG 417 printf("delete watchpoint %d addr %x\n", i, addr); 418 #endif 460 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 461 printf("delete watchpoint %d addr %x\n", i, addr); 419 462 420 463 data_watches[i].fun = WATCHDISABLED; 421 464 stlink_write_debug32(sl, 0xe0001028 + i * 16, 0); … … static int delete_data_watchpoint(stlink_t *sl, stm32_addr_t addr) 424 467 } 425 468 } 426 469 427 #ifdef DEBUG 428 printf("failure: delete watchpoint addr %x\n", addr); 429 #endif 470 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 471 printf("failure: delete watchpoint addr %x\n", addr); 430 472 431 473 return -1; 432 474 } … … static int update_code_breakpoint(stlink_t *sl, stm32_addr_t addr, int set) { 485 527 else brk->type &= ~type; 486 528 487 529 if(brk->type == 0) { 488 #ifdef DEBUG 489 printf("clearing hw break %d\n", id); 490 #endif 530 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 531 printf("clearing hw break %d\n", id); 491 532 492 533 stlink_write_debug32(sl, 0xe0002008 + id * 4, 0); 493 534 } else { 494 535 uint32_t mask = (brk->addr) | 1 | (brk->type << 30); 495 536 496 #ifdef DEBUG 497 printf("setting hw break %d at %08x (%d)\n",498 id, brk->addr, brk->type);499 printf("reg %08x \n",500 mask);501 #endif537 if (logging_level >= LOGGING_LEVEL_GDBSERVER) { 538 printf("setting hw break %d at %08x (%d)\n", 539 id, brk->addr, brk->type); 540 printf("reg %08x \n", 541 mask); 542 } 502 543 503 544 stlink_write_debug32(sl, 0xe0002008 + id * 4, mask); 504 545 } … … static int flash_go(stlink_t *sl) { 589 630 stlink_reset(sl); 590 631 591 632 for(struct flash_block* fb = flash_root; fb; fb = fb->next) { 592 #ifdef DEBUG 593 printf("flash_do: block %08x -> %04x\n", fb->addr, fb->length); 594 #endif 633 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 634 printf("flash_do: block %08x -> %04x\n", fb->addr, fb->length); 595 635 596 636 unsigned length = fb->length; 597 637 for(stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += FLASH_PAGE) { … … static int flash_go(stlink_t *sl) { 599 639 //Update FLASH_PAGE 600 640 stlink_calculate_pagesize(sl, page); 601 641 602 #ifdef DEBUG 603 printf("flash_do: page %08x\n", page); 604 #endif 642 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 643 printf("flash_do: page %08x\n", page); 605 644 606 645 if(stlink_write_flash(sl, page, fb->data + (page - fb->addr), 607 646 length > FLASH_PAGE ? FLASH_PAGE : length) < 0) … … error: 625 664 return error; 626 665 } 627 666 628 int serve(stlink_t *sl, int port) { 629 int sock = socket(AF_INET, SOCK_STREAM, 0); 630 if(sock < 0) { 631 perror("socket"); 632 return 1; 633 } 634 635 unsigned int val = 1; 636 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); 667 int remote_open(int port) { 668 int sock = -1; 669 if (port == 0) { 670 remote_desc = STDOUT_FILENO; 671 remote_piping = 1; 672 signal(SIGINT, SIG_IGN); 673 #ifdef __MINGW32__ 674 if (_setmode (_fileno( stdout ), _O_BINARY) < 0) 675 fprintf(stderr, "cannot change stdout mode to binary"); 676 if (_setmode (_fileno( stdin ), _O_BINARY) < 0) 677 fprintf(stderr, "cannot change stdin mode to binary"); 678 #else 679 signal(SIGIO, SIG_IGN); 680 signal(SIGCHLD, SIG_IGN); 681 #endif 682 } 683 else { 684 sock = socket(AF_INET, SOCK_STREAM, 0); 685 if(sock < 0) { 686 perror("socket"); 687 return 1; 688 } 637 689 638 struct sockaddr_in serv_addr; 639 memset(&serv_addr,0,sizeof(struct sockaddr_in)); 640 serv_addr.sin_family = AF_INET; 641 serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); 642 serv_addr.sin_port = htons(port); 690 unsigned int val = 1; 691 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); 643 692 644 if(bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { 645 perror("bind"); 646 return 1; 647 } 693 struct sockaddr_in serv_addr; 694 memset(&serv_addr,0,sizeof(struct sockaddr_in)); 695 serv_addr.sin_family = AF_INET; 696 serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); 697 serv_addr.sin_port = htons(port); 648 698 649 if(listen(sock, 5) < 0) {650 perror("listen");651 652 699 if(bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { 700 perror("bind"); 701 return 1; 702 } 653 703 654 stlink_force_debug(sl); 655 stlink_reset(sl); 656 init_code_breakpoints(sl); 657 init_data_watchpoints(sl); 704 if(listen(sock, 5) < 0) { 705 perror("listen"); 706 return 1; 707 } 708 } 658 709 659 printf("Listening at *:%d...\n", port); 710 if (!remote_piping) { 711 printf("Listening at *:%d...\n", port); 660 712 661 int client= accept(sock, NULL, NULL);662 663 if(client< 0) {664 665 666 713 remote_desc = accept(sock, NULL, NULL); 714 //signal (SIGINT, SIG_DFL); 715 if(remote_desc < 0) { 716 perror("accept"); 717 return 1; 718 } 667 719 668 close(sock); 720 close(sock); 721 } 669 722 670 723 printf("GDB connected.\n"); 671 724 725 return 0; 726 } 727 728 int serve(stlink_t *sl) { 729 730 stlink_force_debug(sl); 731 stlink_reset(sl); 732 init_code_breakpoints(sl); 733 init_data_watchpoints(sl); 734 672 735 /* 673 736 * To allow resetting the chip from GDB it is required to 674 737 * emulate attaching and detaching to target. … … int serve(stlink_t *sl, int port) { 678 741 while(1) { 679 742 char* packet; 680 743 681 int status = gdb_recv_packet( client, &packet);744 int status = gdb_recv_packet(remote_desc, &packet); 682 745 if(status < 0) { 683 746 fprintf(stderr, "cannot recv: %d\n", status); 684 747 return 1; 685 748 } 686 749 687 #ifdef DEBUG 688 printf("recv: %s\n", packet); 689 #endif 750 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 751 printf("recv: %s\n", packet); 690 752 691 753 char* reply = NULL; 692 754 reg regp; … … int serve(stlink_t *sl, int port) { 709 771 char* queryName = calloc(queryNameLength + 1, 1); 710 772 strncpy(queryName, &packet[1], queryNameLength); 711 773 712 #ifdef DEBUG 713 printf("query: %s;%s\n", queryName, params); 714 #endif 774 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 775 printf("query: %s;%s\n", queryName, params); 715 776 716 777 if(!strcmp(queryName, "Supported")) { 717 778 if(sl->chip_id==STM32_CHIPID_F4) { … … int serve(stlink_t *sl, int port) { 734 795 unsigned addr = strtoul(__s_addr, NULL, 16), 735 796 length = strtoul(s_length, NULL, 16); 736 797 737 #ifdef DEBUG 738 printf("Xfer: type:%s;op:%s;annex:%s;addr:%d;length:%d\n", 739 type, op, annex, addr, length); 740 #endif 798 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 799 printf("Xfer: type:%s;op:%s;annex:%s;addr:%d;length:%d\n", 800 type, op, annex, addr, length); 741 801 742 802 const char* data = NULL; 743 803 … … int serve(stlink_t *sl, int port) { 771 831 772 832 773 833 if (!strncmp(params,"726573756d65",12)) {// resume 774 #ifdef DEBUG 775 printf("Rcmd: resume\n"); 776 #endif 834 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 835 printf("Rcmd: resume\n"); 777 836 stlink_run(sl); 778 837 779 838 reply = strdup("OK"); … … int serve(stlink_t *sl, int port) { 782 841 783 842 stlink_force_debug(sl); 784 843 785 #ifdef DEBUG 786 printf("Rcmd: halt\n");787 #endif 844 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 845 printf("Rcmd: halt\n"); 846 788 847 } else if (!strncmp(params,"6a7461675f7265736574",20)) { //jtag_reset 789 848 reply = strdup("OK"); 790 849 … … int serve(stlink_t *sl, int port) { 792 851 stlink_jtag_reset(sl, 0); 793 852 stlink_force_debug(sl); 794 853 795 #ifdef DEBUG 796 printf("Rcmd: jtag_reset\n");797 #endif 854 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 855 printf("Rcmd: jtag_reset\n"); 856 798 857 } else if (!strncmp(params,"7265736574",10)) { //reset 799 858 reply = strdup("OK"); 800 859 … … int serve(stlink_t *sl, int port) { 803 862 init_code_breakpoints(sl); 804 863 init_data_watchpoints(sl); 805 864 806 #ifdef DEBUG 807 printf("Rcmd: reset\n"); 808 #endif 809 } else { 810 #ifdef DEBUG 811 printf("Rcmd: %s\n", params); 812 #endif 865 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 866 printf("Rcmd: reset\n"); 813 867 868 } else { 869 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 870 printf("Rcmd: %s\n", params); 814 871 } 815 872 816 873 } … … int serve(stlink_t *sl, int port) { 839 896 unsigned addr = strtoul(__s_addr, NULL, 16), 840 897 length = strtoul(s_length, NULL, 16); 841 898 842 #ifdef DEBUG 843 printf("FlashErase: addr:%08x,len:%04x\n", 844 addr, length); 845 #endif 899 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 900 printf("FlashErase: addr:%08x,len:%04x\n", 901 addr, length); 846 902 847 903 if(flash_add_block(addr, length, sl) < 0) { 848 904 reply = strdup("E00"); … … int serve(stlink_t *sl, int port) { 877 933 if(dec_index % 2 != 0) 878 934 dec_index++; 879 935 880 #ifdef DEBUG 881 printf("binary packet %d -> %d\n", data_length, dec_index); 882 #endif 936 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 937 printf("binary packet %d -> %d\n", data_length, dec_index); 883 938 884 939 if(flash_populate(addr, decoded, dec_index) < 0) { 885 940 reply = strdup("E00"); … … int serve(stlink_t *sl, int port) { 908 963 stlink_run(sl); 909 964 910 965 while(1) { 911 int status = gdb_check_for_interrupt( client);966 int status = gdb_check_for_interrupt(remote_desc); 912 967 if(status < 0) { 913 968 fprintf(stderr, "cannot check for int: %d\n", status); 914 969 return 1; … … int serve(stlink_t *sl, int port) { 1190 1245 } 1191 1246 1192 1247 if(reply) { 1193 #ifdef DEBUG 1194 printf("send: %s\n", reply); 1195 #endif 1248 if (logging_level >= LOGGING_LEVEL_GDBSERVER) 1249 printf("send: %s\n", reply); 1196 1250 1197 int result = gdb_send_packet( client, reply);1251 int result = gdb_send_packet(remote_desc, reply); 1198 1252 if(result != 0) { 1199 1253 fprintf(stderr, "cannot send: %d\n", result); 1200 1254 return 1;
Note: See TracBrowser
for help on using the repository browser.