]> git.sur5r.net Git - openocd/blobdiff - src/flash/str9x.c
More robust handling of unknown target state for step/continue packet.
[openocd] / src / flash / str9x.c
index d79e984f5f4f89e4db095ce9cd4f2d4e7d1531af..68fefc1bd93baa4bdf8352453b6a21e66fa66c2a 100644 (file)
@@ -64,7 +64,6 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count);
 int str9x_probe(struct flash_bank_s *bank);
 int str9x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int str9x_protect_check(struct flash_bank_s *bank);
-int str9x_erase_check(struct flash_bank_s *bank);
 int str9x_info(struct flash_bank_s *bank, char *buf, int buf_size);
 
 int str9x_handle_flash_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
@@ -79,7 +78,7 @@ flash_driver_t str9x_flash =
        .write = str9x_write,
        .probe = str9x_probe,
        .auto_probe = str9x_probe,
-       .erase_check = str9x_erase_check,
+       .erase_check = default_flash_blank_check,
        .protect_check = str9x_protect_check,
        .info = str9x_info
 };
@@ -115,7 +114,7 @@ int str9x_build_block_list(struct flash_bank_s *bank)
                        bank1start = bank->base;
                        break;
                default:
-                       ERROR("BUG: unknown bank->size encountered");
+                       LOG_ERROR("BUG: unknown bank->size encountered");
                        exit(-1);
        }
                
@@ -156,7 +155,7 @@ int str9x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char
        
        if (argc < 6)
        {
-               WARNING("incomplete flash_bank str9x configuration");
+               LOG_WARNING("incomplete flash_bank str9x configuration");
                return ERROR_FLASH_BANK_INVALID;
        }
        
@@ -170,44 +169,6 @@ int str9x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char
        return ERROR_OK;
 }
 
-int str9x_blank_check(struct flash_bank_s *bank, int first, int last)
-{
-       target_t *target = bank->target;
-       u8 *buffer;
-       int i;
-       int nBytes;
-       
-       if ((first < 0) || (last > bank->num_sectors))
-               return ERROR_FLASH_SECTOR_INVALID;
-
-       if (bank->target->state != TARGET_HALTED)
-       {
-               return ERROR_TARGET_NOT_HALTED;
-       }
-       
-       buffer = malloc(256);
-       
-       for (i = first; i <= last; i++)
-       {
-               bank->sectors[i].is_erased = 1;
-
-               target->type->read_memory(target, bank->base + bank->sectors[i].offset, 4, 256/4, buffer);
-               
-               for (nBytes = 0; nBytes < 256; nBytes++)
-               {
-                       if (buffer[nBytes] != 0xFF)
-                       {
-                               bank->sectors[i].is_erased = 0;
-                               break;
-                       }
-               }       
-       }
-       
-       free(buffer);
-
-       return ERROR_OK;
-}
-
 int str9x_protect_check(struct flash_bank_s *bank)
 {
        str9x_flash_bank_t *str9x_info = bank->driver_priv;
@@ -252,12 +213,12 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
        {
                return ERROR_TARGET_NOT_HALTED;
        }
-    
+
        for (i = first; i <= last; i++)
        {
                adr = bank->base + bank->sectors[i].offset;
                
-       /* erase sectors */
+               /* erase sectors */
                target_write_u16(target, adr, 0x20);
                target_write_u16(target, adr, 0xD0);
                
@@ -279,7 +240,7 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
                
                if( status & 0x22 )
                {
-                       ERROR("error erasing flash bank, status: 0x%x", status);
+                       LOG_ERROR("error erasing flash bank, status: 0x%x", status);
                        return ERROR_FLASH_OPERATION_FAILED;
                }
        }
@@ -360,7 +321,7 @@ int str9x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 cou
        /* flash write code */
        if (target_alloc_working_area(target, 4 * 19, &str9x_info->write_algorithm) != ERROR_OK)
        {
-               WARNING("no working area available, can't do block memory writes");
+               LOG_WARNING("no working area available, can't do block memory writes");
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        };
                
@@ -376,7 +337,7 @@ int str9x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 cou
                        if (str9x_info->write_algorithm)
                                target_free_working_area(target, str9x_info->write_algorithm);
                        
-                       WARNING("no large enough working area available, can't do block memory writes");
+                       LOG_WARNING("no large enough working area available, can't do block memory writes");
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
                }
        }
@@ -404,7 +365,7 @@ int str9x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 cou
                {
                        target_free_working_area(target, source);
                        target_free_working_area(target, str9x_info->write_algorithm);
-                       ERROR("error executing str9x flash write algorithm");
+                       LOG_ERROR("error executing str9x flash write algorithm");
                        return ERROR_FLASH_OPERATION_FAILED;
                }
        
@@ -446,10 +407,10 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
        {
                return ERROR_TARGET_NOT_HALTED;
        }
-       
+
        if (offset & 0x1)
        {
-               WARNING("offset 0x%x breaks required 2-byte alignment", offset);
+               LOG_WARNING("offset 0x%x breaks required 2-byte alignment", offset);
                return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
        }
        
@@ -482,11 +443,11 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count)
                        {
                                /* if block write failed (no sufficient working area),
                                 * we use normal (slow) single dword accesses */ 
-                               WARNING("couldn't use block writes, falling back to single memory accesses");
+                               LOG_WARNING("couldn't use block writes, falling back to single memory accesses");
                        }
                        else if (retval == ERROR_FLASH_OPERATION_FAILED)
                        {
-                               ERROR("flash writing failed with error code: 0x%x", retval);
+                               LOG_ERROR("flash writing failed with error code: 0x%x", retval);
                                return ERROR_FLASH_OPERATION_FAILED;
                        }
                }
@@ -581,11 +542,6 @@ int str9x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, c
        return ERROR_OK;
 }
 
-int str9x_erase_check(struct flash_bank_s *bank)
-{
-       return str9x_blank_check(bank, 0, bank->num_sectors - 1);
-}
-
 int str9x_info(struct flash_bank_s *bank, char *buf, int buf_size)
 {
        snprintf(buf, buf_size, "str9x flash driver info" );
@@ -600,8 +556,7 @@ int str9x_handle_flash_config_command(struct command_context_s *cmd_ctx, char *c
        
        if (argc < 5)
        {
-               command_print(cmd_ctx, "usage: str9x flash_config <bank> <bbsize> <nbsize> <bbstart> <nbstart>");
-               return ERROR_OK;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
        
        bank = get_flash_bank_by_num(strtoul(args[0], NULL, 0));