coding style: avoid unnecessary line continuations
[openocd.git] / src / flash / nor / mrvlqspi.c
index 21fc91b25213d26f4ea6807a1adeeb0946437194..7a06b3d09d6755192acd312cc2e9737fb8931d44 100644 (file)
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
- *                                                                         *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
  /*
@@ -506,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)
@@ -563,7 +563,7 @@ static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
        if (first == 0 && last == (bank->num_sectors - 1)
                && mrvlqspi_info->dev->chip_erase_cmd !=
                                        mrvlqspi_info->dev->erase_cmd) {
-               LOG_DEBUG("Chip supports the bulk erase command."\
+               LOG_DEBUG("Chip supports the bulk erase command."
                " Will use bulk erase instead of sector-by-sector erase.");
                retval = mrvlqspi_bulk_erase(bank);
                if (retval == ERROR_OK) {
@@ -573,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);
@@ -622,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[] = {
@@ -676,7 +681,7 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
 
        if (target_alloc_working_area(target, sizeof(mrvlqspi_flash_write_code),
                        &write_algorithm) != ERROR_OK) {
-               LOG_ERROR("Insufficient working area. You must configure"\
+               LOG_ERROR("Insufficient working area. You must configure"
                        " a working area > %zdB in order to write to SPIFI flash.",
                        sizeof(mrvlqspi_flash_write_code));
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
@@ -698,15 +703,15 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
                 * space, free the algorithm */
                target_free_working_area(target, write_algorithm);
 
-               LOG_ERROR("Insufficient working area. Please allocate at least"\
+               LOG_ERROR("Insufficient working area. Please allocate at least"
                        " %zdB of working area to enable flash writes.",
                        sizeof(mrvlqspi_flash_write_code) + 1
                );
 
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        } else if (fifo_size < page_size)
-               LOG_WARNING("Working area size is limited; flash writes may be"\
-                       " slow. Increase working area size to at least %zdB"\
+               LOG_WARNING("Working area size is limited; flash writes may be"
+                       " slow. Increase working area size to at least %zdB"
                        " to reduce write times.",
                        (size_t)(sizeof(mrvlqspi_flash_write_code) + page_size)
                );
@@ -829,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)
@@ -862,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");
@@ -875,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;
        }
@@ -902,12 +915,6 @@ static int mrvlqspi_flash_erase_check(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int mrvlqspi_protect_check(struct flash_bank *bank)
-{
-       /* Not implemented yet */
-       return ERROR_OK;
-}
-
 int mrvlqspi_get_info(struct flash_bank *bank, char *buf, int buf_size)
 {
        struct mrvlqspi_flash_bank *mrvlqspi_info = bank->driver_priv;
@@ -946,16 +953,15 @@ FLASH_BANK_COMMAND_HANDLER(mrvlqspi_flash_bank_command)
        return ERROR_OK;
 }
 
-struct flash_driver mrvlqspi_flash = {
+const struct flash_driver mrvlqspi_flash = {
        .name = "mrvlqspi",
        .flash_bank_command = mrvlqspi_flash_bank_command,
        .erase = mrvlqspi_flash_erase,
-       .protect = NULL,
        .write = mrvlqspi_flash_write,
        .read = mrvlqspi_flash_read,
        .probe = mrvlqspi_probe,
        .auto_probe = mrvlqspi_auto_probe,
        .erase_check = mrvlqspi_flash_erase_check,
-       .protect_check = mrvlqspi_protect_check,
        .info = mrvlqspi_get_info,
+       .free_driver_priv = default_flash_free_driver_priv,
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)