Add 'nand verify' command
authorZachary T Welch <zw@superlucidity.net>
Sun, 8 Nov 2009 05:20:45 +0000 (21:20 -0800)
committerZachary T Welch <zw@superlucidity.net>
Mon, 16 Nov 2009 09:38:19 +0000 (01:38 -0800)
Add the 'nand verify' command to perform a dump and fake-write
simultaneously, checking the read bits against those generated by the
write process.  Appropriate user documentation for this command has
been added to the user guide as well.

The algorithm presently makes a relatively naive comparison.  Some chips
that use ECC may not verify correctly using this implementation, but the
new documentation provides details about this limitation.

doc/openocd.texi
src/flash/nand.c

index bb96a2e63e2bcd0966c80a17ef474935417f2fb1..81409acce7a559f3fb985b74a0f43a5dd0cb0a95 100644 (file)
@@ -4620,6 +4620,32 @@ the underlying driver from applying hardware ECC.
 @end itemize
 @end deffn
 
+@deffn Command {nand verify} num filename offset [option...]
+@cindex NAND verification
+@cindex NAND programming
+Verify the binary data in the file has been programmed to the
+specified NAND device, starting at the specified offset.
+The @var{num} parameter is the value shown by @command{nand list}.
+
+Use a complete path name for @var{filename}, so you don't depend
+on the directory used to start the OpenOCD server.
+
+The @var{offset} must be an exact multiple of the device's page size.
+All data in the file will be read and compared to the contents of the
+flash, assuming it doesn't run past the end of the device.
+As with @command{nand write}, only full pages are verified, so any extra
+space in the last page will be filled with 0xff bytes.
+
+The same @var{options} accepted by @command{nand write},
+and the file will be processed similarly to produce the buffers that
+can be compared against the contents produced from @command{nand dump}.
+
+@b{NOTE:} This will not work when the underlying NAND controller
+driver's @code{write_page} routine must update the OOB with a
+hardward-computed ECC before the data is written.  This limitation may
+be removed in a future release.
+@end deffn
+
 @section Other NAND commands
 @cindex NAND other commands
 
index da561f63f2f7e21e678ec027435932a8725bc37d..46ac72867f5cb4f96c99fe6b7963473d5b435956 100644 (file)
@@ -1543,6 +1543,67 @@ COMMAND_HANDLER(handle_nand_write_command)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(handle_nand_verify_command)
+{
+       struct nand_device *nand = NULL;
+       struct nand_fileio_state file;
+       int retval = CALL_COMMAND_HANDLER(nand_fileio_parse_args,
+                       &file, &nand, FILEIO_READ, false, true);
+       if (ERROR_OK != retval)
+               return retval;
+
+       struct nand_fileio_state dev;
+       nand_fileio_init(&dev);
+       dev.address = file.address;
+       dev.size = file.size;
+       dev.oob_format = file.oob_format;
+       retval = nand_fileio_start(cmd_ctx, nand, NULL, FILEIO_NONE, &dev);
+       if (ERROR_OK != retval)
+               return retval;
+
+       while (file.size > 0)
+       {
+               int retval = nand_read_page(nand, dev.address / dev.page_size,
+                               dev.page, dev.page_size, dev.oob, dev.oob_size);
+               if (ERROR_OK != retval)
+               {
+                       command_print(cmd_ctx, "reading NAND flash page failed");
+                       nand_fileio_cleanup(&dev);
+                       return nand_fileio_cleanup(&file);
+               }
+
+               int bytes_read = nand_fileio_read(nand, &file);
+               if (bytes_read <= 0)
+               {
+                       command_print(cmd_ctx, "error while reading file");
+                       nand_fileio_cleanup(&dev);
+                       return nand_fileio_cleanup(&file);
+               }
+
+               if ((dev.page && memcmp(dev.page, file.page, dev.page_size)) ||
+                   (dev.oob && memcmp(dev.oob, file.oob, dev.oob_size)) )
+               {
+                       command_print(cmd_ctx, "NAND flash contents differ "
+                                               "at 0x%8.8" PRIx32, dev.address);
+                       nand_fileio_cleanup(&dev);
+                       return nand_fileio_cleanup(&file);
+               }
+
+               file.size -= bytes_read;
+               file.address += nand->page_size;
+       }
+
+       if (nand_fileio_finish(&file) == ERROR_OK)
+       {
+               command_print(cmd_ctx, "verified file %s in NAND flash %s "
+                               "up to offset 0x%8.8" PRIx32 " in %fs (%0.3f kb/s)",
+                               args[1], args[0], dev.address, duration_elapsed(&file.bench),
+                               duration_kbps(&file.bench, dev.size));
+       }
+
+       return nand_fileio_cleanup(&dev);
+}
+
 COMMAND_HANDLER(handle_nand_dump_command)
 {
        struct nand_device *nand = NULL;
@@ -1641,6 +1702,10 @@ int nand_init(struct command_context *cmd_ctx)
                        handle_nand_dump_command, COMMAND_EXEC,
                        "dump from NAND flash device <num> <filename> "
                         "<offset> <length> [oob_raw | oob_only]");
+       register_command(cmd_ctx, nand_cmd, "verify",
+                       &handle_nand_verify_command, COMMAND_EXEC,
+                       "verify NAND flash device <num> <filename> <offset> "
+                       "[oob_raw | oob_only | oob_softecc | oob_softecc_kw]");
        register_command(cmd_ctx, nand_cmd, "write",
                        handle_nand_write_command, COMMAND_EXEC,
                        "write to NAND flash device <num> <filename> <offset> "

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)