added installation, added ST_LINK autodetection
authorDmitry Bravikov <bravikov@gmail.com>
Wed, 5 Oct 2011 10:15:44 +0000 (18:15 +0800)
committerKarl Palsson <github@tweak.net.au>
Thu, 13 Oct 2011 19:31:34 +0000 (03:31 +0800)
INSTALL [new file with mode: 0644]
build/Makefile
src/gdb-server.c

diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..49e761c
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,25 @@
+INSTALL
+=======
+
+1) Load the sg kernel module:
+
+       $ modprobe sg
+
+2) On Ubuntu you need to install the package libsgutils2-dev:
+
+       $ sudo apt-get install libsgutils2-dev
+
+3) Make:
+
+       $ make -C build
+       
+4) Install or reinstall
+
+       $ sudo make install -C build
+
+5) Run:
+
+       $ st-util <port> [/dev/sgX]
+
+6) Have fun!
+
index c50747fa87fbe79b59db7cbe3f9bca50d6eadb0a..8004d3fc21465a3d2921c3d55d2ce6bab3f28671 100644 (file)
@@ -20,3 +20,9 @@ $(PRG): $(OBJS)
 
 clean:
        @rm -vf *.d *.o $(PRG)
+       
+install:
+       @cp -vf $(PRG) /usr/bin/$(PRG)
+       
+uninstall:
+       @rm -vf /usr/bin/$(PRG)
index 04fd2bcb45dbd347915683a6a026a213291352c2..5e12da02a6d6dd996b3930d326285e8b5dd1ab10 100644 (file)
@@ -54,14 +54,60 @@ int serve(struct stlink* sl, int port);
 char* make_memory_map(const struct chip_params *params, uint32_t flash_size);
 
 int main(int argc, char** argv) {
-       if(argc != 3) {
-               fprintf(stderr, "Usage: %s <port> /dev/sgX\n", argv[0]);
-               return 1;
-       }
 
-       struct stlink *sl = stlink_quirk_open(argv[2], 0);
-       if (sl == NULL)
-               return 1;
+       struct stlink *sl = NULL;
+
+       switch(argc) {
+
+               default: {
+                       fprintf(stderr, "Usage: %s <port> [/dev/sgX] \n", argv[0]);
+                       return 1;
+               }
+
+               case 3 : {
+                       sl = stlink_quirk_open(argv[2], 0);
+                       if(sl == NULL) return 1;
+                       break;
+               }
+
+               case 2 : { // Search ST-LINK (from /dev/sg0 to /dev/sg99)
+                       const int DevNumMax = 99;
+                       int ExistDevCount = 0;
+
+                       for(int DevNum = 0; DevNum <= DevNumMax; DevNum++)
+                       {
+                               if(DevNum < 10) {
+                                       char DevName[] = "/dev/sgX";
+                                       const int X_index = 7;
+                                       DevName[X_index] = DevNum + '0';
+                                       if ( !access(DevName, F_OK) ) {
+                                               sl = stlink_quirk_open(DevName, 0);
+                                               ExistDevCount++;
+                                       }
+                               }
+                               else if(DevNum < 100) {
+                                       char DevName[] = "/dev/sgXY";
+                                       const int X_index = 7;
+                                       const int Y_index = 8;
+                                       DevName[X_index] = DevNum/10 + '0';
+                                       DevName[Y_index] = DevNum%10 + '0';
+                                       if ( !access(DevName, F_OK) ) {
+                                               sl = stlink_quirk_open(DevName, 0);
+                                               ExistDevCount++;
+                                       }
+                               }
+                               if(sl != NULL) break;
+                       }
+
+                       if(sl == NULL) {
+                               fprintf(stdout, "\nNumber of /dev/sgX devices found: %i \n",
+                                               ExistDevCount);
+                               fprintf(stderr, "ST-LINK not found\n");
+                               return 1;
+                       }
+                       break;
+               }
+       }
 
        if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE)
                stlink_enter_swd_mode(sl);