be quicker about determining erased byte pattern when flashing
[fw/stlink] / gdbserver / gdb-server.c
index 12c7c9f94e5b59d4ee8dd6825b25d93790c30e17..ef289f282a8789579cbeaa543330d36077284d1e 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <signal.h>
 #include <unistd.h>
 #include <sys/types.h>
 #ifdef __MINGW32__
@@ -174,11 +173,11 @@ int main(int argc, char** argv) {
     parse_options(argc, argv, &state);
     switch (state.stlink_version) {
         case 2:
-               sl = stlink_open_usb(state.logging_level, 0, NULL);
+            sl = stlink_open_usb(state.logging_level, state.reset, NULL);
             if(sl == NULL) return 1;
             break;
         case 1:
-            sl = stlink_v1_open(state.logging_level, 0);
+            sl = stlink_v1_open(state.logging_level, state.reset);
             if(sl == NULL) return 1;
             break;
     }
@@ -186,6 +185,7 @@ int main(int argc, char** argv) {
     connected_stlink = sl;
     signal(SIGINT, &cleanup);
     signal(SIGTERM, &cleanup);
+    signal(SIGSEGV, &cleanup);
 
     if (state.reset) {
         stlink_reset(sl);
@@ -752,7 +752,7 @@ static int flash_go(stlink_t *sl) {
             DLOG("flash_do: page %08x\n", page);
             unsigned send = length > FLASH_PAGE ? FLASH_PAGE : length;
             if(stlink_write_flash(sl, page, fb->data + (page - fb->addr),
-                        send) < 0)
+                        send, 0) < 0)
                 goto error;
             length -= send;
             
@@ -812,7 +812,7 @@ static struct cache_desc_t cache_desc;
 static unsigned ceil_log2(unsigned v)
 {
   unsigned res;
-  for (res = 0; (1 << res) < v; res++)
+  for (res = 0; (1U << res) < v; res++)
     ;
   return res;
 }
@@ -1353,6 +1353,12 @@ int serve(stlink_t *sl, st_state_t *st) {
 
                 unsigned adj_start = start % 4;
                 unsigned count_rnd = (count + adj_start + 4 - 1) / 4 * 4;
+                if (count_rnd > sl->flash_pgsz)
+                    count_rnd = sl->flash_pgsz;
+                if (count_rnd > 0x1800)
+                    count_rnd = 0x1800;
+                if (count_rnd < count)
+                    count = count_rnd;
 
                 stlink_read_mem32(sl, start - adj_start, count_rnd);