- ST STM32x cortex support added
[fw/openocd] / src / target / target.c
index fd8ffd7b92f2a6f768af07fa37bf807b2fa5b217..07c450cd3137a86f880c4ca28cdf1393d5e81366 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <inttypes.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -81,6 +82,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 +93,7 @@ target_type_t *target_types[] =
        &arm966e_target,
        &arm926ejs_target,
        &xscale_target,
+       &cortexm3_target,
        NULL,
 };
 
@@ -650,6 +653,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 +712,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 */
@@ -1654,7 +1659,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 +1672,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 +1779,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;