- convert spaces to tabs in at91sam7.[ch]
[openocd.git] / src / flash / flash.c
index e5adcc861585cbee117e8d1f12c032b3fdf20029..5f09c72dd7b8f57497f1ac579d063a2c3873eb53 100644 (file)
@@ -2,9 +2,12 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
- *   Copyright (C) 2007,2008 Øyvind Harboe                                      *
+ *   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     *
@@ -64,8 +67,10 @@ flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr);
 extern flash_driver_t lpc2000_flash;
 extern flash_driver_t cfi_flash;
 extern flash_driver_t at91sam7_flash;
+extern flash_driver_t at91sam7_old_flash;
 extern flash_driver_t str7x_flash;
 extern flash_driver_t str9x_flash;
+extern flash_driver_t aduc702x_flash;
 extern flash_driver_t stellaris_flash;
 extern flash_driver_t str9xpec_flash;
 extern flash_driver_t stm32x_flash;
@@ -74,13 +79,14 @@ extern flash_driver_t ecosflash_flash;
 extern flash_driver_t lpc288x_flash;
 extern flash_driver_t ocl_flash;
 
-flash_driver_t *flash_drivers[] =
-{
+flash_driver_t *flash_drivers[] = {
        &lpc2000_flash,
        &cfi_flash,
        &at91sam7_flash,
+       &at91sam7_old_flash,
        &str7x_flash,
        &str9x_flash,
+       &aduc702x_flash,
        &stellaris_flash,
        &str9xpec_flash,
        &stm32x_flash,
@@ -145,7 +151,7 @@ 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;
@@ -160,7 +166,7 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        for (p = flash_banks; p; p = p->next)
        {
                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));
@@ -171,7 +177,7 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->bus_width));
                Jim_ListAppendElement(interp, elem, Jim_NewStringObj(interp, "chip_width", -1));
                Jim_ListAppendElement(interp, elem, Jim_NewIntObj(interp, p->chip_width));
-               
+
                Jim_ListAppendElement(interp, list, elem);
        }
 
@@ -185,7 +191,7 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
        if (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>");
                register_command(cmd_ctx, flash_cmd, "probe", handle_flash_probe_command, COMMAND_EXEC,
@@ -374,7 +380,7 @@ int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char
                                else
                                        protect_state = "protection state unknown";
 
-                               command_print(cmd_ctx, "\t#%i: 0x%8.8x (0x%x %ikB) %s",
+                               command_print(cmd_ctx, "\t#%3i: 0x%8.8x (0x%x %ikB) %s",
                                                        j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
                                                        protect_state);
                        }
@@ -449,7 +455,7 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
                        command_print(cmd_ctx, "unknown error when checking erase state of flash bank #%s at 0x%8.8x",
                                args[0], p->base);
                }
-               
+
                for (j = 0; j < p->num_sectors; j++)
                {
                        char *erase_state;
@@ -461,11 +467,11 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
                        else
                                erase_state = "erase state unknown";
 
-                       command_print(cmd_ctx, "\t#%i: 0x%8.8x (0x%x %ikB) %s",
+                       command_print(cmd_ctx, "\t#%3i: 0x%8.8x (0x%x %ikB) %s",
                                                j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
                                                erase_state);
                }
-               
+
        }
 
        return ERROR_OK;
@@ -639,10 +645,10 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        /* flash auto-erase is disabled by default*/
        int auto_erase = 0;
-       
+
        if (strcmp(args[0], "erase")==0)
        {
                auto_erase = 1;
@@ -650,13 +656,13 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                argc--;
                command_print(cmd_ctx, "auto erase enabled");
        }
-       
+
 
        if (argc < 1)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        if (!target)
        {
                LOG_ERROR("no target selected");
@@ -719,16 +725,16 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        target_t *target = get_current_target(cmd_ctx);
        u32 i;
        int wordsize;
-       
+
        if (argc != 3)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        address = strtoul(args[0], NULL, 0);
        pattern = strtoul(args[1], NULL, 0);
        count   = strtoul(args[2], NULL, 0);
-       
+
        if(count == 0)
                return ERROR_OK;
 
@@ -747,7 +753,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        default:
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
-       
+
        chunk_count = MIN(count, (1024 / wordsize));
        switch(wordsize)
        {
@@ -770,7 +776,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                LOG_ERROR("BUG: can't happen");
                exit(-1);
        }
-       
+
        duration_start_measure(&duration);
 
        flash_set_dirty();
@@ -778,7 +784,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        if (err == ERROR_OK)
        {
                for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
-               { 
+               {
                        int cur_size = MIN( (count*wordsize - wrote) , 1024 );
                        if (err == ERROR_OK)
                        {
@@ -796,7 +802,7 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                                break;
                }
        }
-       
+
        duration_stop_measure(&duration, &duration_text);
 
        if(err == ERROR_OK)
@@ -905,7 +911,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);
@@ -970,7 +976,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
        u32 section_offset;
        flash_bank_t *c;
        int *padding;
-       
+
        section = 0;
        section_offset = 0;
 
@@ -984,10 +990,10 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
 
                flash_set_dirty();
        }
-       
+
        /* allocate padding array */
        padding = malloc(image->num_sections * sizeof(padding));
-       
+
        /* loop until we reach end of the image */
        while (section < image->num_sections)
        {
@@ -998,7 +1004,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                u32 run_address = image->sections[section].base_address + section_offset;
                u32 run_size = image->sections[section].size - section_offset;
                int pad_bytes = 0;
-               
+
                if (image->sections[section].size ==  0)
                {
                        LOG_WARNING("empty section %d", section);
@@ -1036,7 +1042,7 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                        run_size += image->sections[++section_last].size;
                        run_size += pad_bytes;
                        padding[section_last] = 0;
-                       
+
                        LOG_INFO("Padding image section %d with %d bytes", section_last-1, pad_bytes );
                }
 
@@ -1064,11 +1070,11 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                                free(padding);
                                return retval;
                        }
-                       
+
                        /* see if we need to pad the section */
                        while (padding[section]--)
                                 (buffer+buffer_size)[size_read++] = 0xff;
-                       
+
                        buffer_size += size_read;
                        section_offset += size_read;
 
@@ -1104,9 +1110,9 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase)
                if (written != NULL)
                        *written += run_size; /* add run size to total written counter */
        }
-       
+
        free(padding);
-       
+
        return retval;
 }
 
@@ -1117,18 +1123,18 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
        int buffer_size = sizeof(buffer);
        int i;
        int nBytes;
-       
+
        if (bank->target->state != TARGET_HALTED)
        {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
-       
+
        for (i = 0; i < bank->num_sectors; i++)
        {
                int j;
                bank->sectors[i].is_erased = 1;
-               
+
                for (j = 0; j < bank->sectors[i].size; j += buffer_size)
                {
                        int chunk;
@@ -1138,11 +1144,11 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
                        {
                                chunk = (j - bank->sectors[i].size);
                        }
-                       
+
                        retval = target->type->read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer);
                        if (retval != ERROR_OK)
                                return retval;
-               
+
                        for (nBytes = 0; nBytes < chunk; nBytes++)
                        {
                                if (buffer[nBytes] != 0xFF)
@@ -1153,7 +1159,7 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank)
                        }
                }
        }
-       
+
        return ERROR_OK;
 }
 
@@ -1164,18 +1170,18 @@ int default_flash_blank_check(struct flash_bank_s *bank)
        int retval;
        int fast_check = 0;
        int blank;
-       
+
        if (bank->target->state != TARGET_HALTED)
        {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
-               
+
        for (i = 0; i < bank->num_sectors; i++)
        {
                u32 address = bank->base + bank->sectors[i].offset;
                u32 size = bank->sectors[i].size;
-               
+
                if ((retval = target_blank_check_memory(target, address, size, &blank)) != ERROR_OK)
                {
                        fast_check = 0;
@@ -1187,12 +1193,12 @@ int default_flash_blank_check(struct flash_bank_s *bank)
                        bank->sectors[i].is_erased = 0;
                fast_check = 1;
        }
-               
+
        if (!fast_check)
        {
                LOG_USER("Running slow fallback erase check - add working memory");
                return default_flash_mem_blank_check(bank);
        }
-       
+
        return ERROR_OK;
 }

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)