summaryrefslogtreecommitdiff
path: root/src/flash/str9x.c
diff options
context:
space:
mode:
authorntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-06-05 18:55:55 +0000
committerntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-06-05 18:55:55 +0000
commita532e98176d1a01378ec7b49658610970f3e1d54 (patch)
treeea40ec2c04ad2552b32ae24d4220ef349a5b72cd /src/flash/str9x.c
parent24092a51720789c200c83f3a3867a4e02861661c (diff)
downloadopenocd+libswd-a532e98176d1a01378ec7b49658610970f3e1d54.tar.gz
openocd+libswd-a532e98176d1a01378ec7b49658610970f3e1d54.tar.bz2
openocd+libswd-a532e98176d1a01378ec7b49658610970f3e1d54.tar.xz
openocd+libswd-a532e98176d1a01378ec7b49658610970f3e1d54.zip
- erase bank using bank erase rather than each sector
- Thanks Fredrik Hederstierna git-svn-id: svn://svn.berlios.de/openocd/trunk@704 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/flash/str9x.c')
-rw-r--r--src/flash/str9x.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/flash/str9x.c b/src/flash/str9x.c
index 96cad399..fbae6c68 100644
--- a/src/flash/str9x.c
+++ b/src/flash/str9x.c
@@ -236,18 +236,31 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
int i;
u32 adr;
u8 status;
+ u8 erase_cmd;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
+ /* Check if we erase whole bank */
+ if ((first == 0) && (last == (bank->num_sectors - 1)))
+ {
+ /* Optimize to run erase bank command instead of sector */
+ erase_cmd = 0x80;
+ }
+ else
+ {
+ /* Erase sector command */
+ erase_cmd = 0x20;
+ }
+
for (i = first; i <= last; i++)
{
adr = bank->base + bank->sectors[i].offset;
/* erase sectors */
- target_write_u16(target, adr, 0x20);
+ target_write_u16(target, adr, erase_cmd);
target_write_u16(target, adr, 0xD0);
/* get status */
@@ -271,6 +284,10 @@ int str9x_erase(struct flash_bank_s *bank, int first, int last)
LOG_ERROR("error erasing flash bank, status: 0x%x", status);
return ERROR_FLASH_OPERATION_FAILED;
}
+
+ /* If we ran erase bank command, we are finished */
+ if (erase_cmd == 0x80)
+ break;
}
for (i = first; i <= last; i++)