]> git.sur5r.net Git - openocd/blobdiff - src/flash/flash.c
Pavel Chromy, the patch fixes an issue with PRESTO & FTD2XX under Linux.
[openocd] / src / flash / flash.c
index 96a74cd679411e20e2f8f8805d98f1e57639b887..1c6773dbbcbdb93ac5f61e1088b676974d8cd7e5 100644 (file)
@@ -93,7 +93,7 @@ static int flash_driver_write(struct flash_bank_s *bank, u8 *buffer, u32 offset,
        retval=bank->driver->write(bank, buffer, offset, count);
        if (retval!=ERROR_OK)
        {
-               ERROR("error writing to flash at address 0x%08x at offset 0x%8.8x", bank->base, offset);
+               ERROR("error writing to flash at address 0x%08x at offset 0x%8.8x (%d)", bank->base, offset, retval);
        }
 
        return retval;
@@ -106,7 +106,7 @@ static int flash_driver_erase(struct flash_bank_s *bank, int first, int last)
        retval=bank->driver->erase(bank, first, last);
        if (retval!=ERROR_OK)
        {
-               ERROR("failed erasing banks %d to %d", first, last);
+               ERROR("failed erasing sectors %d to %d (%d)", first, last, retval);
        }
 
        return retval;
@@ -119,7 +119,7 @@ int flash_driver_protect(struct flash_bank_s *bank, int set, int first, int last
        retval=bank->driver->protect(bank, set, first, last);
        if (retval!=ERROR_OK)
        {
-               ERROR("failed protecting banks %d to %d", first, last);
+               ERROR("failed setting protection for areas %d to %d (%d)", first, last, retval);
        }
 
        return retval;
@@ -181,6 +181,17 @@ flash_bank_t *get_flash_bank_by_num_noprobe(int num)
        return NULL;
 }
 
+int flash_get_bank_count()
+{
+       flash_bank_t *p;
+       int i = 0;
+       for (p = flash_banks; p; p = p->next)
+       {
+               i++;
+       }
+       return i;
+}
+
 flash_bank_t *get_flash_bank_by_num(int num)
 {
        flash_bank_t *p = get_flash_bank_by_num_noprobe(num);
@@ -300,6 +311,7 @@ int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char
        flash_bank_t *p;
        int i = 0;
        int j = 0;
+       int retval;
 
        if (argc != 1)
        {
@@ -340,8 +352,11 @@ int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char
                                                        erase_state, protect_state);
                        }
 
-                       p->driver->info(p, buf, 1024);
+                       *buf = '\0'; /* initialize buffer, otherwise it migh contain garbage if driver function fails */
+                       retval = p->driver->info(p, buf, sizeof(buf));
                        command_print(cmd_ctx, "%s", buf);
+                       if (retval != ERROR_OK)
+                               ERROR("error retrieving flash info (%d)", retval);
                }
        }
 
@@ -605,7 +620,6 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm
        retval = image_open(&image, args[0], (argc == 3) ? args[2] : NULL);
        if (retval != ERROR_OK)
        {
-               command_print(cmd_ctx, "image_open error: %s", image.error_str);
                return retval;
        }
 
@@ -662,14 +676,12 @@ int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd
 
        if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
        {
-               command_print(cmd_ctx, "flash write_binary error: %s", fileio.error_str);
                return ERROR_OK;
        }
 
        buffer = malloc(fileio.size);
        if (fileio_read(&fileio, fileio.size, buffer, &buf_cnt) != ERROR_OK)
        {
-               command_print(cmd_ctx, "flash write_binary error: %s", fileio.error_str);
                return ERROR_OK;
        }
 
@@ -910,7 +922,6 @@ int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd
        if (argc != 1)
        {
                return ERROR_COMMAND_SYNTAX_ERROR;
-
        }
 
        if (strcmp(args[0], "on") == 0)