#include <stdlib.h>
#include <string.h>
+#include <inttypes.h>
#include <errno.h>
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);
u32 buf_cnt;
enum oob_formats oob_format = NAND_OOB_NONE;
- image_t image;
- int image_type_identified = 0;
+ fileio_t fileio;
duration_t duration;
char *duration_text;
u32 oob_size = 0;
duration_start_measure(&duration);
- strtoul(args[2], NULL, 0);
+ offset = strtoul(args[2], NULL, 0);
if (argc > 3)
{
oob_format |= NAND_OOB_RAW | NAND_OOB_ONLY;
else
{
- if (identify_image_type(&image.type, args[i]) == ERROR_OK)
- {
- image_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 (!image_type_identified)
- {
-
- identify_image_type(&image.type, NULL);
- image_type_identified = 1;
- }
-
- image.base_address_set = 1;
- image.base_address = strtoul(args[2], NULL, 0);
- image.start_address_set = 0;
-
- if (image_open(&image, args[1], FILEIO_READ) != ERROR_OK)
+ if (fileio_open(&fileio, args[1], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
{
- command_print(cmd_ctx, "flash write error: %s", image.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.base_address;
-
- buf_cnt = binary_size = image.size;
+ buf_cnt = binary_size = fileio.size;
if (!(oob_format & NAND_OOB_ONLY))
{
if (page)
{
- image_read(&image, page_size, page, &size_read);
+ fileio_read(&fileio, page_size, page, &size_read);
buf_cnt -= size_read;
if (size_read < page_size)
{
if (oob)
{
- image_read(&image, oob_size, oob, &size_read);
+ fileio_read(&fileio, oob_size, oob, &size_read);
buf_cnt -= size_read;
if (size_read < oob_size)
{
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",
- args[1], args[0], image.base_address, duration_text);
+ args[1], args[0], offset, duration_text);
free(duration_text);
}
else
fileio_close(&fileio);
duration_stop_measure(&duration, &duration_text);
- command_print(cmd_ctx, "dumped %lli byte in %s", fileio.size, duration_text);
+ command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
free(duration_text);
}
else