flash/nor: improved API of flash_driver.info & fixed buffer overruns
[openocd.git] / src / flash / nor / cc3220sf.c
index 244112467a0204efa8c77cfb88c446aa20a59305..1d01ba3be3aea4d56d243fa812d58078b912f54d 100644 (file)
@@ -106,7 +106,8 @@ FLASH_BANK_COMMAND_HANDLER(cc3220sf_flash_bank_command)
        return ERROR_OK;
 }
 
-static int cc3220sf_erase(struct flash_bank *bank, int first, int last)
+static int cc3220sf_erase(struct flash_bank *bank, unsigned int first,
+               unsigned int last)
 {
        struct target *target = bank->target;
        bool done;
@@ -129,7 +130,7 @@ static int cc3220sf_erase(struct flash_bank *bank, int first, int last)
        }
 
        /* Erase requested sectors one by one */
-       for (int i = first; i <= last; i++) {
+       for (unsigned int i = first; i <= last; i++) {
 
                /* Determine address of sector to erase */
                address = FLASH_BASE_ADDR + i * FLASH_SECTOR_SIZE;
@@ -363,6 +364,8 @@ static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer,
                        LOG_ERROR("cc3220sf: Flash operation failed");
                        break;
                }
+
+               keep_alive();
        }
 
        /* Do one word write for any final bytes less than a full word */
@@ -429,16 +432,13 @@ static int cc3220sf_probe(struct flash_bank *bank)
 
        uint32_t base;
        uint32_t size;
-       int num_sectors;
+       unsigned int num_sectors;
 
        base = FLASH_BASE_ADDR;
        size = FLASH_NUM_SECTORS * FLASH_SECTOR_SIZE;
        num_sectors = FLASH_NUM_SECTORS;
 
-       if (NULL != bank->sectors) {
-               free(bank->sectors);
-               bank->sectors = NULL;
-       }
+       free(bank->sectors);
 
        bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
        if (NULL == bank->sectors)
@@ -450,7 +450,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
        bank->write_end_alignment = 0;
        bank->num_sectors = num_sectors;
 
-       for (int i = 0; i < num_sectors; i++) {
+       for (unsigned int i = 0; i < num_sectors; i++) {
                bank->sectors[i].offset = i * FLASH_SECTOR_SIZE;
                bank->sectors[i].size = FLASH_SECTOR_SIZE;
                bank->sectors[i].is_erased = -1;
@@ -477,19 +477,13 @@ static int cc3220sf_auto_probe(struct flash_bank *bank)
        return retval;
 }
 
-static int cc3220sf_info(struct flash_bank *bank, char *buf, int buf_size)
+static int cc3220sf_info(struct flash_bank *bank, struct command_invocation *cmd)
 {
-       int printed;
-
-       printed = snprintf(buf, buf_size, "CC3220SF with 1MB internal flash\n");
-
-       if (printed >= buf_size)
-               return ERROR_BUF_TOO_SMALL;
-
+       command_print_sameline(cmd, "CC3220SF with 1MB internal flash\n");
        return ERROR_OK;
 }
 
-struct flash_driver cc3220sf_flash = {
+const struct flash_driver cc3220sf_flash = {
        .name = "cc3220sf",
        .flash_bank_command = cc3220sf_flash_bank_command,
        .erase = cc3220sf_erase,

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)