ocd_flash_banks now returns empty list when no flash banks are configured instead...
[openocd.git] / src / flash / nand.c
index 4d355cf18b55365923bd52b2d67526f0eccbacae..f55a81bb657b5ec1389dc5b0b96a5db5897a07f3 100644 (file)
@@ -204,10 +204,10 @@ int handle_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, cha
                if (strcmp(args[0], nand_flash_controllers[i]->name) == 0)
                {
                        /* register flash specific commands */
-                       if (nand_flash_controllers[i]->register_commands(cmd_ctx) != ERROR_OK)
+                       if ((retval = nand_flash_controllers[i]->register_commands(cmd_ctx)) != ERROR_OK)
                        {
                                LOG_ERROR("couldn't register '%s' commands", args[0]);
-                               exit(-1);
+                               return retval;
                        }
        
                        c = malloc(sizeof(nand_device_t));
@@ -355,7 +355,7 @@ int nand_read_status(struct nand_device_s *device, u8 *status)
        /* Send read status command */
        device->controller->command(device, NAND_CMD_STATUS);
        
-       usleep(1000);
+       alive_sleep(1);
        
        /* read status */
        if (device->device->options & NAND_BUSWIDTH_16)
@@ -806,7 +806,10 @@ int nand_read_page_raw(struct nand_device_s *device, u32 page, u8 *data, u32 dat
                 * or 2048 for the beginning of OOB area)
                 */
                device->controller->address(device, 0x0);
-               device->controller->address(device, 0x8);
+               if (data)
+                       device->controller->address(device, 0x0);
+               else
+                       device->controller->address(device, 0x8);
                
                /* row */
                device->controller->address(device, page & 0xff);
@@ -1292,6 +1295,9 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                if (offset % p->page_size)
                {
                        command_print(cmd_ctx, "only page size aligned offsets and sizes are supported");
+                       fileio_close(&fileio);
+                       free(oob);
+                       free(page);
                        return ERROR_OK;
                }
                
@@ -1299,7 +1305,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                {
                        u32 size_read;
                        
-                       if (page)
+                       if (NULL != page)
                        {
                                fileio_read(&fileio, page_size, page, &size_read);
                                buf_cnt -= size_read;
@@ -1309,7 +1315,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                                }
                        }
                                
-                       if (oob)
+                       if (NULL != oob)
                        {
                                fileio_read(&fileio, oob_size, oob, &size_read);
                                buf_cnt -= size_read;
@@ -1323,17 +1329,26 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                        {
                                command_print(cmd_ctx, "failed writing file %s to NAND flash %s at offset 0x%8.8x",
                                        args[1], args[0], offset);
+
+                               fileio_close(&fileio);
+                               free(oob);
+                               free(page);
+
                                return ERROR_OK;
                        }
                        offset += page_size;
                }
 
                fileio_close(&fileio);
-               
+               free(oob);
+               free(page);
+               oob = NULL;
+               page = NULL;
                duration_stop_measure(&duration, &duration_text);
                command_print(cmd_ctx, "wrote file %s to NAND flash %s at offset 0x%8.8x in %s",
                        args[1], args[0], offset, duration_text);
                free(duration_text);
+               duration_text = NULL;
        }
        else
        {
@@ -1419,16 +1434,19 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
                                if ((retval = nand_read_page(p, address / p->page_size, page, page_size, oob, oob_size)) != ERROR_OK)
                                {
                                        command_print(cmd_ctx, "reading NAND flash page failed");
+                                       free(page);
+                                       free(oob);                                                              
+                                       fileio_close(&fileio);
                                        return ERROR_OK;
                                }
                                
-                               if (page)
+                               if (NULL != page)
                                {
                                        fileio_write(&fileio, page_size, page, &size_written);
                                        bytes_done += page_size;
                                }
                                        
-                               if (oob)
+                               if (NULL != oob)
                                {
                                        fileio_write(&fileio, oob_size, oob, &size_written);
                                        bytes_done += oob_size;
@@ -1438,17 +1456,16 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
                                address += p->page_size;
                        }
                        
-                       if (page)
-                               free(page);
-                               
-                       if (oob)
-                               free(oob);
-                       
+                       free(page);
+                       page = NULL;
+                       free(oob);
+                       oob = NULL;
                        fileio_close(&fileio);
 
                        duration_stop_measure(&duration, &duration_text);
                        command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
                        free(duration_text);
+                       duration_text = NULL;
                }
                else
                {

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)