summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
Diffstat (limited to 'avr')
-rw-r--r--avr/cmd_fat.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c
index 18784e0..8c8a308 100644
--- a/avr/cmd_fat.c
+++ b/avr/cmd_fat.c
@@ -804,6 +804,53 @@ command_ret_t do_rw(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
return CMD_RET_SUCCESS;
}
+command_ret_t do_dump(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+{
+ FIL File;
+ FRESULT res;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ bool hexdump = argv[0][0] == 'x';
+
+ uint8_t *buffer = (uint8_t *) malloc(BUFFER_SIZE);
+ if (buffer == NULL)
+ cmd_error(CMD_RET_FAILURE, ENOMEM, NULL);
+
+ res = f_open(&File, argv[1], FA_READ );
+
+ if (res == FR_OK) {
+ uint32_t filepos = 0;
+ uint8_t ch = '\n';
+ for (;;) {
+ unsigned int br;
+
+ res = f_read(&File, buffer, BUFFER_SIZE, &br);
+ if (br == 0) break;
+ /* Print the lines. */
+ if (hexdump)
+ dump_ram(buffer, filepos, br, NULL);
+ else {
+ for (unsigned int i = 0; i < br; ++i) {
+ putchar(ch = buffer[i]);
+ }
+ }
+ filepos += br;
+ }
+ if (!hexdump && (ch != '\n'))
+ putchar('\n');
+ }
+
+ f_close(&File);
+ free(buffer);
+
+ if (res)
+ cmd_error(CMD_RET_FAILURE, res, PSTR("'%s'"), argv[1]);
+
+ return CMD_RET_SUCCESS;
+}
+
/*
* command table for fat subcommands
*/
@@ -912,6 +959,16 @@ CMD_TBL_ITEM(
" - Write file to 'path/filename' on logical drive 'd' from RAM\n"
" starting at address 'addr'.\n"
),
+CMD_TBL_ITEM(
+ xxd, 2, 1|CTBL_SUBCMDAUTO, do_dump,
+ "print file as hexdump",
+ "<d:/path/filename>\n"
+),
+CMD_TBL_ITEM(
+ type, 2, 1|CTBL_SUBCMDAUTO, do_dump,
+ "print file",
+ "<d:/path/filename>\n"
+),
CMD_TBL_ITEM(
help, CONFIG_SYS_MAXARGS, CTBL_RPT, do_help,