From 0ffbc6033346d182f37b9a8ff9fa5af8d9f0ce6a Mon Sep 17 00:00:00 2001 From: zwelch Date: Sat, 13 Jun 2009 00:34:31 +0000 Subject: Factor load_image argument parsing to parse_load_image_command_args: - Make fast_load_image use the helper coverage the standard load_image. - Improve whitespace in the moved lines. git-svn-id: svn://svn.berlios.de/openocd/trunk@2239 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/target/target.c | 113 ++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 69 deletions(-) (limited to 'src/target') diff --git a/src/target/target.c b/src/target/target.c index e269a536..c2caa311 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2128,66 +2128,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) +{ + u8 *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) @@ -4316,45 +4320,16 @@ static int handle_fast_load_image_command(struct command_context_s *cmd_ctx, cha 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); -- cgit v1.2.3