From 300635ad8f8c5bdb5c50fc95f1c456ea7cc45151 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 20 Apr 2007 18:27:31 +0200 Subject: * 'set root device' patch inclusion from Robert Schuster --- src/main.c | 16 +++++++++++++--- src/main.h | 3 +++ src/query.c | 31 +++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 7812ae1..a463c26 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,7 @@ char *boot_cmdline = NULL; char *reverseto = NULL; int rdflags = -1; int usb_mode = -1; +int root_device = -1; int verbose = 0; int identify = 0; int reboot = 0; @@ -157,6 +158,7 @@ void show_usage() printf(" -I [piece] identify a firmware piece\n"); printf(" -l list supported usb device ids\n"); printf(" -d [vid:pid] injects a usb device into the supported list\n"); + printf(" -D [0|1|2] sets the root device to flash (0), mmc (1) or usb (2)\n"); printf(" -R reboot the omap board\n"); printf(" -v be verbose and noisy\n"); printf(" -V show 0xFFFF version information\n"); @@ -199,7 +201,7 @@ int main(int argc, char **argv) struct usb_device_descriptor udd; int c; - while((c = getopt(argc, argv, "p:vVhRu:ib:U:r:e:ld:I:")) != -1) { + while((c = getopt(argc, argv, "p:vVhRu:ib:U:r:e:ld:I:D:")) != -1) { switch(c) { case 'd': sscanf(optarg, "%04hx:%04hx", @@ -207,6 +209,9 @@ int main(int argc, char **argv) &supported_devices[SUPPORTED_DEVICES-2].product_id); supported_devices[SUPPORTED_DEVICES-2].name = strdup("user"); break; + case 'D': + root_device = atoi(optarg); + break; case 'e': reverseto = optarg; break; @@ -262,10 +267,12 @@ int main(int argc, char **argv) && (rdflags == -1) && (info == 0) && (reboot == 0) - && (usb_mode == -1)) + && (usb_mode == -1) + && (root_device == -1)) { - printf("Usage: 0xFFFF [-hvVRi] [-e path] [-U 0|1] [-p [piece%]file [-p ...]]\n"); + 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]\n"); return 1; } @@ -330,6 +337,9 @@ int main(int argc, char **argv) } } + if (root_device != -1) + set_root_device(root_device); + if (usb_mode!=-1) set_usb_host_mode(usb_mode); diff --git a/src/main.h b/src/main.h index 9b0bcd1..0155833 100644 --- a/src/main.h +++ b/src/main.h @@ -21,7 +21,10 @@ 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); diff --git a/src/query.c b/src/query.c index bdbcf69..073bf16 100644 --- a/src/query.c +++ b/src/query.c @@ -28,7 +28,7 @@ int get_status() { int ret = 0; - if (usb_control_msg(dev, 192, 1, 0, 0, (char *)&ret, 4, 2000) == -1) { + if (usb_control_msg(dev, CMD_QUERY, 1, 0, 0, (char *)&ret, 4, 2000) == -1) { fprintf(stderr, "Cannot get device status.\n"); exit(1); } @@ -157,7 +157,7 @@ int query_root_device() { unsigned char opcode; - if (usb_control_msg(dev, 192, 17, 0, 1, (char *)&opcode, 1, 2000) < 0) { + if (usb_control_msg(dev, CMD_QUERY, 17, 0, 1, (char *)&opcode, 1, 2000) < 0) { fprintf(stderr, "Cannot query root device\n"); return -1; } @@ -171,12 +171,35 @@ int query_root_device() return 0; } +/** + * request type: CMD_WRITE + * request : 16 + * value : 0|1|2 (=> flash|mmc|usb) + * index : 1 + */ +int set_root_device(unsigned short root_device) +{ + if (root_device>2) { + printf("Invalid root device specified '%d'.\n", root_device); + return -1; + } + + if (usb_control_msg(dev, CMD_WRITE, 16, root_device, 1, 0, 0, 2000) == -1) { + fprintf(stderr, "Cannot set root device\n"); + return -1; + } + + printf("Root device set to: %s\n", root_devices[root_device]); + + return 0; +} + int query_nolo_version() { unsigned int version; // ensure uint is at least 32 bits - //if (usb_control_msg(dev, 192, 3, 0, 1, (char *)&version, 4 , 2000) < 0) { - if (usb_control_msg(dev, 192, 3, 0, 0, (char *)&version, 4 , 2000) < 0) { + //if (usb_control_msg(dev, CMD_QUERY, 3, 0, 1, (char *)&version, 4 , 2000) < 0) { + if (usb_control_msg(dev, CMD_QUERY, 3, 0, 0, (char *)&version, 4 , 2000) < 0) { fprintf(stderr, "Cannot query nolo version. Old bootloader version?\n"); exit(1); } -- cgit v1.2.3