wip.

What to do about protection?

Signed-off-by: Øyvind Harboe <oyvind.har...@zylin.com>
---
 src/flash/nor/stm32x.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/src/flash/nor/stm32x.c b/src/flash/nor/stm32x.c
index 3914d25..52b0848 100644
--- a/src/flash/nor/stm32x.c
+++ b/src/flash/nor/stm32x.c
@@ -835,6 +835,16 @@ static int stm32x_write(struct flash_bank *bank, uint8_t 
*buffer,
        return target_write_u32(target, STM32_FLASH_CR, FLASH_LOCK);
 }
 
+static void setup_sector(struct flash_bank *bank, int start, int num, int size)
+{
+       for (int i = start; i < (start + num) ; i++)
+       {
+               bank->sectors[i].offset = bank->size;
+               bank->sectors[i].size = size;
+               bank->size += bank->sectors[i].size;
+       }
+}
+
 static int stm32x_probe(struct flash_bank *bank)
 {
        struct target *target = bank->target;
@@ -878,6 +888,57 @@ static int stm32x_probe(struct flash_bank *bank)
                        num_pages = 128;
                }
        }
+       else if ((device_id & 0x7ff) == 0x411)
+       {
+               /* sectors sizes vary, handle this in a different code path
+                * than the rest.
+                *
+                * RM0033
+                * http://www.st.com/internet/mcu/product/250192.jsp
+                *
+                * PM0059
+                * 
www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/PROGRAMMING_MANUAL/CD00233952.pdf
+                *
+                * 1mByte part with 4 x 16, 1 x 64, 7 x 128kBytes sectors
+                *
+                * What's the protection page size???
+                *
+                * Tested with STM3220F-EVAL board.
+                *
+                */
+               // Uhhh.... what to use here?
+               stm32x_info->ppage_size = 4;
+
+               /* calculate numbers of pages*/
+               num_pages = 4 + 1 + 7;
+
+               if (bank->sectors)
+               {
+                       free(bank->sectors);
+                       bank->sectors = NULL;
+               }
+
+               bank->base = base_address;
+               bank->num_sectors = num_pages;
+               bank->sectors = malloc(sizeof(struct flash_sector) * num_pages);
+
+               bank->size = 0;
+               setup_sector(bank, 0, 4, 16 * 1024);
+               setup_sector(bank, 4, 1, 64 * 1024);
+               setup_sector(bank, 4+1, 7, 128 * 1024);
+
+               for (i = 0; i < num_pages; i++)
+               {
+                       bank->sectors[i].is_erased = -1;
+                       bank->sectors[i].is_protected = 0;
+               }
+
+               LOG_INFO("flash size = %dkBytes", bank->size / 1024);
+
+               stm32x_info->probed = 1;
+
+               return ERROR_OK;
+       }
        else if ((device_id & 0x7ff) == 0x412)
        {
                /* low density - we have 1k pages
@@ -1058,6 +1119,31 @@ static int get_stm32x_info(struct flash_bank *bank, char 
*buf, int buf_size)
                                break;
                }
        }
+       else if ((device_id & 0x7ff) == 0x411)
+       {
+               printed = snprintf(buf, buf_size, "stm32x (1mByte part) - Rev: 
");
+               buf += printed;
+               buf_size -= printed;
+
+               switch (device_id >> 16)
+               {
+                       case 0x1000:
+                               snprintf(buf, buf_size, "A");
+                               break;
+
+                       case 0x2000:
+                               snprintf(buf, buf_size, "B");
+                               break;
+
+                       case 0x1001:
+                               snprintf(buf, buf_size, "Z");
+                               break;
+
+                       default:
+                               snprintf(buf, buf_size, "unknown");
+                               break;
+               }
+       }
        else if ((device_id & 0x7ff) == 0x412)
        {
                printed = snprintf(buf, buf_size, "stm32x (Low Density) - Rev: 
");
-- 
1.7.0.4

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to