- rename flash_init and flash_erase to flash_init_drivers and flash_erase_address_ran...
[openocd.git] / src / flash / nand.c
index 221d2a4b7b5e2e014e00216ccb7f34f0dfe56d42..52c923287ea01b4e1389edaf8e7139a58112529d 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 
 #include <errno.h>
 
@@ -38,6 +39,7 @@
 #include "flash.h"
 #include "time_support.h"
 #include "fileio.h"
+#include "image.h"
 
 int nand_register_commands(struct command_context_s *cmd_ctx);
 int handle_nand_list_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
@@ -254,7 +256,7 @@ int handle_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, cha
 
 int nand_register_commands(struct command_context_s *cmd_ctx)
 {
-       nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, NULL);
+       nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, "NAND specific commands");
        
        register_command(cmd_ctx, nand_cmd, "device", handle_nand_device_command, COMMAND_CONFIG, NULL);
        
@@ -368,7 +370,6 @@ int nand_read_status(struct nand_device_s *device, u8 *status)
 int nand_probe(struct nand_device_s *device)
 {
        u8 manufacturer_id, device_id;
-       nand_manufacturer_t *manufacturer;
        int retval;
        int i;
 
@@ -419,8 +420,6 @@ int nand_probe(struct nand_device_s *device)
                device_id = data_buf & 0xff;
        }
                
-       device->manufacturer = manufacturer;
-       
        for (i = 0; nand_flash_ids[i].name; i++)
        {
                if (nand_flash_ids[i].id == device_id)
@@ -1139,7 +1138,6 @@ int handle_nand_check_bad_blocks_command(struct command_context_s *cmd_ctx, char
 int handle_nand_copy_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        nand_device_t *p;
-       int retval;
                
        if (argc != 4)
        {
@@ -1167,10 +1165,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
        u32 buf_cnt;
        enum oob_formats oob_format = NAND_OOB_NONE;
        
-       fileio_t file;
-       fileio_image_t image_info;
-       int sec_type_identified = 0;
-       enum fileio_sec_type sec_type;
+       fileio_t fileio;
        
        duration_t duration;
        char *duration_text;
@@ -1192,7 +1187,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                u32 oob_size = 0;
                        
                duration_start_measure(&duration);
-               strtoul(args[2], NULL, 0);
+               offset = strtoul(args[2], NULL, 0);
                
                if (argc > 3)
                {
@@ -1205,40 +1200,18 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                                        oob_format |= NAND_OOB_RAW | NAND_OOB_ONLY;
                                else
                                {
-                                       if (fileio_identify_image_type(&sec_type, args[i]) == ERROR_OK)
-                                       {
-                                               sec_type_identified = 1;
-                                       }
-                                       else
-                                       {
-                                               command_print(cmd_ctx, "unknown option: %s", args[i]);
-                                       }
+                                       command_print(cmd_ctx, "unknown option: %s", args[i]);
                                }
                        }
                }
                
-               /* if no image type option was encountered, set the default */
-               if (!sec_type_identified)
+               if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
                {
-                       
-                       fileio_identify_image_type(&sec_type, NULL);
-                       sec_type_identified = 1;
-               }
-
-               image_info.base_address = strtoul(args[2], NULL, 0);
-               image_info.has_start_address = 0;
-       
-               if (fileio_open(&file, args[1], FILEIO_READ, 
-                       FILEIO_IMAGE, &image_info, sec_type) != ERROR_OK)
-               {
-                       command_print(cmd_ctx, "flash write error: %s", file.error_str);
+                       command_print(cmd_ctx, "file open error: %s", fileio.error_str);
                        return ERROR_OK;
                }
        
-               /* the offset might have been overwritten by the image base address */
-               offset = image_info.base_address;
-               
-               buf_cnt = binary_size = file.size;
+               buf_cnt = binary_size = fileio.size;
                
                if (!(oob_format & NAND_OOB_ONLY))
                {
@@ -1267,7 +1240,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                        
                        if (page)
                        {
-                               fileio_read(&file, page_size, page, &size_read);
+                               fileio_read(&fileio, page_size, page, &size_read);
                                buf_cnt -= size_read;
                                if (size_read < page_size)
                                {
@@ -1277,7 +1250,7 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                                
                        if (oob)
                        {
-                               fileio_read(&file, oob_size, oob, &size_read);
+                               fileio_read(&fileio, oob_size, oob, &size_read);
                                buf_cnt -= size_read;
                                if (size_read < oob_size)
                                {
@@ -1288,15 +1261,17 @@ int handle_nand_write_command(struct command_context_s *cmd_ctx, char *cmd, char
                        if (nand_write_page(p, offset / p->page_size, page, page_size, oob, oob_size) != ERROR_OK)
                        {
                                command_print(cmd_ctx, "failed writing file %s to NAND flash %s at offset 0x%8.8x",
-                                       file.url, args[0], offset);
+                                       args[1], args[0], offset);
                                return ERROR_OK;
                        }
                        offset += page_size;
                }
 
+               fileio_close(&fileio);
+               
                duration_stop_measure(&duration, &duration_text);
                command_print(cmd_ctx, "wrote file %s to NAND flash %s at offset 0x%8.8x in %s",
-                       file.url, args[0], image_info.base_address, duration_text);
+                       args[1], args[0], offset, duration_text);
                free(duration_text);
        }
        else
@@ -1322,8 +1297,7 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
        {
                if (p->device)
                {
-                       fileio_t file;
-                       fileio_image_t image_info;
+                       fileio_t fileio;
                        duration_t duration;
                        char *duration_text;
                        int retval;
@@ -1371,14 +1345,10 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
                                        oob_size = 64;
                                oob = malloc(oob_size);
                        }
-
-                       image_info.base_address = address;
-                       image_info.has_start_address = 0;
                        
-                       if (fileio_open(&file, args[1], FILEIO_WRITE, 
-                               FILEIO_IMAGE, &image_info, FILEIO_PLAIN) != ERROR_OK)
+                       if (fileio_open(&fileio, args[1], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK)
                        {
-                               command_print(cmd_ctx, "dump_image error: %s", file.error_str);
+                               command_print(cmd_ctx, "dump_image error: %s", fileio.error_str);
                                return ERROR_OK;
                        }
        
@@ -1395,13 +1365,13 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
                                
                                if (page)
                                {
-                                       fileio_write(&file, page_size, page, &size_written);
+                                       fileio_write(&fileio, page_size, page, &size_written);
                                        bytes_done += page_size;
                                }
                                        
                                if (oob)
                                {
-                                       fileio_write(&file, oob_size, oob, &size_written);
+                                       fileio_write(&fileio, oob_size, oob, &size_written);
                                        bytes_done += oob_size;
                                }
                                        
@@ -1415,10 +1385,10 @@ int handle_nand_dump_command(struct command_context_s *cmd_ctx, char *cmd, char
                        if (oob)
                                free(oob);
                        
-                       fileio_close(&file);
+                       fileio_close(&fileio);
 
                        duration_stop_measure(&duration, &duration_text);
-                       command_print(cmd_ctx, "dumped %lli byte in %s", file.size, duration_text);
+                       command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
                        free(duration_text);
                }
                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)