X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fflash%2Fflash.c;h=b9c9f5cf5b3b7fd1531f778ce2b5a4b9a1dca649;hb=6abf942baba746df2c7195abe01a9b05cec13b1e;hp=8444bb33df359e4bcc369bbaf30b660bc358bdc3;hpb=6c0553c8c504d4c6da20857abeec80648d841b72;p=openocd.git diff --git a/src/flash/flash.c b/src/flash/flash.c index 8444bb33df..b9c9f5cf5b 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -2,6 +2,9 @@ * Copyright (C) 2005 by Dominic Rath * * Dominic.Rath@gmx.de * * * + * Copyright (C) 2007,2008 Øyvind Harboe * + * oyvind.harboe@zylin.com * + * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * @@ -230,7 +233,7 @@ flash_bank_t *get_flash_bank_by_num_noprobe(int num) return NULL; } -int flash_get_bank_count() +int flash_get_bank_count(void) { flash_bank_t *p; int i = 0; @@ -261,6 +264,7 @@ flash_bank_t *get_flash_bank_by_num(int num) int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { + int retval; int i; int found = 0; target_t *target; @@ -273,7 +277,7 @@ int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char if ((target = get_target_by_num(strtoul(args[5], NULL, 0))) == NULL) { LOG_ERROR("target %lu not defined", strtoul(args[5], NULL, 0)); - return ERROR_OK; + return ERROR_FAIL; } for (i = 0; flash_drivers[i]; i++) @@ -286,7 +290,7 @@ int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char if (flash_drivers[i]->register_commands(cmd_ctx) != ERROR_OK) { LOG_ERROR("couldn't register '%s' commands", args[0]); - exit(-1); + return ERROR_FAIL; } c = malloc(sizeof(flash_bank_t)); @@ -301,11 +305,11 @@ int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char c->sectors = NULL; c->next = NULL; - if (flash_drivers[i]->flash_bank_command(cmd_ctx, cmd, args, argc, c) != ERROR_OK) + if ((retval=flash_drivers[i]->flash_bank_command(cmd_ctx, cmd, args, argc, c)) != ERROR_OK) { LOG_ERROR("'%s' driver rejected flash bank at 0x%8.8x", args[0], c->base); free(c); - return ERROR_OK; + return retval; } /* put flash bank in linked list */ @@ -329,7 +333,7 @@ int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char if (!found) { LOG_ERROR("flash driver '%s' not found", args[0]); - exit(-1); + return ERROR_FAIL; } return ERROR_OK; @@ -901,7 +905,7 @@ flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr) return NULL; } /* check whether address belongs to this flash bank */ - if ((addr >= c->base) && (addr < c->base + c->size) && target == c->target) + if ((addr >= c->base) && (addr <= c->base + (c->size - 1)) && target == c->target) return c; } LOG_ERROR("No flash at address 0x%08x\n", addr); @@ -1049,10 +1053,9 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase) { u32 size_read; - if (buffer_size - run_size <= image->sections[section].size - section_offset) - size_read = buffer_size - run_size; - else - size_read = image->sections[section].size - section_offset; + size_read = run_size - buffer_size; + if (size_read > image->sections[section].size - section_offset) + size_read = image->sections[section].size - section_offset; if ((retval = image_read_section(image, section, section_offset, size_read, buffer + buffer_size, &size_read)) != ERROR_OK || size_read == 0) @@ -1064,7 +1067,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase) /* see if we need to pad the section */ while (padding[section]--) - buffer[size_read++] = 0xff; + (buffer+buffer_size)[size_read++] = 0xff; buffer_size += size_read; section_offset += size_read; @@ -1117,6 +1120,7 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank) if (bank->target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; } @@ -1163,6 +1167,7 @@ int default_flash_blank_check(struct flash_bank_s *bank) if (bank->target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; }