- remove target specific variant and use target->variant member
[openocd.git] / src / flash / flash.c
index b2ebe0b79a0491f787feca8c4b38e59f6e951db8..c5cf757f946a0a48a231c64cc17d07a72757e104 100644 (file)
@@ -80,25 +80,23 @@ extern flash_driver_t lpc288x_flash;
 extern flash_driver_t ocl_flash;
 
 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,
-        &tms470_flash,
-        &ecosflash_flash,
-        &lpc288x_flash,
-        &ocl_flash,
-        NULL,
+       &lpc2000_flash,
+       &cfi_flash,
+       &at91sam7_flash,
+       &at91sam7_old_flash,
+       &str7x_flash,
+       &str9x_flash,
+       &aduc702x_flash,
+       &stellaris_flash,
+       &str9xpec_flash,
+       &stm32x_flash,
+       &tms470_flash,
+       &ecosflash_flash,
+       &lpc288x_flash,
+       &ocl_flash,
+       NULL,
 };
 
-
-
 flash_bank_t *flash_banks;
 static         command_t *flash_cmd;
 
@@ -146,7 +144,7 @@ int flash_register_commands(struct command_context_s *cmd_ctx)
 {
        flash_cmd = register_command(cmd_ctx, NULL, "flash", NULL, COMMAND_ANY, NULL);
 
-       register_command(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash_bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
+       register_command(cmd_ctx, flash_cmd, "bank", handle_flash_bank_command, COMMAND_CONFIG, "flash bank <driver> <base> <size> <chip_width> <bus_width> <target> [driver_options ...]");
        return ERROR_OK;
 }
 
@@ -159,11 +157,6 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                return JIM_ERR;
        }
 
-       if (!flash_banks)
-       {
-               return JIM_ERR;
-       }
-
        Jim_Obj *list=Jim_NewListObj(interp, NULL, 0);
        for (p = flash_banks; p; p = p->next)
        {
@@ -190,10 +183,10 @@ static int jim_flash_banks(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 
 int flash_init_drivers(struct command_context_s *cmd_ctx)
 {
+       register_jim(cmd_ctx, "ocd_flash_banks", jim_flash_banks, "return information about the flash banks");
+
        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,
@@ -208,7 +201,7 @@ int flash_init_drivers(struct command_context_s *cmd_ctx)
                                                 "erase address range <address> <length>");
 
                register_command(cmd_ctx, flash_cmd, "fillw", handle_flash_fill_command, COMMAND_EXEC,
-                                                "fill with pattern <address> <word_pattern> <count>");
+                                                "fill with pattern (no autoerase) <address> <word_pattern> <count>");
                register_command(cmd_ctx, flash_cmd, "fillh", handle_flash_fill_command, COMMAND_EXEC,
                                                 "fill with pattern <address> <halfword_pattern> <count>");
                register_command(cmd_ctx, flash_cmd, "fillb", handle_flash_fill_command, COMMAND_EXEC,
@@ -473,7 +466,6 @@ int handle_flash_erase_check_command(struct command_context_s *cmd_ctx, char *cm
                                                j, p->sectors[j].offset, p->sectors[j].size, p->sectors[j].size>>10,
                                                erase_state);
                }
-
        }
 
        return ERROR_OK;
@@ -516,7 +508,10 @@ int handle_flash_erase_address_command(struct command_context_s *cmd_ctx, char *
 
        if ((retval = flash_erase_address_range(target, address, length)) == ERROR_OK)
        {
-               duration_stop_measure(&duration, &duration_text);
+               if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+               {
+                       return retval;
+               }
                command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
                free(duration_text);
        }
@@ -578,7 +573,10 @@ int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, cha
 
                if ((retval = flash_driver_erase(p, first, last)) == ERROR_OK)
                {
-                       duration_stop_measure(&duration, &duration_text);
+                       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+                       {
+                               return retval;
+                       }
 
                        command_print(cmd_ctx, "erased sectors %i through %i on flash bank %i in %s", first, last, strtoul(args[0], 0, 0), duration_text);
                        free(duration_text);
@@ -641,7 +639,7 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
        duration_t duration;
        char *duration_text;
 
-       int retval;
+       int retval, retvaltemp;
 
        if (argc < 1)
        {
@@ -659,7 +657,6 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                command_print(cmd_ctx, "auto erase enabled");
        }
 
-
        if (argc < 1)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -699,7 +696,11 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
                return retval;
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               image_close(&image);
+               return retvaltemp;
+       }
        if (retval == ERROR_OK)
        {
                command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
@@ -715,7 +716,7 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
 
 int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-       int err = ERROR_OK;
+       int err = ERROR_OK, retval;
        u32 address;
        u32 pattern;
        u32 count;
@@ -740,7 +741,6 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
        if(count == 0)
                return ERROR_OK;
 
-
        switch(cmd[4])
        {
        case 'w':
@@ -781,31 +781,25 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
 
        duration_start_measure(&duration);
 
-       flash_set_dirty();
-       err = flash_erase_address_range( target, address, count*wordsize );
-       if (err == ERROR_OK)
+       for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
        {
-               for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk))
+               int cur_size = MIN( (count*wordsize - wrote) , 1024 );
+               flash_bank_t *bank;
+               bank = get_flash_bank_by_addr(target, address);
+               if(bank == NULL)
                {
-                       int cur_size = MIN( (count*wordsize - wrote) , 1024 );
-                       if (err == ERROR_OK)
-                       {
-                               flash_bank_t *bank;
-                               bank = get_flash_bank_by_addr(target, address);
-                               if(bank == NULL)
-                               {
-                                       err = ERROR_FAIL;
-                                       break;
-                               }
-                               err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size);
-                               wrote += cur_size;
-                       }
-                       if (err!=ERROR_OK)
-                               break;
+                       return ERROR_FAIL;
                }
+               err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size);
+               if (err!=ERROR_OK)
+                       return err;
+               wrote += cur_size;
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               return retval;
+       }
 
        if(err == ERROR_OK)
        {
@@ -831,7 +825,7 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
        duration_t duration;
        char *duration_text;
 
-       int retval;
+       int retval, retvaltemp;
        flash_bank_t *p;
 
        if (argc != 3)
@@ -867,8 +861,12 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
        free(buffer);
        buffer = NULL;
 
-       duration_stop_measure(&duration, &duration_text);
-       if (retval!=ERROR_OK)
+       if ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               fileio_close(&fileio);
+               return retvaltemp;
+       }
+       if (retval==ERROR_OK)
        {
        command_print(cmd_ctx, "wrote  %"PRIi64" byte from file %s to flash bank %i at offset 0x%8.8x in %s (%f kb/s)",
                fileio.size, args[1], strtoul(args[0], NULL, 0), offset, duration_text,
@@ -1171,7 +1169,7 @@ int default_flash_blank_check(struct flash_bank_s *bank)
        int i;
        int retval;
        int fast_check = 0;
-       int blank;
+       u32 blank;
 
        if (bank->target->state != TARGET_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)