SPI table updates (some new devices and new info)
[openocd.git] / src / flash / nor / tcl.c
index 34681db146af746d17121252e5ecd04a57a0387a..f056e07538eb8db3fb52a9c4ee79e770fa4ef604 100644 (file)
@@ -98,10 +98,18 @@ COMMAND_HANDLER(handle_flash_info_command)
                if (retval != ERROR_OK)
                        return retval;
 
-               /* We must query the hardware to avoid printing stale information! */
-               retval = p->driver->protect_check(p);
-               if (retval != ERROR_OK)
-                       return retval;
+               /* If the driver does not implement protection, we show the default
+                * state of is_protected array - usually protection state unknown */
+               if (p->driver->protect_check == NULL) {
+                       retval = ERROR_FLASH_OPER_UNSUPPORTED;
+               } else {
+                       /* We must query the hardware to avoid printing stale information! */
+                       retval = p->driver->protect_check(p);
+                       if (retval != ERROR_OK && retval != ERROR_FLASH_OPER_UNSUPPORTED)
+                               return retval;
+               }
+               if (retval == ERROR_FLASH_OPER_UNSUPPORTED)
+                       LOG_WARNING("Flash protection check is not implemented.");
 
                command_print(CMD_CTX,
                        "#%d : %s at 0x%8.8" PRIx32 ", size 0x%8.8" PRIx32
@@ -288,24 +296,6 @@ COMMAND_HANDLER(handle_flash_erase_address_command)
        return retval;
 }
 
-static int flash_check_sector_parameters(struct command_context *cmd_ctx,
-       uint32_t first, uint32_t last, uint32_t num_sectors)
-{
-       if (!(first <= last)) {
-               command_print(cmd_ctx, "ERROR: "
-                       "first sector must be <= last sector");
-               return ERROR_FAIL;
-       }
-
-       if (!(last <= (num_sectors - 1))) {
-               command_print(cmd_ctx, "ERROR: last sector must be <= %" PRIu32,
-                       num_sectors - 1);
-               return ERROR_FAIL;
-       }
-
-       return ERROR_OK;
-}
-
 COMMAND_HANDLER(handle_flash_erase_command)
 {
        if (CMD_ARGC != 3)
@@ -327,9 +317,18 @@ COMMAND_HANDLER(handle_flash_erase_command)
        else
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], last);
 
-       retval = flash_check_sector_parameters(CMD_CTX, first, last, p->num_sectors);
-       if (retval != ERROR_OK)
-               return retval;
+       if (!(first <= last)) {
+               command_print(CMD_CTX, "ERROR: "
+                       "first sector must be <= last");
+               return ERROR_FAIL;
+       }
+
+       if (!(last <= (uint32_t)(p->num_sectors - 1))) {
+               command_print(CMD_CTX, "ERROR: "
+                       "last sector must be <= %" PRIu32,
+                       p->num_sectors - 1);
+               return ERROR_FAIL;
+       }
 
        struct duration bench;
        duration_start(&bench);
@@ -375,15 +374,28 @@ COMMAND_HANDLER(handle_flash_protect_command)
        bool set;
        COMMAND_PARSE_ON_OFF(CMD_ARGV[3], set);
 
-       retval = flash_check_sector_parameters(CMD_CTX, first, last, num_blocks);
-       if (retval != ERROR_OK)
-               return retval;
+       if (!(first <= last)) {
+               command_print(CMD_CTX, "ERROR: "
+                       "first %s must be <= last",
+                       (p->num_prot_blocks) ? "block" : "sector");
+               return ERROR_FAIL;
+       }
+
+       if (!(last <= (uint32_t)(num_blocks - 1))) {
+               command_print(CMD_CTX, "ERROR: "
+                       "last %s must be <= %" PRIu32,
+                       (p->num_prot_blocks) ? "block" : "sector",
+                       num_blocks - 1);
+               return ERROR_FAIL;
+       }
 
        retval = flash_driver_protect(p, set, first, last);
        if (retval == ERROR_OK) {
-               command_print(CMD_CTX, "%s protection for sectors %" PRIu32
+               command_print(CMD_CTX, "%s protection for %s %" PRIu32
                        " through %" PRIu32 " on flash bank %d",
-                       (set) ? "set" : "cleared", first, last, p->bank_number);
+                       (set) ? "set" : "cleared",
+                       (p->num_prot_blocks) ? "blocks" : "sectors",
+                       first, last, p->bank_number);
        }
 
        return retval;
@@ -502,7 +514,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
        if (count == 0)
                return ERROR_OK;
 
-       if (address + count >= bank->base + bank->size) {
+       if (address + count * wordsize > bank->base + bank->size) {
                LOG_ERROR("Cannot cross flash bank borders");
                return ERROR_FAIL;
        }

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)