* 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.
This commit is contained in:
1 parent
ed3cb1d3f8
commit
579dbe9837
3 files changed
+82
-29
No files matched your search
+30
-17
@@ -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)
|
||||
{
|
||||
if (usb_find_busses() < 0) {
|
||||
fprintf(stderr, "error: no usb busses found.\n");
|
||||
exit(1);
|
||||
} else {
|
||||
if (usb_find_devices() < 0) {
|
||||
fprintf(stderr, "error: no devices found.\n");
|
||||
exit(1);
|
||||
} else {
|
||||
struct usb_bus *bus;
|
||||
int dev_index = 0;
|
||||
|
||||
if (usb_find_busses() < 0) {
|
||||
fprintf(stderr, "\nerror: no usb busses found.\n");
|
||||
exit(1);
|
||||
} else {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+47
-10
@@ -112,35 +112,69 @@ void unpack_fiasco_image(char *file)
|
||||
|
||||
int connect_via_usb()
|
||||
{
|
||||
int c=0;
|
||||
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
|
||||
|
||||
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) {
|
||||
/* open device */
|
||||
if(!(dev = usb_open(device))) {
|
||||
perror("usb_open");
|
||||
return 1;
|
||||
}
|
||||
// TODO
|
||||
|
||||
if ( usb_claim_interface(dev, 2) < 0) { // 2 or 0
|
||||
perror("usb_claim_interface");
|
||||
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) {
|
||||
perror("usb_set_altinterface");
|
||||
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("");
|
||||
|
||||
+5
-2
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user