flash/nor: check fill pattern fits in word size
[openocd.git] / src / flash / nor / tcl.c
index 0daa531b8f073868e60e4b931edac2b2c32981a2..40105b43f7f6fe337b643533f5f26a5e91ce6dea 100644 (file)
@@ -476,7 +476,7 @@ COMMAND_HANDLER(handle_flash_write_image_command)
 COMMAND_HANDLER(handle_flash_fill_command)
 {
        target_addr_t address;
-       uint32_t pattern;
+       uint64_t pattern;
        uint32_t count;
        struct target *target = get_current_target(CMD_CTX);
        unsigned i;
@@ -487,7 +487,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
-       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], pattern);
+       COMMAND_PARSE_NUMBER(u64, CMD_ARGV[1], pattern);
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count);
 
        struct flash_bank *bank;
@@ -496,6 +496,9 @@ COMMAND_HANDLER(handle_flash_fill_command)
                return retval;
 
        switch (CMD_NAME[4]) {
+               case 'd':
+                       wordsize = 8;
+                       break;
                case 'w':
                        wordsize = 4;
                        break;
@@ -509,6 +512,11 @@ COMMAND_HANDLER(handle_flash_fill_command)
                        return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
+       if ((wordsize < sizeof(pattern)) && (pattern >> (8 * wordsize) != 0)) {
+               command_print(CMD, "Fill pattern 0x%" PRIx64 " does not fit within %" PRIu32 "-byte word", pattern, wordsize);
+               return ERROR_FAIL;
+       }
+
        if (count == 0)
                return ERROR_OK;
 
@@ -541,6 +549,10 @@ COMMAND_HANDLER(handle_flash_fill_command)
        uint8_t *ptr = buffer + padding_at_start;
 
        switch (wordsize) {
+               case 8:
+                       for (i = 0; i < count; i++, ptr += wordsize)
+                               target_buffer_set_u64(target, ptr, pattern);
+                       break;
                case 4:
                        for (i = 0; i < count; i++, ptr += wordsize)
                                target_buffer_set_u32(target, ptr, pattern);
@@ -577,9 +589,12 @@ COMMAND_HANDLER(handle_flash_fill_command)
                goto done;
 
        for (i = 0, ptr = buffer; i < count; i++) {
-               uint32_t readback = 0;
+               uint64_t readback = 0;
 
                switch (wordsize) {
+                       case 8:
+                               readback = target_buffer_get_u64(target, ptr);
+                               break;
                        case 4:
                                readback = target_buffer_get_u32(target, ptr);
                                break;
@@ -593,7 +608,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
                if (readback != pattern) {
                        LOG_ERROR(
                                "Verification error address " TARGET_ADDR_FMT
-                               ", read back 0x%02" PRIx32 ", expected 0x%02" PRIx32,
+                               ", read back 0x%02" PRIx64 ", expected 0x%02" PRIx64,
                                address + i * wordsize, readback, pattern);
                        retval = ERROR_FAIL;
                        goto done;
@@ -985,7 +1000,7 @@ static const struct command_registration flash_exec_command_handlers[] = {
                .name = "erase_sector",
                .handler = handle_flash_erase_command,
                .mode = COMMAND_EXEC,
-               .usage = "bank_id first_sector_num last_sector_num",
+               .usage = "bank_id first_sector_num (last_sector_num|'last')",
                .help = "Erase a range of sectors in a flash bank.",
        },
        {
@@ -1002,6 +1017,14 @@ static const struct command_registration flash_exec_command_handlers[] = {
                        "before erasing.",
 
        },
+       {
+               .name = "filld",
+               .handler = handle_flash_fill_command,
+               .mode = COMMAND_EXEC,
+               .usage = "address value n",
+               .help = "Fill n double-words with 64-bit value, starting at "
+                       "word address.  (No autoerase.)",
+       },
        {
                .name = "fillw",
                .handler = handle_flash_fill_command,
@@ -1167,7 +1190,7 @@ COMMAND_HANDLER(handle_flash_banks_command)
 
        unsigned n = 0;
        for (struct flash_bank *p = flash_bank_list(); p; p = p->next, n++) {
-               LOG_USER("#%d : %s (%s) at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", "
+               command_print(CMD, "#%d : %s (%s) at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", "
                        "buswidth %u, chipwidth %u", p->bank_number,
                        p->name, p->driver->name, p->base, p->size,
                        p->bus_width, p->chip_width);

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)