summaryrefslogtreecommitdiff
path: root/utils/MTP/beastpatcher/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/MTP/beastpatcher/main.c')
-rw-r--r--utils/MTP/beastpatcher/main.c81
1 files changed, 66 insertions, 15 deletions
diff --git a/utils/MTP/beastpatcher/main.c b/utils/MTP/beastpatcher/main.c
index 6632b7ae8d..f5150bbbab 100644
--- a/utils/MTP/beastpatcher/main.c
+++ b/utils/MTP/beastpatcher/main.c
@@ -47,47 +47,98 @@
47#include "../MTP_DLL/MTP_DLL.h" 47#include "../MTP_DLL/MTP_DLL.h"
48#endif 48#endif
49 49
50#ifdef WITH_BOOTOBJS
50#define VERSION "1.0 with v1 bootloader" 51#define VERSION "1.0 with v1 bootloader"
52#else
53#define VERSION "1.0"
54#endif
51 55
56enum actions {
57 NONE,
58 INSTALL,
59 SEND,
60 HELP
61};
52 62
53static void print_usage(void) 63static void print_usage(void)
54{ 64{
55 fprintf(stderr,"Usage: beastpatcher [action]\n"); 65 fprintf(stderr,"Usage: beastpatcher [action]\n");
56 fprintf(stderr,"\n"); 66 fprintf(stderr,"\n");
57 fprintf(stderr,"Where [action] is one of the following options:\n"); 67 fprintf(stderr,"Where [action] is one of the following options:\n");
58 fprintf(stderr," -i, --install (default)\n"); 68#ifdef WITH_BOOTOBJS
59 fprintf(stderr," -h, --help\n"); 69 fprintf(stderr," -i, --install <bootloader.bin>\n");
70#else
71 fprintf(stderr," -i, --install bootloader.bin\n");
72#endif
60 fprintf(stderr," -s, --send nk.bin\n"); 73 fprintf(stderr," -s, --send nk.bin\n");
74 fprintf(stderr," -h, --help\n");
61 fprintf(stderr,"\n"); 75 fprintf(stderr,"\n");
76#ifdef WITH_BOOTOBJS
77 fprintf(stderr,"With bootloader file omitted the embedded one will be used.\n");
78 fprintf(stderr,"\n");
79#endif
62} 80}
63 81
64 82
65int main(int argc, char* argv[]) 83int main(int argc, char* argv[])
66{ 84{
67 int res; 85 int res = 0;
68 char yesno[4]; 86 char yesno[4];
87 int i;
88 unsigned char* bootloader = NULL;
89 unsigned char* firmware = NULL;
90#ifdef WITH_BOOTOBJS
91 int action = INSTALL;
92#else
93 int action = NONE;
94#endif
69 95
70 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n"); 96 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
71 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n"); 97 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
72 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); 98 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
73 99
74 if(argc == 1 || strcmp(argv[1],"-i")==0 || strcmp(argv[1],"--install")==0) { 100 i = 1;
75 res = beastpatcher(); 101 while(i < argc) {
102 if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
103 action = HELP;
104 }
105 else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--install") == 0) {
106 action = INSTALL;
107 if(((i + 1) < argc) && argv[i + 1][0] != '-') {
108 bootloader = argv[++i];
109 }
110#ifndef WITH_BOOTOBJS
111 else {
112 action = NONE;
113 }
114#endif
115 }
116 else if(((strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--send") == 0)
117 && (i + 1) < argc)) {
118 action = SEND;
119 firmware = argv[++i];
120 }
121 i++;
122 }
123
124 if(action == NONE) {
125 print_usage();
126 res = -1;
127 }
128 else if(action == HELP) {
129 print_usage();
130 res = 0;
131 }
132 else if(action == SEND) {
133 res = sendfirm(firmware);
134 }
135 else if(action == INSTALL) {
136 res = beastpatcher(bootloader);
76 /* don't ask for enter if started with command line arguments */ 137 /* don't ask for enter if started with command line arguments */
77 if(argc == 1) { 138 if(argc == 1) {
78 printf("\nPress ENTER to exit beastpatcher: "); 139 printf("\nPress ENTER to exit beastpatcher: ");
79 fgets(yesno,4,stdin); 140 fgets(yesno,4,stdin);
80 } 141 }
81 } 142 }
82 else if((argc > 2) && ((strcmp(argv[1],"-s")==0) || (strcmp(argv[1],"--send")==0))) {
83 res = sendfirm(argv[2]);
84 }
85 else {
86 print_usage();
87 res = -1;
88 }
89
90 return res; 143 return res;
91} 144}
92
93