Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: "unaligned addr or size" when trying to write a program in RAM #323

Closed
a-sv opened this issue Aug 8, 2015 · 1 comment
Closed

FIX: "unaligned addr or size" when trying to write a program in RAM #323

a-sv opened this issue Aug 8, 2015 · 1 comment

Comments

@a-sv
Copy link

a-sv commented Aug 8, 2015

--- src/stlink-common.c.orig    2015-08-08 14:44:09.630414490 +0300
+++ src/stlink-common.c 2015-08-08 15:35:47.158845463 +0300
@@ -971,16 +971,23 @@
     } else if ((addr + mf.len) > (sl->sram_base + sl->sram_size)) {
         fprintf(stderr, "addr too high\n");
         goto on_error;
-    } else if ((addr & 3) || (mf.len & 3)) {
+    } else if (addr & 3) {
         /* todo */
-        fprintf(stderr, "unaligned addr or size\n");
+        fprintf(stderr, "unaligned addr\n");
         goto on_error;
     }
+
+    int len = mf.len;
+
+    if((len % 4) > 0) {
+        len -= len % 4;
+    }
+
     /* do the copy by 1k blocks */
-    for (off = 0; off < mf.len; off += 1024) {
+    for (off = 0; off < len; off += 1024) {
         size_t size = 1024;
-        if ((off + size) > mf.len)
-            size = mf.len - off;
+        if ((off + size) > len)
+            size = len - off;

         memcpy(sl->q_buf, mf.base + off, size);

@@ -991,6 +998,11 @@
         stlink_write_mem32(sl, addr + off, size);
     }

+    if(mf.len > len) {
+        memcpy(sl->q_buf, mf.base + len, mf.len - len);
+        stlink_write_mem8(sl, addr + len, mf.len - len);
+    }
+
     /* check the file ha been written */
     if (check_file(sl, &mf, addr) == -1) {
         fprintf(stderr, "check_file() == -1\n");
@a-sv a-sv changed the title FIX: "unaligned addr or size" in attempt of write the program in the RAM FIX: "unaligned addr or size" when trying to write a program in RAM Aug 8, 2015
@texane
Copy link
Collaborator

texane commented Aug 8, 2015

Patch applied, thanks

2015-08-08 14:59 GMT+02:00 Антон Шолохов [email protected]:

--- src/stlink-common.c.orig 2015-08-08 14:44:09.630414490 +0300
+++ src/stlink-common.c 2015-08-08 15:35:47.158845463 +0300
@@ -971,16 +971,23 @@
} else if ((addr + mf.len) > (sl->sram_base + sl->sram_size)) {
fprintf(stderr, "addr too high\n");
goto on_error;

  • } else if ((addr & 3) || (mf.len & 3)) {
  • } else if (addr & 3) {
    /* todo */
  •    fprintf(stderr, "unaligned addr or size\n");
    
  •    fprintf(stderr, "unaligned addr\n");
     goto on_error;
    
    }
    +
  • int len = mf.len;
  • if((len % 4) > 0) {
  •    len -= len % 4;
    
  • }

/* do the copy by 1k blocks */

  • for (off = 0; off < mf.len; off += 1024) {
  • for (off = 0; off < len; off += 1024) {
    size_t size = 1024;
  •    if ((off + size) > mf.len)
    
  •        size = mf.len - off;
    
  •    if ((off + size) > len)
    
  •        size = len - off;
    
     memcpy(sl->q_buf, mf.base + off, size);
    

@@ -991,6 +998,11 @@
stlink_write_mem32(sl, addr + off, size);
}

  • if(mf.len > len) {
  •    memcpy(sl->q_buf, mf.base + len, mf.len - len);
    
  •    stlink_write_mem8(sl, addr + len, mf.len - len);
    
  • }

/* check the file ha been written */
if (check_file(sl, &mf, addr) == -1) {
fprintf(stderr, "check_file() == -1\n");


Reply to this email directly or view it on GitHub
#323.

@xor-gate xor-gate closed this as completed May 4, 2016
@Nightwalker-87 Nightwalker-87 added this to the v1.3.0 milestone Feb 26, 2020
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants