Georg Acher <acher@in.tum.de> implements the buffer flash mode for Spansion flashes...
[openocd.git] / src / flash / str9x.c
index fbae6c688e35a43e5830dd5df3097d3534c7a8a0..1160c7090a91ca36f2240cfdd0e97c21fca653d6 100644 (file)
@@ -2,6 +2,12 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2008 by Spencer Oliver                                  *
+ *   spen@spen-soft.co.uk                                                  *
+ *
+ *   Copyright (C) 2008 by Oyvind Harboe                                   *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
  *   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     *
@@ -180,6 +186,7 @@ int str9x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char
 
 int str9x_protect_check(struct flash_bank_s *bank)
 {
+       int retval;
        str9x_flash_bank_t *str9x_info = bank->driver_priv;
        target_t *target = bank->target;
        
@@ -189,6 +196,7 @@ int str9x_protect_check(struct flash_bank_s *bank)
 
        if (bank->target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -199,25 +207,46 @@ int str9x_protect_check(struct flash_bank_s *bank)
                if (str9x_info->bank1)
                {
                        adr = bank1start + 0x18;
-                       target_write_u16(target, adr, 0x90);
-                       target_read_u16(target, adr, (u16*)&status);
+                       if ((retval=target_write_u16(target, adr, 0x90))!=ERROR_OK)
+                       {
+                               return retval;
+                       }
+                       if ((retval=target_read_u16(target, adr, (u16*)&status))!=ERROR_OK)
+                       {
+                               return retval;
+                       }
                }
                else
                {
                        adr = bank1start + 0x14;
-                       target_write_u16(target, adr, 0x90);
-                       target_read_u32(target, adr, &status);
+                       if ((retval=target_write_u16(target, adr, 0x90))!=ERROR_OK)
+                       {
+                               return retval;
+                       }
+                       if ((retval=target_read_u32(target, adr, &status))!=ERROR_OK)
+                       {
+                               return retval;
+                       }
                }
        }
        else
        {
                adr = bank1start + 0x10;
-               target_write_u16(target, adr, 0x90);
-               target_read_u16(target, adr, (u16*)&status);
+               if ((retval=target_write_u16(target, adr, 0x90))!=ERROR_OK)
+               {
+                       return retval;
+               }
+               if ((retval=target_read_u16(target, adr, (u16*)&status))!=ERROR_OK)
+               {
+                       return retval;
+               }
        }
        
        /* read array command */
-       target_write_u16(target, adr, 0xFF);
+       if ((retval=target_write_u16(target, adr, 0xFF))!=ERROR_OK)
+       {
+               return retval;
+       }
        
        for (i = 0; i < bank->num_sectors; i++)
        {
@@ -240,6 +269,7 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
        
        if (bank->target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -257,27 +287,52 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
        
        for (i = first; i <= last; i++)
        {
+               int retval;
                adr = bank->base + bank->sectors[i].offset;
                
                /* erase sectors */
-               target_write_u16(target, adr, erase_cmd);
-               target_write_u16(target, adr, 0xD0);
+               if ((retval=target_write_u16(target, adr, erase_cmd))!=ERROR_OK)
+               {
+                       return retval;
+               }
+               if ((retval=target_write_u16(target, adr, 0xD0))!=ERROR_OK)
+               {
+                       return retval;
+               }
                
                /* get status */
-               target_write_u16(target, adr, 0x70);
-               
-               while (1) {
-                       target_read_u8(target, adr, &status);
+               if ((retval=target_write_u16(target, adr, 0x70))!=ERROR_OK)
+               {
+                       return retval;
+               }
+
+               int timeout;            
+               for (timeout=0; timeout<1000; timeout++) {
+                       if ((retval=target_read_u8(target, adr, &status))!=ERROR_OK)
+                       {
+                               return retval;
+                       }
                        if( status & 0x80 )
                                break;
-                       usleep(1000);
+                       alive_sleep(1);
+               }
+               if (timeout==1000)
+               {
+                       LOG_ERROR("erase timed out");
+                       return ERROR_FAIL;
                }
                
                /* clear status, also clear read array */
-               target_write_u16(target, adr, 0x50);
+               if ((retval=target_write_u16(target, adr, 0x50))!=ERROR_OK)
+               {
+                       return retval;
+               }
                
                /* read array command */
-               target_write_u16(target, adr, 0xFF);
+               if ((retval=target_write_u16(target, adr, 0xFF))!=ERROR_OK)
+               {
+                       return retval;
+               }
                
                if( status & 0x22 )
                {
@@ -305,6 +360,7 @@ int str9x_protect(struct flash_bank_s *bank, int set, int first, int last)
        
        if (bank->target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
        
@@ -456,6 +512,7 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
        
        if (bank->target->state != TARGET_HALTED)
        {
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
 
@@ -520,12 +577,19 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
                
                /* get status command */
                target_write_u16(target, bank_adr, 0x70);
-               
-               while (1) {
+       
+               int timeout;
+               for (timeout=0; timeout<1000; timeout++)
+               {       
                        target_read_u8(target, bank_adr, &status);
                        if( status & 0x80 )
                                break;
-                       usleep(1000);
+                       alive_sleep(1);
+               }
+               if (timeout==1000)
+               {
+                       LOG_ERROR("write timed out");
+                       return ERROR_FAIL;
                }
                
                /* clear status reg and read array */
@@ -563,11 +627,18 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
                /* query status command */
                target_write_u16(target, bank_adr, 0x70);
                
-               while (1) {
+               int timeout;
+               for (timeout=0; timeout<1000; timeout++)
+               {       
                        target_read_u8(target, bank_adr, &status);
                        if( status & 0x80 )
                                break;
-                       usleep(1000);
+                       alive_sleep(1);
+               }
+               if (timeout==1000)
+               {
+                       LOG_ERROR("write timed out");
+                       return ERROR_FAIL;
                }
                
                /* clear status reg and read array */
@@ -623,6 +694,7 @@ int str9x_handle_flash_config_command(struct command_context_s *cmd_ctx, char *c
        
        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)