Laurentiu Cocanu - more error handling fixes
[openocd.git] / src / flash / flash.c
index 3d450ac8dc0306dbd472cbc1959cbdfcec72b370..d5f89de6cf6acd4d6619dee284a5fbf1850a3961 100644 (file)
@@ -67,6 +67,7 @@ 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;
@@ -78,11 +79,11 @@ 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,
@@ -379,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);
                        }
@@ -466,7 +467,7 @@ 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);
                }
@@ -513,7 +514,11 @@ 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)
+               {
+                       free(duration_text);
+                       return retval;
+               }
                command_print(cmd_ctx, "erased address 0x%8.8x length %i in %s", address, length, duration_text);
                free(duration_text);
        }
@@ -575,7 +580,11 @@ 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)
+                       {
+                               free(duration_text);
+                               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);
@@ -638,7 +647,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)
        {
@@ -696,7 +705,12 @@ 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)
+       {
+               free(duration_text);
+               image_close(&image);
+               return retvaltemp;
+       }
        if (retval == ERROR_OK)
        {
                command_print(cmd_ctx, "wrote %u byte from file %s in %s (%f kb/s)",
@@ -712,7 +726,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;
@@ -802,7 +816,12 @@ int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char
                }
        }
 
-       duration_stop_measure(&duration, &duration_text);
+       if ((retval = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               return retval;
+       }
+
 
        if(err == ERROR_OK)
        {
@@ -828,7 +847,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)
@@ -864,7 +883,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 ((retvaltemp = duration_stop_measure(&duration, &duration_text)) != ERROR_OK)
+       {
+               free(duration_text);
+               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)",

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)