summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpancake <pancake@dazo>2007-06-14 23:32:52 +0200
committerpancake <pancake@dazo>2007-06-14 23:32:52 +0200
commit579dbe983733df293b620143d3a18f9bbcabcec7 (patch)
tree48247979a87975d8778f7cc715683547b72d71b1
parented3cb1d3f8f21a067b30a9d6695515a791895c74 (diff)
download0xFFFF-579dbe983733df293b620143d3a18f9bbcabcec7.tar.bz2
* Fix device identification for n800. patch from Robert Schuster
- Looks like n770 and n800 have different USB identifiers on the bootloader and the operating system. * Print oops message and exit when the use has no permissions to access to the usb.
-rw-r--r--src/devices.c41
-rw-r--r--src/main.c83
-rw-r--r--src/main.h7
3 files changed, 92 insertions, 39 deletions
diff --git a/src/devices.c b/src/devices.c
index 538dc9e..0739905 100644
--- a/src/devices.c
+++ b/src/devices.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
struct devices supported_devices[SUPPORTED_DEVICES] = {
+ { "FFFF", 0x000, 0x0000, 0x0000 }, // dummy
{ "unkn", 0x421, 0x3f00, 0x0000 }, // probably a development board
{ "n770", 0x421, 0x0105, 0x0001 }, // my n770
{ "n800", 0x421, 0x04c3, 0x0001 }, // a n800
@@ -31,17 +32,22 @@ struct devices supported_devices[SUPPORTED_DEVICES] = {
{ 0 }
};
+/** Returns 0 when no device was found and a positive
+ * non-zero value when one was found.
+ *
+ * The return value is the index into the supported_devices
+ * array which denotes the device which was found.
+ */
int is_valid_device(struct usb_device_descriptor *udd)
{
int i;
- struct devices ptr = supported_devices[0];
+ struct devices ptr = supported_devices[1];
- for(i=0 ; ptr.vendor_id; ptr = supported_devices[++i])
+ for(i=1 ; ptr.vendor_id; ptr = supported_devices[++i])
if ((udd->idVendor == ptr.vendor_id)
&& (udd->idProduct == ptr.product_id)) {
- printf("found %s (%04x:%04x)\n",
- ptr.name, ptr.vendor_id, ptr.product_id);
- return 1;
+ D printf("found %s\n", supported_devices[i]);
+ return i;
}
return 0;
@@ -50,23 +56,29 @@ int is_valid_device(struct usb_device_descriptor *udd)
void list_valid_devices()
{
int i;
- struct devices ptr = supported_devices[0];
+ struct devices ptr = supported_devices[1];
- for(i=0; ptr.vendor_id; ptr = supported_devices[++i])
+ for(i=1; ptr.vendor_id; ptr = supported_devices[++i])
printf("%04x:%04x %s\n", ptr.vendor_id, ptr.product_id, ptr.name);
}
-int usb_device_found(struct usb_device_descriptor *udd)
+int usb_device_found(struct usb_device_descriptor *udd, struct devices *it_device)
{
+ struct usb_bus *bus;
+ int dev_index = 0;
+
if (usb_find_busses() < 0) {
- fprintf(stderr, "error: no usb busses found.\n");
+ fprintf(stderr, "\nerror: no usb busses found.\n");
exit(1);
} else {
- if (usb_find_devices() < 0) {
- fprintf(stderr, "error: no devices found.\n");
+ switch(usb_find_devices()) {
+ case -1:
+ fprintf(stderr, "\nerror: no devices found.\n");
+ exit(1);
+ case 0:
+ fprintf(stderr, "\noops: no permission to usb. got root?\n");
exit(1);
- } else {
- struct usb_bus *bus;
+ default:
for (bus = usb_busses; bus; bus = bus->next) {
struct usb_device *dev = bus->devices;
D printf("bus: \n");
@@ -75,8 +87,9 @@ int usb_device_found(struct usb_device_descriptor *udd)
D printf(" dev (%s) - ", dev->filename);
D printf("vendor: %04x product: %04x\n", udd->idVendor, udd->idProduct);
- if (is_valid_device(udd)) {
+ if ((dev_index = is_valid_device(udd))) {
device = dev;
+ *it_device = supported_devices[dev_index];
return 1;
}
}
diff --git a/src/main.c b/src/main.c
index 4c66917..fd1e17e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -112,34 +112,68 @@ void unpack_fiasco_image(char *file)
int connect_via_usb()
{
- int c=0;
- struct usb_device_descriptor udd;
+ struct usb_device_descriptor udd;
+ struct devices it_device;
+ int c = 0;
+ static char pbc[]={'/','-','\\', '|'};
+
// usb_set_debug(5);
usb_init();
- while(!usb_device_found(&udd)) {
- char pbc[]={'/','-','\\', '|'};
+ /* Tries to get access to the Internet Tablet and retries
+ * if any of the neccessary steps fail.
+ *
+ * Note: While a proper device may be found on the bus it may
+ * not be in the right state to be accessed (e.g. the Nokia is
+ * not in the boot stage any more).
+ */
+ while(!dev) {
usleep(0xc350); // 0.5s
- printf("\rWaiting for device... %c", pbc[++c%4]);
- fflush(stdout);
- }
+
+ if(!usb_device_found(&udd, &it_device)) {
+ printf("\rWaiting for device... %c", pbc[++c%4]);
+ fflush(stdout);
+ continue;
+ }
- /*/ 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;
- }
+ /* open device */
+ if(!(dev = usb_open(device))) {
+ perror("usb_open");
+ return 1;
+ }
- if (usb_set_altinterface(dev, 1) < 0) {
- perror("usb_set_altinterface");
- return 1;
- }
+ if ( usb_claim_interface(dev, 2) < 0) { // 2 or 0
+ D perror("usb_claim_interface");
+
+ // Something is broken if closing fails.
+ if(usb_close(dev)) {
+ perror("usb_close");
+ return 1;
+ }
+
+ dev = NULL;
+
+ // Try again later.
+ continue;
+ }
+
+ if (usb_set_altinterface(dev, 1) < 0) {
+ D perror("usb_set_altinterface");
+
+ // Something is broken if closing fails.
+ if(usb_close(dev)) {
+ perror("usb_close");
+ return 1;
+ }
+
+ dev = NULL;
+ // Try again later.
+ continue;
+ }
+ }
+
+ printf("found %s (%04x:%04x)\n", it_device.name,
+ it_device.vendor_id, it_device.product_id);
/* go go go! */
while(get_status());
@@ -258,7 +292,10 @@ int main(int argc, char **argv)
return 0;
}
- connect_via_usb();
+ if (connect_via_usb()) {
+ fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n");
+ return 0;
+ }
// if (info)
cmd_info("");
diff --git a/src/main.h b/src/main.h
index 7895c5c..dcbacff 100644
--- a/src/main.h
+++ b/src/main.h
@@ -5,6 +5,8 @@
#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
+// Forward declaration for use in function arguments.
+struct devices;
int reverse_extract_pieces(char *dir);
void flash_image(char *filename, char *piece, char *version);
@@ -22,7 +24,7 @@ extern struct usb_device *device;
extern struct usb_dev_handle *dev;
int is_valid_device(struct usb_device_descriptor *udd);
void list_valid_devices();
-int usb_device_found(struct usb_device_descriptor *udd);
+int usb_device_found(struct usb_device_descriptor *udd, struct devices *it_device);
int console(const char *device);
int connect_via_usb();
int console_prompt();
@@ -54,7 +56,8 @@ struct devices {
unsigned short product_id;
unsigned short flags;
};
-#define SUPPORTED_DEVICES 5
+
+#define SUPPORTED_DEVICES 6
extern struct devices supported_devices[SUPPORTED_DEVICES];
extern int pcs_n;