diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-10-22 22:33:12 -0700 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-05 18:19:18 -0800 |
commit | fc116380bf26ac00b8d0a37fee91e74118e12d8d (patch) | |
tree | 61faf6b82f1a97e736eafc166adfbb3fcd809373 /src | |
parent | ee4723c494fb9cd8deefdbf5387f0ba31ea57c65 (diff) | |
download | openocd_libswd-fc116380bf26ac00b8d0a37fee91e74118e12d8d.tar.gz openocd_libswd-fc116380bf26ac00b8d0a37fee91e74118e12d8d.tar.bz2 openocd_libswd-fc116380bf26ac00b8d0a37fee91e74118e12d8d.tar.xz openocd_libswd-fc116380bf26ac00b8d0a37fee91e74118e12d8d.zip |
Improve pic32mx.c command argument parsing.
Diffstat (limited to 'src')
-rw-r--r-- | src/flash/pic32mx.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c index 48ba38c3..d9966bf5 100644 --- a/src/flash/pic32mx.c +++ b/src/flash/pic32mx.c @@ -724,7 +724,6 @@ static int pic32mx_info(struct flash_bank_s *bank, char *buf, int buf_size) #if 0 int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - flash_bank_t *bank; target_t *target = NULL; pic32mx_flash_bank_t *pic32mx_info = NULL; @@ -734,12 +733,10 @@ int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, ch return ERROR_OK; } - bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0)); - if (!bank) - { - command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]); - return ERROR_OK; - } + flash_bank_t *bank; + int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank); + if (ERROR_OK != retval) + return retval; pic32mx_info = bank->driver_priv; @@ -773,7 +770,6 @@ int pic32mx_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, ch int pic32mx_handle_unlock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - flash_bank_t *bank; target_t *target = NULL; pic32mx_flash_bank_t *pic32mx_info = NULL; @@ -783,12 +779,10 @@ int pic32mx_handle_unlock_command(struct command_context_s *cmd_ctx, char *cmd, return ERROR_OK; } - bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0)); - if (!bank) - { - command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]); - return ERROR_OK; - } + flash_bank_t *bank; + int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank); + if (ERROR_OK != retval) + return retval; pic32mx_info = bank->driver_priv; @@ -867,7 +861,6 @@ static int pic32mx_chip_erase(struct flash_bank_s *bank) static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { #if 0 - flash_bank_t *bank; int i; if (argc != 0) @@ -876,12 +869,10 @@ static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx, return ERROR_OK; } - bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0)); - if (!bank) - { - command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[0]); - return ERROR_OK; - } + flash_bank_t *bank; + int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank); + if (ERROR_OK != retval) + return retval; if (pic32mx_chip_erase(bank) == ERROR_OK) { @@ -904,7 +895,6 @@ static int pic32mx_handle_chip_erase_command(struct command_context_s *cmd_ctx, static int pic32mx_handle_pgm_word_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - flash_bank_t *bank; uint32_t address, value; int status, res; @@ -914,15 +904,14 @@ static int pic32mx_handle_pgm_word_command(struct command_context_s *cmd_ctx, ch return ERROR_OK; } - address = strtoul(args[0], NULL, 0); - value = strtoul(args[1], NULL, 0); + COMMAND_PARSE_NUMBER(u32, args[0], address); + COMMAND_PARSE_NUMBER(u32, args[1], value); + + flash_bank_t *bank; + int retval = flash_command_get_bank_by_num(cmd_ctx, args[2], &bank); + if (ERROR_OK != retval) + return retval; - bank = get_flash_bank_by_num(strtoul(args[2], NULL, 0)); - if (!bank) - { - command_print(cmd_ctx, "flash bank '#%s' is out of bounds", args[2]); - return ERROR_OK; - } if (address < bank->base || address >= (bank->base + bank->size)) { command_print(cmd_ctx, "flash address '%s' is out of bounds", args[0]); |