flash: fix protect check for pic32mx1x/2x family
authorSpencer Oliver <spen@spen-soft.co.uk>
Thu, 3 May 2012 09:44:42 +0000 (10:44 +0100)
committerSpencer Oliver <spen@spen-soft.co.uk>
Mon, 14 May 2012 09:37:50 +0000 (09:37 +0000)
Change-Id: Ib2692d8b79e52cd40f429008047494aa7f552984
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/612
Tested-by: jenkins
Reviewed-by: Xiaofan <xiaofanc@gmail.com>
src/flash/nor/pic32mx.c

index 248e0615761a0874e5a8d51ecf9091d7b76cc8de..8cd0fe656ddf03c99740f6332223bcc3a21b7cc0 100644 (file)
@@ -275,8 +275,13 @@ static int pic32mx_protect_check(struct flash_bank *bank)
                        num_pages = 0;                  /* All pages unprotected */
                else
                        num_pages = 0xffff;             /* All pages protected */
-       } else /* pgm flash */
-               num_pages = (~devcfg0 >> 12) & 0xff;
+       } else {
+               /* pgm flash */
+               if (pic32mx_info->dev_type == MX_1_2)
+                       num_pages = (~devcfg0 >> 10) & 0x3f;
+               else
+                       num_pages = (~devcfg0 >> 12) & 0xff;
+       }
 
        for (s = 0; s < bank->num_sectors && s < num_pages; s++)
                bank->sectors[s].is_protected = 1;