target: use target_buffer_set_u32_array 83/1783/3
authorSpencer Oliver <spen@spen-soft.co.uk>
Thu, 24 Oct 2013 22:26:51 +0000 (23:26 +0100)
committerSpencer Oliver <spen@spen-soft.co.uk>
Thu, 7 Nov 2013 21:38:49 +0000 (21:38 +0000)
Attempt to use target_buffer_set_u32_array to convert to target endian
arrays rather reimplementing code.

This also removed cfi_fix_code_endian as its functionality is also
repeated.

Change-Id: I7c359dbe46ea791cd5f6fb18d8b0fb6895c599d3
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1783
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/flash/nand/arm_io.c
src/flash/nor/cfi.c
src/target/arm7_9_common.c
src/target/feroceon.c

index 67b15088542362797a4f87c9256f26b6f646e6b3..d54958adc9c6287961d84a0e6e5cfde93236b45b 100644 (file)
@@ -48,7 +48,6 @@ static int arm_code_to_working_area(struct target *target,
        unsigned additional, struct working_area **area)
 {
        uint8_t code_buf[code_size];
        unsigned additional, struct working_area **area)
 {
        uint8_t code_buf[code_size];
-       unsigned i;
        int retval;
        unsigned size = code_size + additional;
 
        int retval;
        unsigned size = code_size + additional;
 
@@ -67,8 +66,7 @@ static int arm_code_to_working_area(struct target *target,
        }
 
        /* buffer code in target endianness */
        }
 
        /* buffer code in target endianness */
-       for (i = 0; i < code_size / 4; i++)
-               target_buffer_set_u32(target, code_buf + i * 4, code[i]);
+       target_buffer_set_u32_array(target, code_buf, code_size / 4, code);
 
        /* copy code to work area */
        retval = target_write_memory(target, (*area)->address,
 
        /* copy code to work area */
        retval = target_write_memory(target, (*area)->address,
index 5724c184f6270e951b310e0e91e9ec8faec5a756..56d8e6e85d20e772508e1c899313680ae593ce18 100644 (file)
@@ -1103,19 +1103,6 @@ static int cfi_protect(struct flash_bank *bank, int set, int first, int last)
        }
 }
 
        }
 }
 
-/* Convert code image to target endian
- * FIXME create general block conversion fcts in target.c?) */
-static void cfi_fix_code_endian(struct target *target, uint8_t *dest,
-       const uint32_t *src, uint32_t count)
-{
-       uint32_t i;
-       for (i = 0; i < count; i++) {
-               target_buffer_set_u32(target, dest, *src);
-               dest += 4;
-               src++;
-       }
-}
-
 static uint32_t cfi_command_val(struct flash_bank *bank, uint8_t cmd)
 {
        struct target *target = bank->target;
 static uint32_t cfi_command_val(struct flash_bank *bank, uint8_t cmd)
 {
        struct target *target = bank->target;
@@ -1264,7 +1251,8 @@ static int cfi_intel_write_block(struct flash_bank *bank, uint8_t *buffer,
                                "Increase CFI_MAX_INTEL_CODESIZE and recompile.");
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
                                "Increase CFI_MAX_INTEL_CODESIZE and recompile.");
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
-       cfi_fix_code_endian(target, target_code, target_code_src, target_code_size / 4);
+
+       target_buffer_set_u32_array(target, target_code, target_code_size / 4, target_code_src);
 
        /* Get memory for block write handler */
        retval = target_alloc_working_area(target,
 
        /* Get memory for block write handler */
        retval = target_alloc_working_area(target,
@@ -1504,7 +1492,8 @@ static int cfi_spansion_write_block_mips(struct flash_bank *bank, uint8_t *buffe
                LOG_ERROR("Out of memory");
                return ERROR_FAIL;
        }
                LOG_ERROR("Out of memory");
                return ERROR_FAIL;
        }
-       cfi_fix_code_endian(target, target_code, target_code_src, target_code_size / 4);
+
+       target_buffer_set_u32_array(target, target_code, target_code_size / 4, target_code_src);
 
        /* allocate working area */
        retval = target_alloc_working_area(target, target_code_size,
 
        /* allocate working area */
        retval = target_alloc_working_area(target, target_code_size,
@@ -1883,7 +1872,8 @@ static int cfi_spansion_write_block(struct flash_bank *bank, uint8_t *buffer,
                LOG_ERROR("Out of memory");
                return ERROR_FAIL;
        }
                LOG_ERROR("Out of memory");
                return ERROR_FAIL;
        }
-       cfi_fix_code_endian(target, target_code, target_code_src, target_code_size / 4);
+
+       target_buffer_set_u32_array(target, target_code, target_code_size / 4, target_code_src);
 
        /* allocate working area */
        retval = target_alloc_working_area(target, target_code_size,
 
        /* allocate working area */
        retval = target_alloc_working_area(target, target_code_size,
index 6b1a1731b8ff990f7d3e38aac249607bcb5c0484..7f0e3adb38826aa8d2b43a1d8308db7cef99aa31 100644 (file)
@@ -2576,7 +2576,6 @@ int arm7_9_bulk_write_memory(struct target *target,
 {
        int retval;
        struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 {
        int retval;
        struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
-       int i;
 
        if (address % 4 != 0)
                return ERROR_TARGET_UNALIGNED_ACCESS;
 
        if (address % 4 != 0)
                return ERROR_TARGET_UNALIGNED_ACCESS;
@@ -2595,8 +2594,7 @@ int arm7_9_bulk_write_memory(struct target *target,
                }
 
                /* copy target instructions to target endianness */
                }
 
                /* copy target instructions to target endianness */
-               for (i = 0; i < 6; i++)
-                       target_buffer_set_u32(target, dcc_code_buf + i*4, dcc_code[i]);
+               target_buffer_set_u32_array(target, dcc_code_buf, ARRAY_SIZE(dcc_code), dcc_code);
 
                /* write DCC code to working area, using the non-optimized
                 * memory write to avoid ending up here again */
 
                /* write DCC code to working area, using the non-optimized
                 * memory write to avoid ending up here again */
index acaa1b3b4846cab63523783a1871cae2c75909c3..ee0bafd2466eefc77d9c6eef17537f257345e492 100644 (file)
@@ -510,8 +510,7 @@ static int feroceon_bulk_write_memory(struct target *target,
                }
 
                /* copy target instructions to target endianness */
                }
 
                /* copy target instructions to target endianness */
-               for (i = 0; i < dcc_size/4; i++)
-                       target_buffer_set_u32(target, dcc_code_buf + i*4, dcc_code[i]);
+               target_buffer_set_u32_array(target, dcc_code_buf, ARRAY_SIZE(dcc_code), dcc_code);
 
                /* write DCC code to working area, using the non-optimized
                 * memory write to avoid ending up here again */
 
                /* write DCC code to working area, using the non-optimized
                 * memory write to avoid ending up here again */

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)