- if (stellaris_info->did1 == 0)
- {
- LOG_WARNING("Cannot identify target as Stellaris");
- return ERROR_FLASH_OPERATION_FAILED;
+ /* Read each Flash Memory Protection Program Enable (FMPPE) register
+ * to report any pages that we can't write. Ignore the Read Enable
+ * register (FMPRE).
+ */
+ for (i = 0, page = 0;
+ i < DIV_ROUND_UP(stellaris->num_lockbits, 32u);
+ i++) {
+ uint32_t lockbits;
+
+ status = target_read_u32(bank->target,
+ SCB_BASE + (i ? (FMPPE0 + 4 * i) : FMPPE),
+ &lockbits);
+ LOG_DEBUG("FMPPE%d = %#8.8x (status %d)", i, lockbits, status);
+ if (status != ERROR_OK)
+ goto done;
+
+ for (unsigned j = 0; j < 32; j++) {
+ unsigned k;
+
+ for (k = 0; k < stellaris->pages_in_lockregion; k++) {
+ if (page >= (unsigned) bank->num_sectors)
+ goto done;
+ bank->sectors[page++].is_protected =
+ !(lockbits & (1 << j));
+ }
+ }