aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Bonnes2013-10-06 15:45:54 +0200
committerUwe Bonnes2013-10-20 16:14:19 +0200
commit15e529a43a48be51f3da24ef39d0c5ea859b4cbe (patch)
treeca9df313b768d38efe55de323ce79b9488ce74f2
parentc395c6f73a220cd6da26ff3b48afde8487b6199f (diff)
stm32f1.c: On a read protected device, deny any other option action than erase.
Otherwise the first option action triggers an error, inhibiting further option actions.
-rw-r--r--src/stm32f1.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/stm32f1.c b/src/stm32f1.c
index 03dcc43..4dc5768 100644
--- a/src/stm32f1.c
+++ b/src/stm32f1.c
@@ -101,6 +101,8 @@ static const char stm32hd_xml_memory_map[] = "<?xml version=\"1.0\"?>"
#define FLASH_CR_MER (1 << 2)
#define FLASH_CR_PER (1 << 1)
+#define FLASH_OBR_RDPRT (1 << 1)
+
#define FLASH_SR_BSY (1 << 0)
#define FLASH_OBP_RDP 0x1FFFF800
@@ -341,6 +343,7 @@ static bool stm32f1_cmd_option(target *t, int argc, char *argv[])
uint32_t addr, val;
uint32_t flash_obp_rdp_key;
ADIv5_AP_t *ap = adiv5_target_ap(t);
+ uint32_t rdprt;
switch(t->idcode) {
case 0x422: /* STM32F30x */
@@ -350,6 +353,7 @@ static bool stm32f1_cmd_option(target *t, int argc, char *argv[])
break;
default: flash_obp_rdp_key = FLASH_OBP_RDP_KEY;
}
+ rdprt = (adiv5_ap_mem_read(ap, FLASH_OBR) & FLASH_OBR_RDPRT);
stm32f1_flash_unlock(ap);
adiv5_ap_mem_write(ap, FLASH_OPTKEYR, KEY1);
adiv5_ap_mem_write(ap, FLASH_OPTKEYR, KEY2);
@@ -357,6 +361,10 @@ static bool stm32f1_cmd_option(target *t, int argc, char *argv[])
if ((argc == 2) && !strcmp(argv[1], "erase")) {
stm32f1_option_erase(t);
stm32f1_option_write(t, FLASH_OBP_RDP, flash_obp_rdp_key);
+ } else if (rdprt) {
+ gdb_out("Device is Read Protected\n");
+ gdb_out("Use \"monitor option erase\" to unprotect, erasing device\n");
+ return true;
} else if (argc == 3) {
addr = strtol(argv[1], NULL, 0);
val = strtol(argv[2], NULL, 0);