summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpancake <pancake@dazo>2007-06-10 05:41:50 +0200
committerpancake <pancake@dazo>2007-06-10 05:41:50 +0200
commitc46961d511ce87859e3bdd18ecf42ccd70ca525a (patch)
tree56b9117ff9a117baed25c2d1dd8fc3bc5280ad86
parentec71146727eb352c57e0ddb5b38858f4a7780c6b (diff)
download0xFFFF-c46961d511ce87859e3bdd18ecf42ccd70ca525a.tar.bz2
* Fix in fpid for proper JFFS2 identification
* Add new flag '-c' that makes 0xFFFF run as a shell * Split the connect_via_usb() code from main() * Add console handler for shell like usage of the flasher
-rw-r--r--src/Makefile2
-rw-r--r--src/console.c120
-rw-r--r--src/fpid.c3
-rw-r--r--src/main.c86
-rw-r--r--src/main.h5
5 files changed, 175 insertions, 41 deletions
diff --git a/src/Makefile b/src/Makefile
index 8f44893..7f635d7 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,6 +1,6 @@
VERSION=0.2
OBJ=main.o fiasco.o hexdump.o dump.o flash.o serial.o
-OBJ+=hash.o fpid.o query.o pieces.o utils.o devices.o
+OBJ+=hash.o fpid.o query.o pieces.o utils.o devices.o console.o
BIN=0xFFFF
CFLAGS+=-DVERSION=\"${VERSION}\" -Wall -g -I .
diff --git a/src/console.c b/src/console.c
new file mode 100644
index 0000000..977ffba
--- /dev/null
+++ b/src/console.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2007
+ * pancake <pancake@youterm.com>
+ *
+ * 0xFFFF is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 0xFFFF is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with 0xFFFF; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "main.h"
+#include "query.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+void cmd_exit(char *line)
+{
+ exit(0);
+}
+
+void cmd_help(char *line)
+{
+ printf("connect connects via usb to nolo\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("dump [dir] dumps the contents of /dev/mtd to dir\n");
+ printf("exit exits the shell\n");
+ fflush(stdout);
+}
+
+void cmd_info(char *line)
+{
+ get_hw_revision(); // get hardware revision:
+ get_root_device(); // only for flashing
+ get_usb_mode();
+ get_rd_mode();
+ get_rd_flags();
+}
+
+void cmd_dump(char *line)
+{
+ if (!line[0]) {
+ printf("Usage: dump [path]\n");
+ return;
+ }
+ reverse_extract_pieces(line);
+}
+
+void cmd_connect(char *line)
+{
+ connect_via_usb();
+}
+
+void cmd_shell(char *line)
+{
+ system("/bin/sh");
+}
+
+#define CMDS 8
+#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++)
+
+struct cmd_t {
+ char *name;
+ void (*callback)(char *);
+} console_commands[CMDS] = {
+ { .name = "exit", .callback = &cmd_exit },
+ { .name = "q", .callback = &cmd_exit },
+ { .name = "connect", .callback = &cmd_connect },
+ { .name = "help", .callback = &cmd_help },
+ { .name = "?", .callback = &cmd_help },
+ { .name = "info", .callback = &cmd_info },
+ { .name = "dump", .callback = &cmd_dump },
+ { .name = "shell", .callback = &cmd_shell }
+};
+
+static int console_command(const char *line)
+{
+ int i;
+ char command[11];
+
+ command[0] = '\0';
+ sscanf(line, "%10s", command);
+ line = line + strlen(command);
+
+ FOREACH_CMD(i)
+ if (IS_CMD(command))
+ CALL_CMD(i);
+ //
+ return 1;
+}
+
+int console_prompt()
+{
+ char line[1024];
+
+ do {
+ write(1, "0xFFFF> ", 8);
+ line[0] = '\0';
+ fgets(line, 1024, stdin);
+ if (line[0]) line[strlen(line)-1] = '\0';
+ line[1023] = '\0';
+ } while(console_command(line));
+
+ return 0;
+}
diff --git a/src/fpid.c b/src/fpid.c
index 93bf205..af2724d 100644
--- a/src/fpid.c
+++ b/src/fpid.c
@@ -64,7 +64,8 @@ char *fpid_file(char *filename)
if (!memcmp(b+0x00, "\x00\x00\xa0\xe1\x00\x00\xa0\xe1", 8))
return pieces[PIECE_KERNEL];
else
- if (!memcmp(b+0x00, "\x85\x19\x01\xe0", 4)) {
+ // JFFS2 MAGIC
+ if (!memcmp(b+0x00, "\x85\x19", 2)) { //\x01\xe0", 4)) {
/*/ is jffs2 */
if (size < 0x300000)
return pieces[PIECE_INITFS];
diff --git a/src/main.c b/src/main.c
index c90d502..86b52e2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -79,11 +79,12 @@ void show_usage()
printf(" -b [arg] boots the kernel with arguments\n");
printf(" -e [path] dump and extract pieces to path\n");
printf(" -r [0|1] disable/enable R&D mode\n");
- printf(" -f <flags> set the given RD flags (see '-f help' or 'Flasher_tool_usage' in maemo wiki)\n");
+ printf(" -f <flags> set the given RD flags (see '-f help')\n");
printf(" -p [[p%%]file] piece-of-firmware %% file-where-this-piece-is\n");
printf(" -u [fiasco] unpack target fiasco image\n");
printf(" -U [0|1] disable/enable the usb host mode\n");
printf(" -s [serial] serial port console (minicom like terminal)\n");
+ printf(" -c console prompt mode\n");
printf(" -h show this help message\n");
printf(" -i show device information (let standby mode)\n");
printf(" -I [piece] identify a firmware piece\n");
@@ -107,13 +108,53 @@ void unpack_fiasco_image(char *file)
// TODO
}
-int main(int argc, char **argv)
+int connect_via_usb()
{
+ int c=0;
struct usb_device_descriptor udd;
+ // usb_set_debug(5);
+ usb_init();
+
+ while(!usb_device_found(&udd)) {
+ char pbc[]={'/','-','\\', '|'};
+ usleep(0xc350); // 0.5s
+ printf("\rWaiting for device... %c", pbc[++c%4]);
+ fflush(stdout);
+ }
+
+ /*/ open device */
+ dev = usb_open(device);
+ if (dev == NULL) {
+ perror("usb_open");
+ return 1;
+ }
+ // TODO
+ if ( usb_claim_interface(dev, 2) < 0) { // 2 or 0
+ perror("usb_claim_interface");
+ return 1;
+ }
+
+ if (usb_set_altinterface(dev, 1) < 0) {
+ perror("usb_set_altinterface");
+ return 1;
+ }
+
+ /* go go go! */
+ while(get_status());
+
+ sleep(1); // take breath
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
int c;
- while((c = getopt(argc, argv, "p:vVhRu:ib:U:r:e:ld:I:D:f:s:")) != -1) {
+ while((c = getopt(argc, argv, "cp:vVhRu:ib:U:r:e:ld:I:D:f:s:")) != -1) {
switch(c) {
+ case 'c':
+ return console_prompt();
case 'd':
sscanf(optarg, "%04hx:%04hx",
&supported_devices[SUPPORTED_DEVICES-2].vendor_id,
@@ -197,7 +238,7 @@ int main(int argc, char **argv)
{
printf("Usage: 0xFFFF [-hvVRi] [-e path] [-U 0|1] [-p [piece%%]file [-p ...]]\n");
printf(" [-b boot-args] [-I piece [-I ...]] [-u fiasco-image]\n");
- printf(" [-D 0|1|2] [-F rd flags] [-s serial-dev]\n");
+ printf(" [-D 0|1|2] [-F rd flags] [-s serial-dev] [-c]\n");
return 1;
}
@@ -211,43 +252,10 @@ int main(int argc, char **argv)
return 0;
}
- // usb_set_debug(5);
- usb_init();
-
- while(!usb_device_found(&udd)) {
- char pbc[]={'/','-','\\', '|'};
- usleep(0xc350); // 0.5s
- printf("\rWaiting for device... %c", pbc[++c%4]);
- fflush(stdout);
- }
-
- /*/ open device */
- dev = usb_open(device);
- if (dev == NULL) {
- perror("usb_open");
- return 1;
- }
- // TODO
- if ( usb_claim_interface(dev, 2) < 0) { // 2 or 0
- perror("usb_claim_interface");
- return 1;
- }
-
- if (usb_set_altinterface(dev, 1) < 0) {
- perror("usb_set_altinterface");
- return 1;
- }
-
- /* go go go! */
- while(get_status());
+ connect_via_usb();
// if (info)
- sleep(1); // take breath
- get_hw_revision(); // get hardware revision:
- get_root_device(); // only for flashing
- get_usb_mode();
- get_rd_mode();
- get_rd_flags();
+ cmd_info("");
if (pcs_n) {
int c;
diff --git a/src/main.h b/src/main.h
index be9926e..fae655c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -24,6 +24,11 @@ int is_valid_device(struct usb_device_descriptor *udd);
void list_valid_devices();
int usb_device_found(struct usb_device_descriptor *udd);
int console(const char *device);
+int connect_via_usb();
+int console_prompt();
+
+//
+void cmd_info(char *line);
extern int verbose;
#define D if (verbose)