flash: Constify write buffer
[fw/openocd] / src / flash / nor / efm32.c
index eab113331f634baa65d88432a47bf984fed28b4b..3c46c76da0b02eec183a4f0f153a5ee78d8743e0 100644 (file)
@@ -42,6 +42,7 @@
 #define EFM_FAMILY_ID_GIANT_GECKO       72
 #define EFM_FAMILY_ID_TINY_GECKO        73
 #define EFM_FAMILY_ID_LEOPARD_GECKO     74
+#define EFM_FAMILY_ID_WONDER_GECKO      75
 
 #define EFM32_FLASH_ERASE_TMO           100
 #define EFM32_FLASH_WDATAREADY_TMO      100
@@ -97,7 +98,7 @@ struct efm32_info {
        uint16_t page_size;
 };
 
-static int efm32x_write(struct flash_bank *bank, uint8_t *buffer,
+static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer,
        uint32_t offset, uint32_t count);
 
 static int efm32x_get_flash_size(struct flash_bank *bank, uint16_t *flash_sz)
@@ -139,8 +140,10 @@ static int efm32x_read_info(struct flash_bank *bank,
 
        if (((cpuid >> 4) & 0xfff) == 0xc23) {
                /* Cortex M3 device */
+       } else if (((cpuid >> 4) & 0xfff) == 0xc24) {
+               /* Cortex M4 device */
        } else {
-               LOG_ERROR("Target is not CortexM3");
+               LOG_ERROR("Target is not CortexM3 or M4");
                return ERROR_FAIL;
        }
 
@@ -191,6 +194,18 @@ static int efm32x_read_info(struct flash_bank *bank,
                        LOG_ERROR("Invalid page size %u", efm32_info->page_size);
                        return ERROR_FAIL;
                }
+       } else if (EFM_FAMILY_ID_WONDER_GECKO == efm32_info->part_family) {
+               uint8_t pg_size = 0;
+               ret = target_read_u8(bank->target, EFM32_MSC_DI_PAGE_SIZE,
+                       &pg_size);
+               if (ERROR_OK != ret)
+                       return ret;
+
+               efm32_info->page_size = (1 << ((pg_size+10) & 0xff));
+               if (2048 != efm32_info->page_size) {
+                       LOG_ERROR("Invalid page size %u", efm32_info->page_size);
+                       return ERROR_FAIL;
+               }
        } else {
                LOG_ERROR("Unknown MCU family %d", efm32_info->part_family);
                return ERROR_FAIL;
@@ -484,7 +499,7 @@ static int efm32x_protect(struct flash_bank *bank, int set, int first, int last)
        return ERROR_OK;
 }
 
-static int efm32x_write_block(struct flash_bank *bank, uint8_t *buf,
+static int efm32x_write_block(struct flash_bank *bank, const uint8_t *buf,
        uint32_t offset, uint32_t count)
 {
        struct target *target = bank->target;
@@ -578,8 +593,7 @@ static int efm32x_write_block(struct flash_bank *bank, uint8_t *buf,
        };
 
        ret = target_write_buffer(target, write_algorithm->address,
-               sizeof(efm32x_flash_write_code),
-               (uint8_t *)efm32x_flash_write_code);
+                       sizeof(efm32x_flash_write_code), efm32x_flash_write_code);
        if (ret != ERROR_OK)
                return ret;
 
@@ -721,7 +735,7 @@ static int efm32x_write_word(struct flash_bank *bank, uint32_t addr,
        return ERROR_OK;
 }
 
-static int efm32x_write(struct flash_bank *bank, uint8_t *buffer,
+static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer,
                uint32_t offset, uint32_t count)
 {
        struct target *target = bank->target;
@@ -749,7 +763,7 @@ static int efm32x_write(struct flash_bank *bank, uint8_t *buffer,
                }
                LOG_INFO("odd number of bytes to write (%" PRIu32 "), extending to %" PRIu32 " "
                        "and padding with 0xff", old_count, count);
-               memset(buffer, 0xff, count);
+               memset(new_buffer, 0xff, count);
                buffer = memcpy(new_buffer, buffer, old_count);
        }
 
@@ -826,6 +840,9 @@ static int efm32x_probe(struct flash_bank *bank)
                case EFM_FAMILY_ID_LEOPARD_GECKO:
                        LOG_INFO("Leopard Gecko MCU detected");
                        break;
+               case EFM_FAMILY_ID_WONDER_GECKO:
+                       LOG_INFO("Wonder Gecko MCU detected");
+                       break;
                default:
                        LOG_ERROR("Unsupported MCU family %d",
                                efm32_mcu_info.part_family);
@@ -936,6 +953,9 @@ static int get_efm32x_info(struct flash_bank *bank, char *buf, int buf_size)
                case EFM_FAMILY_ID_LEOPARD_GECKO:
                        printed = snprintf(buf, buf_size, "Leopard Gecko");
                        break;
+               case EFM_FAMILY_ID_WONDER_GECKO:
+                       printed = snprintf(buf, buf_size, "Wonder Gecko");
+                       break;
        }
 
        buf += printed;