summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpancake <pancake@dazo>2007-04-25 21:05:03 +0200
committerpancake <pancake@dazo>2007-04-25 21:05:03 +0200
commit60f2337927efe4116a6675fccdf1021f51c86937 (patch)
tree8f793d5937d692bf8526590e0fc86af8b90f274b
parent196f1f7abbb896b84bbbb7a813e9d6641e162fc1 (diff)
download0xFFFF-60f2337927efe4116a6675fccdf1021f51c86937.tar.bz2
* import of the 'set-get-query_header' from Robert Schuster
1) name the simple functions get_foo and set_foo (and make them more consistent e.g. set_rd_mode and get_rd_mode). 2) moved remaining simple queries from main.c into query.c 3) created separate query.h header and included it in main.c 4) implemented get_usb_mode (they do not have this in the proprietary flasher) and added this function to a normal run (-> you will see the current USB mode when running with -i)
-rw-r--r--gui/DESCR53
-rw-r--r--src/main.c36
-rw-r--r--src/main.h15
-rw-r--r--src/query.c84
4 files changed, 121 insertions, 67 deletions
diff --git a/gui/DESCR b/gui/DESCR
new file mode 100644
index 0000000..eb446e3
--- /dev/null
+++ b/gui/DESCR
@@ -0,0 +1,53 @@
+- preferences
+
+ * choose flasher type.
+
+ by default 0xFFFF is used
+
+ *
+
+piece [file]
+ |
+ +-- radio
+ |
+ +-- nbh
+
+info
+ |
+ +-- -i
+
+reboot
+ |
+ +-- ???
+
+----------
+
+piece [file]
+ |
+ +-- xloader
+ |
+ +-- secondary
+ |
+ +-- kernel
+ |
+ +-- initfs
+ |
+ +-- rootfs
+ |
+ +-- autodetected
+
+info
+ |
+ +-- -i
+
+usb-host-mode
+ |
+ +-- -U [0|1]
+
+rd-mode
+ |
+ +-- -r 0|1
+
+reboot
+ |
+ +-- -R
diff --git a/src/main.c b/src/main.c
index a463c26..df1fe85 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,6 +19,8 @@
*/
#include "main.h"
+#include "query.h"
+
#include <usb.h>
#include <stdio.h>
#include <string.h>
@@ -176,26 +178,6 @@ void unpack_fiasco_image(char *file)
// TODO
}
-int query_sw_version()
-{
- int ret;
- char bytes[1024];
-
- strcpy(bytes, "version:sw-release");
- ret = usb_control_msg(dev, CMD_WRITE, 18, 0, 0, (char *)&bytes, 18, 2000);
- if (ret<0) {
- fprintf(stderr, "error: cannot write query 18\n");
- return 0;
- }
- ret = usb_control_msg(dev, CMD_QUERY, 20, 0, 0, (char *)&bytes, 512, 2000);
- if (ret<0) {
- fprintf(stderr, "error: b0rken swversion read!\n");
- return 0;
- }
- printf("SWVERSION GOT: %s\n", bytes); //???+strlen(bytes)+1));
- return 1;
-}
-
int main(int argc, char **argv)
{
struct usb_device_descriptor udd;
@@ -320,16 +302,18 @@ int main(int argc, char **argv)
// if (info)
sleep(1); // take breath
- query_root_device(); // only for flashing
- query_rdmode_device();
- query_hw_revision(); // get hardware revision:
+ get_root_device(); // only for flashing
+ get_rd_mode();
+ get_usb_mode();
+
+ get_hw_revision(); // get hardware revision:
if (pcs_n) {
int c;
check_nolo_order();
- query_sw_version();
- query_nolo_version();
+ get_sw_version();
+ get_nolo_version();
for(c=0;c<pcs_n;c++) {
printf("Flashing %s (%s)\n", pcs[c].type, pcs[c].name);
@@ -341,7 +325,7 @@ int main(int argc, char **argv)
set_root_device(root_device);
if (usb_mode!=-1)
- set_usb_host_mode(usb_mode);
+ set_usb_mode(usb_mode);
if (boot_cmdline)
boot_board(boot_cmdline);
diff --git a/src/main.h b/src/main.h
index 0155833..1417b24 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1,3 +1,4 @@
+
#ifndef _INCLUDE_MAIN_H_
#define _INCLUDE_MAIN_H_
@@ -11,21 +12,7 @@ void check_nolo_order();
extern struct usb_dev_handle *dev;
unsigned long get_file_size(char *file);
void progressbar(unsigned long long part, unsigned long long total);
-int get_status();
-int get_peripheral_host_mode(int foo);
-int boot_board(char *cmdline);
-int boot_board(char *cmdline);
-int reboot_board();
char *fpid_file(char *filename);
-int set_rd_mode(unsigned short mode);
-int set_usb_host_mode(unsigned short mode);
-int query_hw_revision();
-int query_rdmode_device();
-
-int query_root_device();
-int set_root_device(unsigned short);
-
-int query_nolo_version();
int add_piece(char *piece);
#define D if (verbose)
diff --git a/src/query.c b/src/query.c
index 073bf16..dda636c 100644
--- a/src/query.c
+++ b/src/query.c
@@ -36,26 +36,48 @@ int get_status()
return ret;
}
-int get_peripheral_host_mode(int foo)
+/**
+ * request type: CMD_WRITE
+ * request : 16
+ * value : 0|1 (=> client|host)
+ * index : 2
+ */
+int set_usb_mode(unsigned int mode)
+{
+ if (usb_control_msg(dev, CMD_WRITE, 16, mode, 2, 0, 0, 2000) == -1) {
+ fprintf(stderr, "Cannot set USB mode.\n");
+ return -1;
+ }
+
+ printf("Set USB mode to: '%s'.\n", (mode) ? "host" : "client");
+
+ return 0;
+}
+
+/**
+ * request type: CMD_QUERY
+ * request : 17
+ * index : 2
+ *
+ * return value: 0|1 (=> client|host)
+ */
+int get_usb_mode()
{
- //unsigned short mode = 0;
+ unsigned short mode = 0;
- // XXX BROKEN
-#if 0
- if (usb_control_msg(dev, 64, 16, 2, 0, 2, 0, 0, 2000)) {
+ if (usb_control_msg(dev, CMD_QUERY, 17, 0, 2, &mode, sizeof(mode), 2000) == -1) {
fprintf(stderr, "Cannot query device.\n");
return -1;
}
- printf("Device is in \"%s\" mode (%hd)\n", (mode)?"host":"peripheral", mode);
-#endif
+ printf("Device's USB mode is '%s'\n", (mode) ? "host" : "client");
return 0;
}
+
/*
- * boot the omap mobo
+ * Boots the Kernel with the given command-line.
*/
-
int boot_board(char *cmdline)
{
if (usb_control_msg(dev, CMD_WRITE, 130, 0, 0, cmdline, strlen(cmdline), 2000) == -1) {
@@ -70,7 +92,7 @@ int boot_board(char *cmdline)
}
/*
- * reboot the omap mobo
+ * Reboots the omap mobo.
*/
int reboot_board()
{
@@ -100,23 +122,10 @@ int set_rd_mode(unsigned short mode)
return 0;
}
-// mode = 1 || 0
-int set_usb_host_mode(unsigned short mode)
-{
- if (usb_control_msg(dev, CMD_WRITE, 16, mode, 2, 0, 0, 2000) == -1) {
- fprintf(stderr, "Cannot change the usb-host mode.\n");
- return -1;
- }
-
- printf("USB host mode is %s.\n", mode?"enabled":"disabled");
-
- return 0;
-}
-
/*
* query root device
*/
-int query_hw_revision()
+int get_hw_revision()
{
unsigned char string[512];
int i = 0;
@@ -140,7 +149,7 @@ int query_hw_revision()
return 0;
}
-int query_rdmode_device()
+int get_rd_mode()
{
char isrd = 1;
@@ -153,7 +162,7 @@ int query_rdmode_device()
return isrd;
}
-int query_root_device()
+int get_root_device()
{
unsigned char opcode;
@@ -194,7 +203,7 @@ int set_root_device(unsigned short root_device)
return 0;
}
-int query_nolo_version()
+int get_nolo_version()
{
unsigned int version; // ensure uint is at least 32 bits
@@ -214,3 +223,24 @@ int query_nolo_version()
return 0;
}
+
+int get_sw_version()
+{
+ int ret;
+ char bytes[1024];
+
+ strcpy(bytes, "version:sw-release");
+ ret = usb_control_msg(dev, CMD_WRITE, 18, 0, 0, (char *)&bytes, 18, 2000);
+ if (ret<0) {
+ fprintf(stderr, "error: cannot write query 18\n");
+ return 0;
+ }
+ ret = usb_control_msg(dev, CMD_QUERY, 20, 0, 0, (char *)&bytes, 512, 2000);
+ if (ret<0) {
+ fprintf(stderr, "error: b0rken swversion read!\n");
+ return 0;
+ }
+ printf("SWVERSION GOT: %s\n", bytes); //???+strlen(bytes)+1));
+ return 1;
+}
+