flash: stm32f2x support write protection 89/989/5
authorSpencer Oliver <spen@spen-soft.co.uk>
Tue, 20 Nov 2012 12:53:22 +0000 (12:53 +0000)
committerSpencer Oliver <spen@spen-soft.co.uk>
Mon, 21 Jan 2013 16:43:09 +0000 (16:43 +0000)
Change-Id: I42662681104bb06e28148229464ae144c4a54538
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/989
Tested-by: jenkins
src/flash/nor/stm32f2x.c

index 4083882bb9358d620653e61845ac438dc1f734a4..7201914dc1ee7b9a9d938915052bfebc36dd3add 100644 (file)
@@ -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;
 }
 

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)