- added myself to copyright on files i remember adding large contributions for over...
[openocd.git] / src / flash / flash.c
index 16c2633b18edfdc32d24459aafe67de495c65bf7..5f9d78bc4a3565d9e7eb3b4497f1ae98e556bd4f 100644 (file)
@@ -2,6 +2,12 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                 *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
+ *   Copyright (C) 2008 by Spencer Oliver                                  *
+ *   spen@spen-soft.co.uk                                                  *
+ *                                                                         *
  *   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     *
@@ -141,12 +147,12 @@ int flash_register_commands(struct command_context_s *cmd_ctx)
 
 static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
+       flash_bank_t *p;
+       
        if (argc != 1) {
                Jim_WrongNumArgs(interp, 1, argv, "no arguments to flash_banks command");
                return JIM_ERR;
        }
-       flash_bank_t *p;
-       int i = 0;
 
        if (!flash_banks)
        {
@@ -158,7 +164,6 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        {
                Jim_Obj *elem=Jim_NewListObj(interp, NULL, 0);
                
-
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "name", -1));
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, p->driver->name, -1));
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "base", -1));
@@ -178,12 +183,11 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        return JIM_OK;
 }
 
-
 int flash_init_drivers(struct command_context_s *cmd_ctx)
 {
        if (flash_banks)
        {
-               register_jim(cmd_ctx, "openocd_flash_banks", jim_flash_banks, "return information about the flash banks");
+               register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
                
                register_command(cmd_ctx, flash_cmd, "info", handle_flash_info_command, COMMAND_EXEC,
                                                 "print info about flash bank <num>");
@@ -232,7 +236,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;
@@ -263,6 +267,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;
@@ -275,7 +280,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++)
@@ -288,7 +293,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));
@@ -303,11 +308,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 */
@@ -331,7 +336,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;
@@ -903,7 +908,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);
@@ -1051,10 +1056,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)
@@ -1066,7 +1070,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;
@@ -1119,6 +1123,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;
        }
        
@@ -1165,6 +1170,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;
        }
                

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)