Also ignore ZEROs at end of file when writing
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Sun, 18 Dec 2011 15:53:16 +0000 (16:53 +0100)
committerUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Sun, 18 Dec 2011 15:53:16 +0000 (16:53 +0100)
src/stlink-common.c

index fac7b685c225cdcab25739bdadfc44ee2254001d..937bf82963bf33ffb1cfa3d5e0de6230df899561 100644 (file)
@@ -1420,11 +1420,22 @@ int stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t* base, unsigned
 int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
     /* write the file in flash at addr */
     int err;
 int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
     /* write the file in flash at addr */
     int err;
+    unsigned int num_zero = 0, index;
     mapped_file_t mf = MAPPED_FILE_INITIALIZER;
     if (map_file(&mf, path) == -1) {
         WLOG("map_file() == -1\n");
         return -1;
     }
     mapped_file_t mf = MAPPED_FILE_INITIALIZER;
     if (map_file(&mf, path) == -1) {
         WLOG("map_file() == -1\n");
         return -1;
     }
+    for(index = 0; index < mf.len; index ++) {
+       if (mf.base[index] == 0)
+           num_zero ++;
+       else
+           num_zero = 0;
+    }
+    if(num_zero != 0) {
+       ILOG("Ignoring %d bytes of Zeros at end of file\n",num_zero);
+       mf.len -= num_zero;
+    }
     err = stlink_write_flash(sl, addr, mf.base, mf.len);
     unmap_file(&mf);
     return err;
     err = stlink_write_flash(sl, addr, mf.base, mf.len);
     unmap_file(&mf);
     return err;