X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=ded4d55d7e21001f93068271a4dc28a2cb4f87f8;hb=890973acc46bcf21031a28ac5ac97154989dc3c4;hp=13c0842ff9ce791a08c2b5b3c01f1889564118b0;hpb=45ec363c4a56ade3d0c1f62c054e4310c76ce0f5;p=openocd.git diff --git a/src/target/target.c b/src/target/target.c index 13c0842ff9..ded4d55d7e 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1822,21 +1822,23 @@ static int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, cha static int handle_wait_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - int ms = 5000; + if (argc > 1) + return ERROR_COMMAND_SYNTAX_ERROR; - if (argc > 0) + unsigned ms = 5000; + if (1 == argc) { - char *end; - - ms = strtoul(args[0], &end, 0) * 1000; - if (*end) + int retval = parse_uint(args[0], &ms); + if (ERROR_OK != retval) { command_print(cmd_ctx, "usage: %s [seconds]", cmd); - return ERROR_OK; + return ERROR_COMMAND_SYNTAX_ERROR; } + // convert seconds (given) to milliseconds (needed) + ms *= 1000; } - target_t *target = get_current_target(cmd_ctx); + target_t *target = get_current_target(cmd_ctx); return target_wait_state(target, TARGET_HALTED, ms); } @@ -1887,23 +1889,20 @@ int target_wait_state(target_t *target, enum target_state state, int ms) static int handle_halt_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - int retval; - target_t *target = get_current_target(cmd_ctx); - LOG_DEBUG("-"); - if ((retval = target_halt(target)) != ERROR_OK) - { + target_t *target = get_current_target(cmd_ctx); + int retval = target_halt(target); + if (ERROR_OK != retval) return retval; - } if (argc == 1) { - int wait; - char *end; - - wait = strtoul(args[0], &end, 0); - if (!*end && !wait) + unsigned wait; + retval = parse_uint(args[0], &wait); + if (ERROR_OK != retval) + return ERROR_COMMAND_SYNTAX_ERROR; + if (!wait) return ERROR_OK; } @@ -1955,7 +1954,11 @@ static int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, c * handle breakpoints, not debugging */ u32 addr = 0; if (argc == 1) - addr = strtoul(args[0], NULL, 0); + { + int retval = parse_u32(args[0], &addr); + if (ERROR_OK != retval) + return retval; + } return target_resume(target, 0, addr, 1, 0); } @@ -1972,7 +1975,11 @@ static int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, cha * handle breakpoints, debugging */ u32 addr = 0; if (argc == 1) - addr = strtoul(args[0], NULL, 0); + { + int retval = parse_u32(args[0], &addr); + if (ERROR_OK != retval) + return retval; + } target_t *target = get_current_target(cmd_ctx); return target->type->step(target, 0, addr, 1); @@ -2039,16 +2046,23 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char default: return ERROR_COMMAND_SYNTAX_ERROR; } - u32 address = strtoul(args[0], NULL, 0); + u32 address; + int retval = parse_u32(args[0], &address); + if (ERROR_OK != retval) + return retval; unsigned count = 1; if (argc == 2) - count = strtoul(args[1], NULL, 0); + { + retval = parse_uint(args[1], &count); + if (ERROR_OK != retval) + return retval; + } u8 *buffer = calloc(count, size); target_t *target = get_current_target(cmd_ctx); - int retval = target_read_memory(target, + retval = target_read_memory(target, address, size, count, buffer); if (ERROR_OK == retval) handle_md_output(cmd_ctx, target, address, size, count, buffer); @@ -2060,22 +2074,30 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - u32 address = 0; - u32 value = 0; - int count = 1; - int i; - int wordsize; - target_t *target = get_current_target(cmd_ctx); - u8 value_buf[4]; - if ((argc < 2) || (argc > 3)) return ERROR_COMMAND_SYNTAX_ERROR; - address = strtoul(args[0], NULL, 0); - value = strtoul(args[1], NULL, 0); + u32 address; + int retval = parse_u32(args[0], &address); + if (ERROR_OK != retval) + return retval; + + u32 value; + retval = parse_u32(args[1], &value); + if (ERROR_OK != retval) + return retval; + + unsigned count = 1; if (argc == 3) - count = strtoul(args[2], NULL, 0); + { + retval = parse_uint(args[2], &count); + if (ERROR_OK != retval) + return retval; + } + target_t *target = get_current_target(cmd_ctx); + unsigned wordsize; + u8 value_buf[4]; switch (cmd[2]) { case 'w': @@ -2093,9 +2115,9 @@ static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char default: return ERROR_COMMAND_SYNTAX_ERROR; } - for (i=0; i= 2) { + u32 addr; + 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 = strtoul(args[1], NULL, 0); } else { @@ -2144,11 +2170,17 @@ static int handle_load_image_command(struct command_context_s *cmd_ctx, char *cm if (argc>=4) { - min_address=strtoul(args[3], NULL, 0); + retval = parse_u32(args[3], &min_address); + if (ERROR_OK != retval) + return ERROR_COMMAND_SYNTAX_ERROR; } if (argc>=5) { - max_address=strtoul(args[4], NULL, 0)+min_address; + 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; } if (min_address>max_address) @@ -2234,10 +2266,8 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm { fileio_t fileio; - u32 address; - u32 size; u8 buffer[560]; - int retval=ERROR_OK, retvaltemp; + int retvaltemp; duration_t duration; char *duration_text; @@ -2250,8 +2280,15 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm return ERROR_OK; } - address = strtoul(args[1], NULL, 0); - size = strtoul(args[2], NULL, 0); + u32 address; + int retval = parse_u32(args[1], &address); + if (ERROR_OK != retval) + return retval; + + u32 size; + retval = parse_u32(args[2], &size); + if (ERROR_OK != retval) + return retval; if (fileio_open(&fileio, args[0], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK) {