Transform 'u16' to 'uint16_t'
[openocd.git] / src / target / target.c
index e269a5365d3dc707a5d1d496bb7c241c9c442d78..4ee91570fa9279a7158b9c66f98adfb5e931b305 100644 (file)
@@ -269,10 +269,10 @@ static int new_target_number(void)
        return x+1;
 }
 
-static int target_continous_poll = 1;
+static int target_continuous_poll = 1;
 
 /* read a u32 from a buffer in target memory endianness */
-u32 target_buffer_get_u32(target_t *target, const u8 *buffer)
+u32 target_buffer_get_u32(target_t *target, const uint8_t *buffer)
 {
        if (target->endianness == TARGET_LITTLE_ENDIAN)
                return le_to_h_u32(buffer);
@@ -280,8 +280,8 @@ u32 target_buffer_get_u32(target_t *target, const u8 *buffer)
                return be_to_h_u32(buffer);
 }
 
-/* read a u16 from a buffer in target memory endianness */
-u16 target_buffer_get_u16(target_t *target, const u8 *buffer)
+/* read a uint16_t from a buffer in target memory endianness */
+uint16_t target_buffer_get_u16(target_t *target, const uint8_t *buffer)
 {
        if (target->endianness == TARGET_LITTLE_ENDIAN)
                return le_to_h_u16(buffer);
@@ -289,14 +289,14 @@ u16 target_buffer_get_u16(target_t *target, const u8 *buffer)
                return be_to_h_u16(buffer);
 }
 
-/* read a u8 from a buffer in target memory endianness */
-u8 target_buffer_get_u8(target_t *target, const u8 *buffer)
+/* read a uint8_t from a buffer in target memory endianness */
+uint8_t target_buffer_get_u8(target_t *target, const uint8_t *buffer)
 {
        return *buffer & 0x0ff;
 }
 
 /* write a u32 to a buffer in target memory endianness */
-void target_buffer_set_u32(target_t *target, u8 *buffer, u32 value)
+void target_buffer_set_u32(target_t *target, uint8_t *buffer, u32 value)
 {
        if (target->endianness == TARGET_LITTLE_ENDIAN)
                h_u32_to_le(buffer, value);
@@ -304,8 +304,8 @@ void target_buffer_set_u32(target_t *target, u8 *buffer, u32 value)
                h_u32_to_be(buffer, value);
 }
 
-/* write a u16 to a buffer in target memory endianness */
-void target_buffer_set_u16(target_t *target, u8 *buffer, u16 value)
+/* write a uint16_t to a buffer in target memory endianness */
+void target_buffer_set_u16(target_t *target, uint8_t *buffer, uint16_t value)
 {
        if (target->endianness == TARGET_LITTLE_ENDIAN)
                h_u16_to_le(buffer, value);
@@ -313,8 +313,8 @@ void target_buffer_set_u16(target_t *target, u8 *buffer, u16 value)
                h_u16_to_be(buffer, value);
 }
 
-/* write a u8 to a buffer in target memory endianness */
-void target_buffer_set_u8(target_t *target, u8 *buffer, u8 value)
+/* write a uint8_t to a buffer in target memory endianness */
+void target_buffer_set_u8(target_t *target, uint8_t *buffer, uint8_t value)
 {
        *buffer = value;
 }
@@ -436,13 +436,13 @@ int target_process_reset(struct command_context_s *cmd_ctx, enum target_reset_mo
         * more predictable, i.e. dr/irscan & pathmove in events will
         * not have JTAG operations injected into the middle of a sequence.
         */
-       int save_poll = target_continous_poll;
-       target_continous_poll = 0;
+       int save_poll = target_continuous_poll;
+       target_continuous_poll = 0;
 
        sprintf( buf, "ocd_process_reset %s", n->name );
        retval = Jim_Eval( interp, buf );
 
-       target_continous_poll = save_poll;
+       target_continuous_poll = save_poll;
 
        if(retval != JIM_OK) {
                Jim_PrintErrorMessage(interp);
@@ -478,6 +478,18 @@ int target_examine_one(struct target_s *target)
        return target->type->examine(target);
 }
 
+static int jtag_enable_callback(enum jtag_event event, void *priv)
+{
+       target_t *target = priv;
+
+       if (event != JTAG_TAP_EVENT_ENABLE || !target->tap->enabled)
+               return ERROR_OK;
+
+       jtag_unregister_event_callback(jtag_enable_callback, target);
+       return target_examine_one(target);
+}
+
+
 /* Targets that correctly implement init+examine, i.e.
  * no communication with target during init:
  *
@@ -490,8 +502,12 @@ int target_examine(void)
 
        for (target = all_targets; target; target = target->next)
        {
-               if (!target->tap->enabled)
+               /* defer examination, but don't skip it */
+               if (!target->tap->enabled) {
+                       jtag_register_event_callback(jtag_enable_callback,
+                                       target);
                        continue;
+               }
                if ((retval = target_examine_one(target)) != ERROR_OK)
                        return retval;
        }
@@ -502,7 +518,7 @@ const char *target_get_name(struct target_s *target)
        return target->type->name;
 }
 
-static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
+static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, uint8_t *buffer)
 {
        if (!target_was_examined(target))
        {
@@ -512,7 +528,7 @@ static int target_write_memory_imp(struct target_s *target, u32 address, u32 siz
        return target->type->write_memory_imp(target, address, size, count, buffer);
 }
 
-static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
+static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, uint8_t *buffer)
 {
        if (!target_was_examined(target))
        {
@@ -543,18 +559,18 @@ static int target_run_algorithm_imp(struct target_s *target, int num_mem_params,
 }
 
 int target_read_memory(struct target_s *target,
-               u32 address, u32 size, u32 count, u8 *buffer)
+               u32 address, u32 size, u32 count, uint8_t *buffer)
 {
        return target->type->read_memory(target, address, size, count, buffer);
 }
 
 int target_write_memory(struct target_s *target,
-               u32 address, u32 size, u32 count, u8 *buffer)
+               u32 address, u32 size, u32 count, uint8_t *buffer)
 {
        return target->type->write_memory(target, address, size, count, buffer);
 }
 int target_bulk_write_memory(struct target_s *target,
-               u32 address, u32 count, u8 *buffer)
+               u32 address, u32 count, uint8_t *buffer)
 {
        return target->type->bulk_write_memory(target, address, count, buffer);
 }
@@ -1080,7 +1096,7 @@ int target_arch_state(struct target_s *target)
  * mode respectively, otherwise data is handled as quickly as
  * possible
  */
-int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer)
+int target_write_buffer(struct target_s *target, u32 address, u32 size, uint8_t *buffer)
 {
        int retval;
        LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address);
@@ -1159,7 +1175,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
  * mode respectively, otherwise data is handled as quickly as
  * possible
  */
-int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer)
+int target_read_buffer(struct target_s *target, u32 address, u32 size, uint8_t *buffer)
 {
        int retval;
        LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address);
@@ -1227,7 +1243,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
 
 int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* crc)
 {
-       u8 *buffer;
+       uint8_t *buffer;
        int retval;
        u32 i;
        u32 checksum = 0;
@@ -1289,7 +1305,7 @@ int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u3
 
 int target_read_u32(struct target_s *target, u32 address, u32 *value)
 {
-       u8 value_buf[4];
+       uint8_t value_buf[4];
        if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
@@ -1312,9 +1328,9 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value)
        return retval;
 }
 
-int target_read_u16(struct target_s *target, u32 address, u16 *value)
+int target_read_u16(struct target_s *target, u32 address, uint16_t *value)
 {
-       u8 value_buf[2];
+       uint8_t value_buf[2];
        if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
@@ -1337,7 +1353,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value)
        return retval;
 }
 
-int target_read_u8(struct target_s *target, u32 address, u8 *value)
+int target_read_u8(struct target_s *target, u32 address, uint8_t *value)
 {
        int retval = target_read_memory(target, address, 1, 1, value);
        if (!target_was_examined(target))
@@ -1362,7 +1378,7 @@ int target_read_u8(struct target_s *target, u32 address, u8 *value)
 int target_write_u32(struct target_s *target, u32 address, u32 value)
 {
        int retval;
-       u8 value_buf[4];
+       uint8_t value_buf[4];
        if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
@@ -1380,10 +1396,10 @@ int target_write_u32(struct target_s *target, u32 address, u32 value)
        return retval;
 }
 
-int target_write_u16(struct target_s *target, u32 address, u16 value)
+int target_write_u16(struct target_s *target, u32 address, uint16_t value)
 {
        int retval;
-       u8 value_buf[2];
+       uint8_t value_buf[2];
        if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
@@ -1401,7 +1417,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
        return retval;
 }
 
-int target_write_u8(struct target_s *target, u32 address, u8 value)
+int target_write_u8(struct target_s *target, u32 address, uint8_t value)
 {
        int retval;
        if (!target_was_examined(target))
@@ -1650,20 +1666,23 @@ int handle_target(void *priv)
                recursive = 0;
        }
 
-       target_t *target = all_targets;
-
-       while (target)
+       /* Poll targets for state changes unless that's globally disabled.
+        * Skip targets that are currently disabled.
+        */
+       for (target_t *target = all_targets;
+                       target_continuous_poll && target;
+                       target = target->next)
        {
+               if (!target->tap->enabled)
+                       continue;
 
                /* only poll target if we've got power and srst isn't asserted */
-               if (target_continous_poll&&!powerDropout&&!srstAsserted)
+               if (!powerDropout && !srstAsserted)
                {
                        /* polling may fail silently until the target has been examined */
                        if((retval = target_poll(target)) != ERROR_OK)
                                return retval;
                }
-
-               target = target->next;
        }
 
        return retval;
@@ -1763,7 +1782,7 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char
        /* set register value */
        if (argc == 2)
        {
-               u8 *buf = malloc(CEIL(reg->size, 8));
+               uint8_t *buf = malloc(CEIL(reg->size, 8));
                str_to_buf(args[1], strlen(args[1]), buf, reg->size, 0);
 
                reg_arch_type_t *arch_type = register_get_arch_type(reg->arch_type);
@@ -1791,7 +1810,12 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha
        if (argc == 0)
        {
                command_print(cmd_ctx, "background polling: %s",
-                               target_continous_poll ?  "on" : "off");
+                               target_continuous_poll ?  "on" : "off");
+               command_print(cmd_ctx, "TAP: %s (%s)",
+                               target->tap->dotted_name,
+                               target->tap->enabled ? "enabled" : "disabled");
+               if (!target->tap->enabled)
+                       return ERROR_OK;
                if ((retval = target_poll(target)) != ERROR_OK)
                        return retval;
                if ((retval = target_arch_state(target)) != ERROR_OK)
@@ -1802,11 +1826,11 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha
        {
                if (strcmp(args[0], "on") == 0)
                {
-                       target_continous_poll = 1;
+                       target_continuous_poll = 1;
                }
                else if (strcmp(args[0], "off") == 0)
                {
-                       target_continous_poll = 0;
+                       target_continuous_poll = 0;
                }
                else
                {
@@ -1987,7 +2011,7 @@ static int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, cha
 
 static void handle_md_output(struct command_context_s *cmd_ctx,
                struct target_s *target, u32 address, unsigned size,
-               unsigned count, const u8 *buffer)
+               unsigned count, const uint8_t *buffer)
 {
        const unsigned line_bytecnt = 32;
        unsigned line_modulo = line_bytecnt / size;
@@ -2015,7 +2039,7 @@ static void handle_md_output(struct command_context_s *cmd_ctx,
                }
 
                u32 value=0;
-               const u8 *value_ptr = buffer + i * size;
+               const uint8_t *value_ptr = buffer + i * size;
                switch (size) {
                case 4: value = target_buffer_get_u32(target, value_ptr); break;
                case 2: value = target_buffer_get_u16(target, value_ptr); break;
@@ -2059,7 +2083,7 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char
                        return retval;
        }
 
-       u8 *buffer = calloc(count, size);
+       uint8_t *buffer = calloc(count, size);
 
        target_t *target = get_current_target(cmd_ctx);
        retval = target_read_memory(target,
@@ -2097,7 +2121,7 @@ static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char
 
        target_t *target = get_current_target(cmd_ctx);
        unsigned wordsize;
-       u8 value_buf[4];
+       uint8_t value_buf[4];
        switch (cmd[2])
        {
                case 'w':
@@ -2128,66 +2152,70 @@ static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char
 
 }
 
-static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int parse_load_image_command_args(char **args, int argc,
+               image_t *image, u32 *min_address, u32 *max_address)
 {
-       u8 *buffer;
-       u32 buf_cnt;
-       u32 image_size;
-       u32 min_address=0;
-       u32 max_address=0xffffffff;
-       int i;
-       int retval, retvaltemp;
-
-       image_t image;
-
-       duration_t duration;
-       char *duration_text;
-
-       target_t *target = get_current_target(cmd_ctx);
-
-       if ((argc < 1)||(argc > 5))
-       {
+       if (argc < 1 || argc > 5)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
-       /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
+       /* a base address isn't always necessary,
+        * default to 0x0 (i.e. don't relocate) */
        if (argc >= 2)
        {
                u32 addr;
-               retval = parse_u32(args[1], &addr);
+               int retval = parse_u32(args[1], &addr);
                if (ERROR_OK != retval)
                        return ERROR_COMMAND_SYNTAX_ERROR;
-               image.base_address = addr;
-               image.base_address_set = 1;
+               image->base_address = addr;
+               image->base_address_set = 1;
        }
        else
-       {
-               image.base_address_set = 0;
-       }
-
+               image->base_address_set = 0;
 
-       image.start_address_set = 0;
+       image->start_address_set = 0;
 
-       if (argc>=4)
+       if (argc >= 4)
        {
-               retval = parse_u32(args[3], &min_address);
+               int retval = parse_u32(args[3], min_address);
                if (ERROR_OK != retval)
                        return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       if (argc>=5)
+       if (argc == 5)
        {
-               retval = parse_u32(args[4], &max_address);
+               int retval = parse_u32(args[4], max_address);
                if (ERROR_OK != retval)
                        return ERROR_COMMAND_SYNTAX_ERROR;
                // use size (given) to find max (required)
-               max_address += min_address;
+               *max_address += *min_address;
        }
 
-       if (min_address>max_address)
-       {
+       if (*min_address > *max_address)
                return ERROR_COMMAND_SYNTAX_ERROR;
-       }
 
+       return ERROR_OK;
+}
+
+static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+{
+       uint8_t *buffer;
+       u32 buf_cnt;
+       u32 image_size;
+       u32 min_address = 0;
+       u32 max_address = 0xffffffff;
+       int i;
+       int retvaltemp;
+
+       image_t image;
+
+       duration_t duration;
+       char *duration_text;
+       
+       int retval = parse_load_image_command_args(args, argc,
+                       &image, &min_address, &max_address);
+       if (ERROR_OK != retval)
+               return retval;
+
+       target_t *target = get_current_target(cmd_ctx);
        duration_start_measure(&duration);
 
        if (image_open(&image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
@@ -2266,7 +2294,7 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
 {
        fileio_t fileio;
 
-       u8 buffer[560];
+       uint8_t buffer[560];
        int retvaltemp;
 
        duration_t duration;
@@ -2336,7 +2364,7 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
 
 static int handle_verify_image_command_internal(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, int verify)
 {
-       u8 *buffer;
+       uint8_t *buffer;
        u32 buf_cnt;
        u32 image_size;
        int i;
@@ -2417,11 +2445,11 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
                        if( checksum != mem_checksum )
                        {
                                /* failed crc checksum, fall back to a binary compare */
-                               u8 *data;
+                               uint8_t *data;
 
                                command_print(cmd_ctx, "checksum mismatch - attempting binary compare");
 
-                               data = (u8*)malloc(buf_cnt);
+                               data = (uint8_t*)malloc(buf_cnt);
 
                                /* Can we use 32bit word accesses? */
                                int size = 1;
@@ -2732,7 +2760,7 @@ static void writeGmon(u32 *samples, u32 sampleNum, char *filename)
        writeLong(f, 0); /* padding */
        writeLong(f, 0); /* padding */
 
-       u8 zero = 0;  /* GMON_TAG_TIME_HIST */
+       uint8_t zero = 0;  /* GMON_TAG_TIME_HIST */
        writeData(f, &zero, 1);
 
        /* figure out bucket size */
@@ -2956,7 +2984,7 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_
        u32 count;
        u32 v;
        const char *varname;
-       u8 buffer[4096];
+       uint8_t buffer[4096];
        int  n, e, retval;
        u32 i;
 
@@ -3138,7 +3166,7 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_
        u32 count;
        u32 v;
        const char *varname;
-       u8 buffer[4096];
+       uint8_t buffer[4096];
        int  n, e, retval;
        u32 i;
 
@@ -3606,7 +3634,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
        Jim_GetOptInfo goi;
        jim_wide a,b,c;
        int x,y,z;
-       u8  target_buf[32];
+       uint8_t  target_buf[32];
        Jim_Nvp *n;
        target_t *target;
        struct command_context_s *cmd_ctx;
@@ -3695,7 +3723,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                 * argv[3] = optional count.
                 */
 
-               if( (goi.argc == 3) || (goi.argc == 4) ){
+               if( (goi.argc == 2) || (goi.argc == 3) ){
                        /* all is well */
                } else {
                mwx_error:
@@ -3712,7 +3740,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                if( e != JIM_OK ){
                        goto mwx_error;
                }
-               if( goi.argc ){
+               if (goi.argc == 3) {
                        e = Jim_GetOpt_Wide( &goi, &c );
                        if( e != JIM_OK ){
                                goto mwx_error;
@@ -4282,7 +4310,7 @@ static int jim_target( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
 struct FastLoad
 {
        u32 address;
-       u8 *data;
+       uint8_t *data;
        int length;
 
 };
@@ -4310,51 +4338,22 @@ static void free_fastload(void)
 
 static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       u8 *buffer;
+       uint8_t *buffer;
        u32 buf_cnt;
        u32 image_size;
        u32 min_address=0;
        u32 max_address=0xffffffff;
        int i;
-       int retval;
 
        image_t image;
 
        duration_t duration;
        char *duration_text;
 
-       if ((argc < 1)||(argc > 5))
-       {
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
-
-       /* 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;
-
-       if (argc>=4)
-       {
-               min_address=strtoul(args[3], NULL, 0);
-       }
-       if (argc>=5)
-       {
-               max_address=strtoul(args[4], NULL, 0)+min_address;
-       }
-
-       if (min_address>max_address)
-       {
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
+       int retval = parse_load_image_command_args(args, argc,
+                       &image, &min_address, &max_address);
+       if (ERROR_OK != retval)
+               return retval;
 
        duration_start_measure(&duration);
 

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)