SPI table updates (some new devices and new info)
[openocd.git] / src / flash / nor / mrvlqspi.c
index 132e5f3..cb2cfdb 100644 (file)
@@ -503,6 +503,9 @@ static int mrvlqspi_bulk_erase(struct flash_bank *bank)
        int retval;
        struct mrvlqspi_flash_bank *mrvlqspi_info = bank->driver_priv;
 
+       if (mrvlqspi_info->dev->chip_erase_cmd == 0x00)
+               return ERROR_FLASH_OPER_UNSUPPORTED;
+
        /* Set flash write enable */
        retval = mrvlqspi_set_write_status(bank, WRITE_ENABLE);
        if (retval != ERROR_OK)
@@ -570,6 +573,9 @@ static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
                                " Falling back to sector-by-sector erase.");
        }
 
+       if (mrvlqspi_info->dev->erase_cmd == 0x00)
+               return ERROR_FLASH_OPER_UNSUPPORTED;
+
        for (sector = first; sector <= last; sector++) {
                retval = mrvlqspi_block_erase(bank,
                                sector * mrvlqspi_info->dev->sectorsize);
@@ -619,7 +625,9 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
                }
        }
 
-       page_size = mrvlqspi_info->dev->pagesize;
+       /* if no valid page_size, use reasonable default */
+       page_size = mrvlqspi_info->dev->pagesize ?
+               mrvlqspi_info->dev->pagesize : SPIFLASH_DEF_PAGESIZE;
 
        /* See contrib/loaders/flash/mrvlqspi.S for src */
        static const uint8_t mrvlqspi_flash_write_code[] = {
@@ -826,6 +834,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
        uint32_t id = 0;
        int retval;
        struct flash_sector *sectors;
+       uint32_t sectorsize;
 
        /* If we've already probed, we should be fine to skip this time. */
        if (mrvlqspi_info->probed)
@@ -859,12 +868,20 @@ static int mrvlqspi_probe(struct flash_bank *bank)
        LOG_INFO("Found flash device \'%s\' ID 0x%08" PRIx32,
                mrvlqspi_info->dev->name, mrvlqspi_info->dev->device_id);
 
+
        /* Set correct size value */
        bank->size = mrvlqspi_info->dev->size_in_bytes;
+       if (bank->size <= (1UL << 16))
+               LOG_WARNING("device needs 2-byte addresses - not implemented");
+       if (bank->size > (1UL << 24))
+               LOG_WARNING("device needs paging or 4-byte addresses - not implemented");
+
+       /* if no sectors, treat whole bank as single sector */
+       sectorsize = mrvlqspi_info->dev->sectorsize ?
+               mrvlqspi_info->dev->sectorsize : mrvlqspi_info->dev->size_in_bytes;
 
        /* create and fill sectors array */
-       bank->num_sectors = mrvlqspi_info->dev->size_in_bytes /
-                                       mrvlqspi_info->dev->sectorsize;
+       bank->num_sectors = mrvlqspi_info->dev->size_in_bytes / sectorsize;
        sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
        if (sectors == NULL) {
                LOG_ERROR("not enough memory");
@@ -872,9 +889,8 @@ static int mrvlqspi_probe(struct flash_bank *bank)
        }
 
        for (int sector = 0; sector < bank->num_sectors; sector++) {
-               sectors[sector].offset =
-                               sector * mrvlqspi_info->dev->sectorsize;
-               sectors[sector].size = mrvlqspi_info->dev->sectorsize;
+               sectors[sector].offset = sector * sectorsize;
+               sectors[sector].size = sectorsize;
                sectors[sector].is_erased = -1;
                sectors[sector].is_protected = 0;
        }