target: or1k: remove wrong endian swap from or1k generic code
[openocd.git] / src / target / openrisc / or1k_du_adv.c
index c3aceff1443facd8dd992b3d19051396d299897f..f497a869d4b16c510462dd65cd3fb06294aad26b 100644 (file)
@@ -846,7 +846,7 @@ static int or1k_adv_jtag_read_memory(struct or1k_jtag *jtag_info,
 
        int block_count_left = count;
        uint32_t block_count_address = addr;
-       uint8_t *block_count_buffer = (uint8_t *)buffer;
+       uint8_t *block_count_buffer = buffer;
 
        while (block_count_left) {
 
@@ -863,6 +863,23 @@ static int or1k_adv_jtag_read_memory(struct or1k_jtag *jtag_info,
                block_count_buffer += size * MAX_BURST_SIZE;
        }
 
+       /* The adv_debug_if always return words and half words in
+        * little-endian order no matter what the target endian is.
+        * So if the target endian is big, change the order.
+        */
+
+       struct target *target = jtag_info->target;
+       if ((target->endianness == TARGET_BIG_ENDIAN) && (size != 1)) {
+               switch (size) {
+               case 4:
+                       buf_bswap32(buffer, buffer, size * count);
+                       break;
+               case 2:
+                       buf_bswap16(buffer, buffer, size * count);
+                       break;
+               }
+       }
+
        return ERROR_OK;
 }
 
@@ -882,6 +899,31 @@ static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info,
        if (retval != ERROR_OK)
                return retval;
 
+       /* The adv_debug_if wants words and half words in little-endian
+        * order no matter what the target endian is. So if the target
+        * endian is big, change the order.
+        */
+
+       void *t = NULL;
+       struct target *target = jtag_info->target;
+       if ((target->endianness == TARGET_BIG_ENDIAN) && (size != 1)) {
+               t = malloc(count * size * sizeof(uint8_t));
+               if (t == NULL) {
+                       LOG_ERROR("Out of memory");
+                       return ERROR_FAIL;
+               }
+
+               switch (size) {
+               case 4:
+                       buf_bswap32(t, buffer, size * count);
+                       break;
+               case 2:
+                       buf_bswap16(t, buffer, size * count);
+                       break;
+               }
+               buffer = t;
+       }
+
        int block_count_left = count;
        uint32_t block_count_address = addr;
        uint8_t *block_count_buffer = (uint8_t *)buffer;
@@ -894,14 +936,20 @@ static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info,
                retval = adbg_wb_burst_write(jtag_info, block_count_buffer,
                                             size, blocks_this_round,
                                             block_count_address);
-               if (retval != ERROR_OK)
+               if (retval != ERROR_OK) {
+                       if (t != NULL)
+                               free(t);
                        return retval;
+               }
 
                block_count_left -= blocks_this_round;
                block_count_address += size * MAX_BURST_SIZE;
                block_count_buffer += size * MAX_BURST_SIZE;
        }
 
+       if (t != NULL)
+               free(t);
+
        return ERROR_OK;
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)