summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorpancake <pancake@dazo>2007-06-16 05:52:46 +0200
committerpancake <pancake@dazo>2007-06-16 05:52:46 +0200
commit3728cdea3130c62f3d766df040d2cb85f1e6caa4 (patch)
treee1e683eb758edf0638578c75195c04ec1d35e562 /src
parentc1d909c41587eb0f4b0581c5be9b70b2b72aefdb (diff)
download0xFFFF-3728cdea3130c62f3d766df040d2cb85f1e6caa4.tar.bz2
* Add new command 'nanddump' for the console shell
* Avoid dumping non-mtd files because writesize = 0 - Properly close the file when failing * Better doc/pieces documentation
Diffstat (limited to 'src')
-rw-r--r--src/console.c34
-rw-r--r--src/dump.c10
2 files changed, 42 insertions, 2 deletions
diff --git a/src/console.c b/src/console.c
index f0fbfb4..1f51053 100644
--- a/src/console.c
+++ b/src/console.c
@@ -33,11 +33,14 @@ void cmd_exit(char *line)
void cmd_help(char *line)
{
printf("connect connects via usb to nolo\n");
+ printf("reboot reboots remote host\n");
printf("info shows info of the remote system\n");
printf("linfo shows info of the local system\n");
printf("shell opens a shell (/bin/sh)\n");
printf("badblocks [dev] checks bad blocks on mtd (/dev/mtd1)\n");
printf("dump [dir] dumps the contents of /dev/mtd to dir\n");
+ printf("nanddump [dev] [start] [len] [out] [ignore-badblocks] [ignore-oob]\n");
+ printf(" f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
printf("exit exits the shell\n");
fflush(stdout);
}
@@ -51,6 +54,24 @@ void cmd_info(char *line)
get_rd_flags();
}
+void cmd_nanddump(char *line)
+{
+ char dev[128];
+ int from;
+ int length;
+ char out[128];
+ int ignbb;
+ int ignoob = -1;
+ sscanf(line, "%127s 0x%x 0x%x %127s %d %d", &dev, &from, &length, &out, &ignbb, &ignoob);
+ if (ignoob == -1) {
+ printf("Invalid arguments.\n");
+ printf("nanddump [dev] [start] [len] [out] [ignore-badblocks] [ignore-oob]\n");
+ printf(" f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
+ } else {
+ nanddump(dev, from, length, out, ignbb, ignoob);
+ }
+}
+
void cmd_dump(char *line)
{
if (!line[0]) {
@@ -76,12 +97,17 @@ void cmd_connect(char *line)
connect_via_usb();
}
+void cmd_reboot(char *line)
+{
+ reboot_board();
+}
+
void cmd_shell(char *line)
{
system("/bin/sh");
}
-#define CMDS 9
+#define CMDS 11
#define IS_CMD(x) !strcmp(console_commands[i].name, x)
#define CALL_CMD(x) console_commands[x].callback((char *)line)
#define FOREACH_CMD(x) for(x=0;x<CMDS;x++)
@@ -93,11 +119,13 @@ struct cmd_t {
{ .name = "exit", .callback = &cmd_exit },
{ .name = "q", .callback = &cmd_exit },
{ .name = "connect", .callback = &cmd_connect },
+ { .name = "reboot", .callback = &cmd_reboot },
{ .name = "badblocks", .callback = &cmd_badblocks},
{ .name = "help", .callback = &cmd_help },
{ .name = "?", .callback = &cmd_help },
{ .name = "info", .callback = &cmd_info },
{ .name = "dump", .callback = &cmd_dump },
+ { .name = "nanddump", .callback = &cmd_nanddump },
{ .name = "shell", .callback = &cmd_shell }
};
@@ -125,6 +153,10 @@ int console_prompt()
write(1, "0xFFFF> ", 8);
line[0] = '\0';
fgets(line, 1024, stdin);
+ if (feof(stdin)) {
+ write(1, "\n", 1);
+ break;
+ }
if (line[0]) line[strlen(line)-1] = '\0';
line[1023] = '\0';
} while(console_command(line));
diff --git a/src/dump.c b/src/dump.c
index af453a4..167d3c4 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -124,6 +124,9 @@ int mtd_open(char *file, mtd_info_t *meminfo, int *oobinfochanged,
int mtd_close(int fd, struct nand_oobinfo *old_oobinfo, int oobinfochanged)
{
+ if (fd == -1)
+ return 1;
+
/* reset oobinfo */
if (oobinfochanged == 1) {
if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
@@ -264,6 +267,12 @@ int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char
fd = mtd_open(mtddev, &meminfo, &oobinfochanged, &old_oobinfo, &eccstats, flags);
+ if (meminfo.writesize == 0) {
+ printf("What the fuck.. this is not an MTD device!\n");
+ close(fd);
+ return 1;
+ }
+
/* Read the real oob length */
oob.length = meminfo.oobsize;
fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
@@ -271,7 +280,6 @@ int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char
fprintf(stderr, "Size %u, flags %u, type 0x%x\n",
meminfo.size, meminfo.flags, (int)meminfo.type);
-
if (flags & M_OMITECC) { // (noecc)
switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) {
case -ENOTTY: