flash/nor/nrf5: remove is_erased setting and autoerase before write
[openocd.git] / src / flash / nor / nrf5.c
index 31dd5aae5f2701d804f758ea6a6237004aec0f25..a7ae6f3b79707d1997d01ed923aed4cd7ca6490f 100644 (file)
@@ -531,7 +531,6 @@ static int nrf5_probe(struct flash_bank *bank)
                bank->sectors[0].size = bank->size;
                bank->sectors[0].offset = 0;
 
                bank->sectors[0].size = bank->size;
                bank->sectors[0].offset = 0;
 
-               /* mark as unknown */
                bank->sectors[0].is_erased = 0;
                bank->sectors[0].is_protected = 0;
 
                bank->sectors[0].is_erased = 0;
                bank->sectors[0].is_protected = 0;
 
@@ -553,17 +552,6 @@ static int nrf5_auto_probe(struct flash_bank *bank)
                return nrf5_probe(bank);
 }
 
                return nrf5_probe(bank);
 }
 
-static struct flash_sector *nrf5_find_sector_by_address(struct flash_bank *bank, uint32_t address)
-{
-       struct nrf5_info *chip = bank->driver_priv;
-
-       for (int i = 0; i < bank->num_sectors; i++)
-               if (bank->sectors[i].offset <= address &&
-                   address < (bank->sectors[i].offset + chip->code_page_size))
-                       return &bank->sectors[i];
-       return NULL;
-}
-
 static int nrf5_erase_all(struct nrf5_info *chip)
 {
        LOG_DEBUG("Erasing all non-volatile memory");
 static int nrf5_erase_all(struct nrf5_info *chip)
 {
        LOG_DEBUG("Erasing all non-volatile memory");
@@ -615,9 +603,6 @@ static int nrf5_erase_page(struct flash_bank *bank,
                                               sector->offset);
        }
 
                                               sector->offset);
        }
 
-       if (res == ERROR_OK)
-               sector->is_erased = 1;
-
        return res;
 }
 
        return res;
 }
 
@@ -743,48 +728,22 @@ static int nrf5_write_pages(struct flash_bank *bank, uint32_t start, uint32_t en
 {
        int res = ERROR_FAIL;
        struct nrf5_info *chip = bank->driver_priv;
 {
        int res = ERROR_FAIL;
        struct nrf5_info *chip = bank->driver_priv;
-       struct flash_sector *sector;
-       uint32_t offset;
 
        assert(start % chip->code_page_size == 0);
        assert(end % chip->code_page_size == 0);
 
 
        assert(start % chip->code_page_size == 0);
        assert(end % chip->code_page_size == 0);
 
-       /* Erase all sectors */
-       for (offset = start; offset < end; offset += chip->code_page_size) {
-               sector = nrf5_find_sector_by_address(bank, offset);
-               if (!sector) {
-                       LOG_ERROR("Invalid sector @ 0x%08"PRIx32, offset);
-                       return ERROR_FLASH_SECTOR_INVALID;
-               }
-
-               if (sector->is_protected) {
-                       LOG_ERROR("Can't erase protected sector @ 0x%08"PRIx32, offset);
-                       goto error;
-               }
-
-               if (sector->is_erased != 1) {   /* 1 = erased, 0= not erased, -1 = unknown */
-                       res = nrf5_erase_page(bank, chip, sector);
-                       if (res != ERROR_OK) {
-                               LOG_ERROR("Failed to erase sector @ 0x%08"PRIx32, sector->offset);
-                               goto error;
-                       }
-               }
-               sector->is_erased = 0;
-       }
-
        res = nrf5_nvmc_write_enable(chip);
        if (res != ERROR_OK)
                goto error;
 
        res = nrf5_ll_flash_write(chip, start, buffer, (end - start));
        if (res != ERROR_OK)
        res = nrf5_nvmc_write_enable(chip);
        if (res != ERROR_OK)
                goto error;
 
        res = nrf5_ll_flash_write(chip, start, buffer, (end - start));
        if (res != ERROR_OK)
-               goto set_read_only;
+               goto error;
 
        return nrf5_nvmc_read_only(chip);
 
 
        return nrf5_nvmc_read_only(chip);
 
-set_read_only:
-       nrf5_nvmc_read_only(chip);
 error:
 error:
+       nrf5_nvmc_read_only(chip);
        LOG_ERROR("Failed to write to nrf5 flash");
        return res;
 }
        LOG_ERROR("Failed to write to nrf5 flash");
        return res;
 }
@@ -876,11 +835,9 @@ static int nrf5_uicr_flash_write(struct flash_bank *bank,
        if (res != ERROR_OK)
                return res;
 
        if (res != ERROR_OK)
                return res;
 
-       if (sector->is_erased != 1) {
-               res = nrf5_erase_page(bank, chip, sector);
-               if (res != ERROR_OK)
-                       return res;
-       }
+       res = nrf5_erase_page(bank, chip, sector);
+       if (res != ERROR_OK)
+               return res;
 
        res = nrf5_nvmc_write_enable(chip);
        if (res != ERROR_OK)
 
        res = nrf5_nvmc_write_enable(chip);
        if (res != ERROR_OK)
@@ -992,9 +949,6 @@ COMMAND_HANDLER(nrf5_handle_mass_erase_command)
                return res;
        }
 
                return res;
        }
 
-       for (int i = 0; i < bank->num_sectors; i++)
-               bank->sectors[i].is_erased = 1;
-
        res = nrf5_protect_check(bank);
        if (res != ERROR_OK) {
                LOG_ERROR("Failed to check chip's write protection");
        res = nrf5_protect_check(bank);
        if (res != ERROR_OK) {
                LOG_ERROR("Failed to check chip's write protection");
@@ -1005,8 +959,6 @@ COMMAND_HANDLER(nrf5_handle_mass_erase_command)
        if (res != ERROR_OK)
                return res;
 
        if (res != ERROR_OK)
                return res;
 
-       bank->sectors[0].is_erased = 1;
-
        return ERROR_OK;
 }
 
        return ERROR_OK;
 }
 

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)