diff options
author | pancake <pancake@dazo> | 2007-04-25 21:47:53 +0200 |
---|---|---|
committer | pancake <pancake@dazo> | 2007-04-25 21:47:53 +0200 |
commit | 5b5425e0d06ac2a320ee182f2de9e805489e7e66 (patch) | |
tree | 0d7c263839a55013edfaaf2a9e4a9f558f427d80 /src | |
parent | 60f2337927efe4116a6675fccdf1021f51c86937 (diff) | |
download | 0xFFFF-5b5425e0d06ac2a320ee182f2de9e805489e7e66.tar.bz2 |
* import of the 'set-rd-flags+cleanups' patch from Robert Schuster
adds support for setting and clearing the rd flags (no-retu-watchdog,
serial-console and the like).
The interface to it is a bit cryptic (construct your own hex number) but
it works like like 'chmod'.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/main.c | 35 | ||||
-rw-r--r-- | src/query.c | 97 | ||||
-rw-r--r-- | src/query.h | 28 |
4 files changed, 147 insertions, 15 deletions
diff --git a/src/Makefile b/src/Makefile index ec48974..f88d138 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -VERSION=0.1 +VERSION=0.2 OBJ=main.o fiasco.o hexdump.o dump.o flash.o OBJ+=hash.o fpid.o query.o pieces.o utils.o BIN=0xFFFF @@ -33,7 +33,8 @@ struct usb_dev_handle *dev = NULL; char *fiasco_image = NULL; char *boot_cmdline = NULL; char *reverseto = NULL; -int rdflags = -1; +int rd_mode = -1; +int rd_flags = -1; int usb_mode = -1; int root_device = -1; int verbose = 0; @@ -151,8 +152,9 @@ void show_usage() printf(" -b [arg] boots the kernel with arguments\n"); printf(" -e [path] dump and extract pieces to path\n"); - printf(" -p [[p%%]file] piece-of-firmware %% file-where-this-piece-is\n"); printf(" -r [0|1] disable/enable R&D mode\n"); + printf(" -f <flags> set the given RD flags (see 'Flasher_tool_usage' in maemo wiki)\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(" -h show this help message\n"); @@ -183,7 +185,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:D:")) != -1) { + while((c = getopt(argc, argv, "p:vVhRu:ib:U:r:e:ld:I:D:f:")) != -1) { switch(c) { case 'd': sscanf(optarg, "%04hx:%04hx", @@ -197,11 +199,13 @@ int main(int argc, char **argv) case 'e': reverseto = optarg; break; + case 'f': + rd_flags = (unsigned short) strtoul(optarg, NULL, 16); case 'U': usb_mode = atoi(optarg); break; case 'r': - rdflags = atoi(optarg); + rd_mode = atoi(optarg); break; case 'b': boot_cmdline = optarg; @@ -246,15 +250,16 @@ int main(int argc, char **argv) && (boot_cmdline == NULL) && (reverseto == NULL) && (pcs_n == 0) - && (rdflags == -1) + && (rd_flags == -1) + && (rd_mode == -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(" [-b boot-args] [-I piece [-I ...]] [-u fiasco-image]\n"); - printf(" [-D 0|1|2]\n"); + printf(" [-D 0|1|2] [-F rd flags]\n"); return 1; } @@ -295,19 +300,17 @@ int main(int argc, char **argv) return 1; } - set_rd_mode(rdflags); - /* go go go! */ while(get_status()); // if (info) sleep(1); // take breath + get_hw_revision(); // get hardware revision: get_root_device(); // only for flashing - get_rd_mode(); get_usb_mode(); + get_rd_mode(); + get_rd_flags(); - get_hw_revision(); // get hardware revision: - if (pcs_n) { int c; @@ -321,10 +324,16 @@ int main(int argc, char **argv) } } + if (rd_mode != -1) + set_rd_mode(rd_mode); + + if (rd_flags != -1) + set_rd_flags(rd_flags); + if (root_device != -1) set_root_device(root_device); - if (usb_mode!=-1) + if (usb_mode != -1) set_usb_mode(usb_mode); if (boot_cmdline) diff --git a/src/query.c b/src/query.c index dda636c..9fc5d24 100644 --- a/src/query.c +++ b/src/query.c @@ -44,6 +44,12 @@ int get_status() */ int set_usb_mode(unsigned int mode) { + if (mode > 1) + { + printf("Invalid USB mode specified '%d'.\n", mode); + return -1; + } + if (usb_control_msg(dev, CMD_WRITE, 16, mode, 2, 0, 0, 2000) == -1) { fprintf(stderr, "Cannot set USB mode.\n"); return -1; @@ -65,7 +71,7 @@ int get_usb_mode() { unsigned short mode = 0; - if (usb_control_msg(dev, CMD_QUERY, 17, 0, 2, &mode, sizeof(mode), 2000) == -1) { + if (usb_control_msg(dev, CMD_QUERY, 17, 0, 2, (void *) &mode, sizeof(mode), 2000) == -1) { fprintf(stderr, "Cannot query device.\n"); return -1; } @@ -203,6 +209,95 @@ int set_root_device(unsigned short root_device) return 0; } +/** + * Set flags: + * request type: CMD_WRITE + * request : 16 + * value : flags to set, see below + * index : 3 + * + * Clear flags: + * request type: CMD_WRITE + * request : 16 + * value : flags to clear, see below + * index : 4 + + * Flags are composed of: + * 0x02 - disable OMAP watchdog (possibly) + * 0x04 - disable RETU watchdog (possibly) + * 0x08 - disable lifeguard reset + * 0x10 - enable serial console + * 0x20 - disable USB timeout + * + * The function encapsule the NOLO API in a way that it works like + * a chmod 707. The bits that are not set will be cleared after the + * call. This is done by issuing a 'clear flags' command with all the + * non set bits. + * + */ +int set_rd_flags(unsigned short flags) +{ + unsigned short reverse_flags = 0; + + if (flags & ~(0x02 | 0x04 | 0x08 | 0x10 | 0x20)) { + printf("Invalid rd flags specified '%x'.\n", flags); + return -1; + } + + if (!(flags & 0x02)) + reverse_flags |= 0x02; + + if (!(flags & 0x04)) + reverse_flags |= 0x04; + + if (!(flags & 0x08)) + reverse_flags |= 0x08; + + if (!(flags & 0x10)) + reverse_flags |= 0x10; + + if (!(flags & 0x20)) + reverse_flags |= 0x20; + + if (usb_control_msg(dev, CMD_WRITE, 16, flags, 3, 0, 0, 2000) == -1) { + fprintf(stderr, "Cannot set rd flags\n"); + return -1; + } + + if (usb_control_msg(dev, CMD_WRITE, 16, reverse_flags, 4, 0, 0, 2000) == -1) { + fprintf(stderr, "Cannot set rd flags\n"); + return -1; + } + + printf("Set rd flags successfully!\n"); + printf("disable OMAP watchdog : %s\n", (flags & 0x02) ? "set" : "not set"); + printf("disable RETU watchdog : %s\n", (flags & 0x04) ? "set" : "not set"); + printf("disable lifeguard reset: %s\n", (flags & 0x08) ? "set" : "not set"); + printf("enable serial console : %s\n", (flags & 0x10) ? "set" : "not set"); + printf("disable USB timeout : %s\n", (flags & 0x20) ? "set" : "not set"); + + return 0; +} + +int get_rd_flags() +{ + unsigned short flags = 0; + + if (usb_control_msg(dev, CMD_QUERY, 17, 0, 3, (void *) &flags, sizeof(flags), 2000) == -1) { + fprintf(stderr, "Cannot get rd flags\n"); + return -1; + } + + printf("Current rd flag setting:\n"); + printf("disable OMAP watchdog : %s\n", (flags & 0x02) ? "set" : "not set"); + printf("disable RETU watchdog : %s\n", (flags & 0x04) ? "set" : "not set"); + printf("disable lifeguard reset: %s\n", (flags & 0x08) ? "set" : "not set"); + printf("enable serial console : %s\n", (flags & 0x10) ? "set" : "not set"); + printf("disable USB timeout : %s\n", (flags & 0x20) ? "set" : "not set"); + + return 0; +} + int get_nolo_version() { unsigned int version; // ensure uint is at least 32 bits diff --git a/src/query.h b/src/query.h new file mode 100644 index 0000000..03ee963 --- /dev/null +++ b/src/query.h @@ -0,0 +1,28 @@ +#ifndef QUERY_H_ +#define QUERY_H_ + +int boot_board(char *cmdline); + +int reboot_board(); + +int get_status(); + +int get_usb_mode(); +int set_usb_mode(unsigned int); + +int get_rd_mode(); +int set_rd_mode(unsigned short mode); + +int get_rd_flags(); +int set_rd_flags(unsigned short flags); + +int get_hw_revision(); + +int get_root_device(); +int set_root_device(unsigned short); + +int get_nolo_version(); + +int get_sw_version(); + +#endif /*QUERY_H_*/ |