aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer Oliver <spen@spen-soft.co.uk>2012-11-20 12:53:22 +0000
committerSpencer Oliver <spen@spen-soft.co.uk>2013-01-21 16:43:09 +0000
commit86cc37183a9f5f7f86a9e20d9e8c3460d22aca50 (patch)
tree9b9a8da2d0af56ed039df99969d04a2a00301657
parent061f828a504e458352f83251ea87108133f5b086 (diff)
downloadriscv-openocd-86cc37183a9f5f7f86a9e20d9e8c3460d22aca50.zip
riscv-openocd-86cc37183a9f5f7f86a9e20d9e8c3460d22aca50.tar.gz
riscv-openocd-86cc37183a9f5f7f86a9e20d9e8c3460d22aca50.tar.bz2
flash: stm32f2x support write protection
Change-Id: I42662681104bb06e28148229464ae144c4a54538 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/989 Tested-by: jenkins
-rw-r--r--src/flash/nor/stm32f2x.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c
index 4083882..7201914 100644
--- a/src/flash/nor/stm32f2x.c
+++ b/src/flash/nor/stm32f2x.c
@@ -377,6 +377,28 @@ static int stm32x_write_options(struct flash_bank *bank)
static int stm32x_protect_check(struct flash_bank *bank)
{
+ struct target *target = bank->target;
+ struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
+
+ if (target->state != TARGET_HALTED) {
+ LOG_ERROR("Target not halted");
+ return ERROR_TARGET_NOT_HALTED;
+ }
+
+ /* read write protection settings */
+ int retval = stm32x_read_options(bank);
+ if (retval != ERROR_OK) {
+ LOG_DEBUG("unable to read option bytes");
+ return retval;
+ }
+
+ for (int i = 0; i < bank->num_sectors; i++) {
+ if (stm32x_info->option_bytes.protection & (1 << i))
+ bank->sectors[i].is_protected = 0;
+ else
+ bank->sectors[i].is_protected = 1;
+ }
+
return ERROR_OK;
}
@@ -428,6 +450,33 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
{
+ struct target *target = bank->target;
+ struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
+
+ if (target->state != TARGET_HALTED) {
+ LOG_ERROR("Target not halted");
+ return ERROR_TARGET_NOT_HALTED;
+ }
+
+ /* read protection settings */
+ int retval = stm32x_read_options(bank);
+ if (retval != ERROR_OK) {
+ LOG_DEBUG("unable to read option bytes");
+ return retval;
+ }
+
+ for (int i = first; i <= last; i++) {
+
+ if (set)
+ stm32x_info->option_bytes.protection &= ~(1 << i);
+ else
+ stm32x_info->option_bytes.protection |= (1 << i);
+ }
+
+ retval = stm32x_write_options(bank);
+ if (retval != ERROR_OK)
+ return retval;
+
return ERROR_OK;
}