target: Add default implementation of bulk_write_memory
[openocd.git] / src / target / target.c
index e964f522488c6bc41f807088bb554660b6b301b8..04e375b8493dfefeb098284b9efd48eed18874a3 100644 (file)
@@ -80,6 +80,7 @@ extern struct target_type dragonite_target;
 extern struct target_type xscale_target;
 extern struct target_type cortexm3_target;
 extern struct target_type cortexa8_target;
+extern struct target_type cortexr4_target;
 extern struct target_type arm11_target;
 extern struct target_type mips_m4k_target;
 extern struct target_type avr_target;
@@ -103,6 +104,7 @@ static struct target_type *target_types[] = {
        &xscale_target,
        &cortexm3_target,
        &cortexa8_target,
+       &cortexr4_target,
        &arm11_target,
        &mips_m4k_target,
        &avr_target,
@@ -657,38 +659,18 @@ const char *target_type_name(struct target *target)
        return target->type->name;
 }
 
-static int target_write_memory_imp(struct target *target, uint32_t address,
-               uint32_t size, uint32_t count, const uint8_t *buffer)
-{
-       if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
-       }
-       return target->type->write_memory_imp(target, address, size, count, buffer);
-}
-
-static int target_read_memory_imp(struct target *target, uint32_t address,
-               uint32_t size, uint32_t count, uint8_t *buffer)
-{
-       if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
-       }
-       return target->type->read_memory_imp(target, address, size, count, buffer);
-}
-
-static int target_soft_reset_halt_imp(struct target *target)
+static int target_soft_reset_halt(struct target *target)
 {
        if (!target_was_examined(target)) {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
        }
-       if (!target->type->soft_reset_halt_imp) {
+       if (!target->type->soft_reset_halt) {
                LOG_ERROR("Target %s does not support soft_reset_halt",
                                target_name(target));
                return ERROR_FAIL;
        }
-       return target->type->soft_reset_halt_imp(target);
+       return target->type->soft_reset_halt(target);
 }
 
 /**
@@ -951,24 +933,40 @@ int target_run_flash_async_algorithm(struct target *target,
 int target_read_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 {
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
        return target->type->read_memory(target, address, size, count, buffer);
 }
 
-static int target_read_phys_memory(struct target *target,
+int target_read_phys_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 {
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
        return target->type->read_phys_memory(target, address, size, count, buffer);
 }
 
 int target_write_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
        return target->type->write_memory(target, address, size, count, buffer);
 }
 
-static int target_write_phys_memory(struct target *target,
+int target_write_phys_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
        return target->type->write_phys_memory(target, address, size, count, buffer);
 }
 
@@ -978,6 +976,12 @@ int target_bulk_write_memory(struct target *target,
        return target->type->bulk_write_memory(target, address, count, buffer);
 }
 
+static int target_bulk_write_memory_default(struct target *target,
+               uint32_t address, uint32_t count, const uint8_t *buffer)
+{
+       return target_write_memory(target, address, 4, count, buffer);
+}
+
 int target_add_breakpoint(struct target *target,
                struct breakpoint *breakpoint)
 {
@@ -1085,23 +1089,6 @@ static int target_init_one(struct command_context *cmd_ctx,
                return retval;
        }
 
-       /**
-        * @todo get rid of those *memory_imp() methods, now that all
-        * callers are using target_*_memory() accessors ... and make
-        * sure the "physical" paths handle the same issues.
-        */
-       /* a non-invasive way(in terms of patches) to add some code that
-        * runs before the type->write/read_memory implementation
-        */
-       type->write_memory_imp = target->type->write_memory;
-       type->write_memory = target_write_memory_imp;
-
-       type->read_memory_imp = target->type->read_memory;
-       type->read_memory = target_read_memory_imp;
-
-       type->soft_reset_halt_imp = target->type->soft_reset_halt;
-       type->soft_reset_halt = target_soft_reset_halt_imp;
-
        /* Sanity-check MMU support ... stub in what we must, to help
         * implement it in stages, but warn if we need to do so.
         */
@@ -1140,6 +1127,9 @@ static int target_init_one(struct command_context *cmd_ctx,
        if (target->type->write_buffer == NULL)
                target->type->write_buffer = target_write_buffer_default;
 
+       if (target->type->bulk_write_memory == NULL)
+               target->type->bulk_write_memory = target_bulk_write_memory_default;
+
        return ERROR_OK;
 }
 
@@ -2498,7 +2488,7 @@ COMMAND_HANDLER(handle_soft_reset_halt_command)
 
        LOG_USER("requesting target halt and executing a soft reset");
 
-       target->type->soft_reset_halt(target);
+       target_soft_reset_halt(target);
 
        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)