- reworked presto.c to allow use of either FTD2XX or libftdi (libftdi not functional...
[openocd.git] / src / target / target.c
index b7f842e7b8f85e8641a00bc79a9e063774e64395..de71b140fd4b4da9d1f5522f2878a211edc30e6a 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "replacements.h"
 #include "target.h"
+#include "target_request.h"
 
 #include "log.h"
 #include "configuration.h"
@@ -31,6 +32,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <inttypes.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -81,6 +83,7 @@ extern target_type_t arm920t_target;
 extern target_type_t arm966e_target;
 extern target_type_t arm926ejs_target;
 extern target_type_t xscale_target;
+extern target_type_t cortexm3_target;
 
 target_type_t *target_types[] =
 {
@@ -91,6 +94,7 @@ target_type_t *target_types[] =
        &arm966e_target,
        &arm926ejs_target,
        &xscale_target,
+       &cortexm3_target,
        NULL,
 };
 
@@ -650,6 +654,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
        {
                if ((retval = target->type->write_memory(target, address, 1, size, buffer)) != ERROR_OK)
                        return retval;
+               return ERROR_OK;
        }
        
        /* handle unaligned head bytes */
@@ -708,6 +713,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
        {
                if ((retval = target->type->read_memory(target, address, 1, size, buffer)) != ERROR_OK)
                        return retval;
+               return ERROR_OK;
        }
        
        /* handle unaligned head bytes */
@@ -873,11 +879,14 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx,  NULL, "wp", handle_wp_command, COMMAND_EXEC, "set watchpoint <address> <length> <r/w/a> [value] [mask]");    
        register_command(cmd_ctx,  NULL, "rwp", handle_rwp_command, COMMAND_EXEC, "remove watchpoint <adress>");
        
-       register_command(cmd_ctx,  NULL, "load_image", handle_load_image_command, COMMAND_EXEC, "load_image <file> <address> ['bin'|'ihex']");
+       register_command(cmd_ctx,  NULL, "load_image", handle_load_image_command, COMMAND_EXEC, "load_image <file> <address> ['bin'|'ihex'|'elf'|'s19']");
        register_command(cmd_ctx,  NULL, "dump_image", handle_dump_image_command, COMMAND_EXEC, "dump_image <file> <address> <size>");
        register_command(cmd_ctx,  NULL, "load_binary", handle_load_image_command, COMMAND_EXEC, "[DEPRECATED] load_binary <file> <address>");
        register_command(cmd_ctx,  NULL, "dump_binary", handle_dump_image_command, COMMAND_EXEC, "[DEPRECATED] dump_binary <file> <address> <size>");
        
+       target_request_register_commands(cmd_ctx);
+       trace_register_commands(cmd_ctx);
+       
        return ERROR_OK;
 }
 
@@ -995,6 +1004,16 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a
                                (*last_target_p)->next = NULL;
                                (*last_target_p)->arch_info = NULL;
                                
+                               /* initialize trace information */
+                               (*last_target_p)->trace_info = malloc(sizeof(trace_t));
+                               (*last_target_p)->trace_info->num_trace_points = 0;
+                               (*last_target_p)->trace_info->trace_points_size = 0;
+                               (*last_target_p)->trace_info->trace_points = NULL;
+                               (*last_target_p)->trace_info->trace_history_size = 0;
+                               (*last_target_p)->trace_info->trace_history = NULL;
+                               (*last_target_p)->trace_info->trace_history_pos = 0;
+                               (*last_target_p)->trace_info->trace_history_overflowed = 0;
+                                                               
                                (*last_target_p)->type->target_command(cmd_ctx, cmd, args, argc, *last_target_p);
                                
                                found = 1;
@@ -1654,7 +1673,6 @@ int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args,
 
 int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       u32 address;
        u8 *buffer;
        u32 buf_cnt;
        u32 image_size;
@@ -1668,22 +1686,28 @@ int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char
        
        target_t *target = get_current_target(cmd_ctx);
 
-       if (argc < 2)
+       if (argc < 1)
        {
-               command_print(cmd_ctx, "usage: load_image <filename> <address> [type]");
+               command_print(cmd_ctx, "usage: load_image <filename> [address] [type]");
                return ERROR_OK;
        }
        
-       identify_image_type(&image.type, (argc == 3) ? args[2] : NULL);
-
-       image.base_address_set = 1;
-       image.base_address = strtoul(args[1], NULL, 0);
+       /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
+       if (argc >= 2)
+       {
+               image.base_address_set = 1;
+               image.base_address = strtoul(args[1], NULL, 0);
+       }
+       else
+       {
+               image.base_address_set = 0;
+       }
        
        image.start_address_set = 0;
 
        duration_start_measure(&duration);
        
-       if (image_open(&image, args[0], FILEIO_READ) != ERROR_OK)
+       if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
        {
                command_print(cmd_ctx, "load_image error: %s", image.error_str);
                return ERROR_OK;
@@ -1769,7 +1793,7 @@ int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cmd, char
        fileio_close(&fileio);
 
        duration_stop_measure(&duration, &duration_text);
-       command_print(cmd_ctx, "dumped %lli byte in %s", fileio.size, duration_text);
+       command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
        free(duration_text);
        
        return ERROR_OK;
@@ -1852,6 +1876,7 @@ int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args
 int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
+       int retval;
 
        if (argc == 0)
        {
@@ -1895,7 +1920,23 @@ int handle_wp_command(struct command_context_s *cmd_ctx, char *cmd, char **args,
                {
                        data_mask = strtoul(args[4], NULL, 0);
                }
-               watchpoint_add(target, strtoul(args[0], NULL, 0), strtoul(args[1], NULL, 0), type, data_value, data_mask);
+               
+               if ((retval = watchpoint_add(target, strtoul(args[0], NULL, 0),
+                               strtoul(args[1], NULL, 0), type, data_value, data_mask)) != ERROR_OK)
+               {
+                       switch (retval)
+                       {
+                               case ERROR_TARGET_NOT_HALTED:
+                                       command_print(cmd_ctx, "target must be halted to set watchpoints");
+                                       break;
+                               case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
+                                       command_print(cmd_ctx, "no more watchpoints available");
+                                       break;
+                               default:
+                                       command_print(cmd_ctx, "unknown error, watchpoint not set");
+                                       break;
+                       }       
+               }
        }
        else
        {

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)