summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.c64
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.h2
-rw-r--r--utils/MTP/beastpatcher/main.c11
3 files changed, 42 insertions, 35 deletions
diff --git a/utils/MTP/beastpatcher/beastpatcher.c b/utils/MTP/beastpatcher/beastpatcher.c
index 9d216d37bf..35c4d83c31 100644
--- a/utils/MTP/beastpatcher/beastpatcher.c
+++ b/utils/MTP/beastpatcher/beastpatcher.c
@@ -158,7 +158,7 @@ static int readfile(const char* filename, struct filebuf *buf)
158} 158}
159 159
160 160
161int beastpatcher(const char* bootfile, const char* firmfile) 161int beastpatcher(const char* bootfile, const char* firmfile, int interactive)
162{ 162{
163 char yesno[4]; 163 char yesno[4];
164 struct mtp_info_t mtp_info; 164 struct mtp_info_t mtp_info;
@@ -195,45 +195,47 @@ int beastpatcher(const char* bootfile, const char* firmfile)
195 mtp_info.modelname); 195 mtp_info.modelname);
196 printf("[INFO] Device version: \"%s\"\n",mtp_info.version); 196 printf("[INFO] Device version: \"%s\"\n",mtp_info.version);
197 197
198 if(firmfile) { 198 if (interactive) {
199 printf("\nEnter i to install the Rockbox dualboot bootloader or c to cancel and do nothing (i/c): "); 199 if(firmfile) {
200 } 200 printf("\nEnter i to install the Rockbox dualboot bootloader or c "
201 else { 201 "to cancel and do nothing (i/c): ");
202 printf("\nEnter i to install the Rockbox bootloader or c to cancel and do nothing (i/c): "); 202 }
203 else {
204 printf("\nEnter i to install the Rockbox bootloader or c to cancel "
205 "and do nothing (i/c): ");
206 }
207 fgets(yesno,4,stdin);
203 } 208 }
204 209
205 if (fgets(yesno,4,stdin)) 210 if (!interactive || yesno[0]=='i')
206 { 211 {
207 if (yesno[0]=='i') 212 if(firmfile) {
208 { 213 /* if a firmware file is given create a dualboot image. */
209 if(firmfile) { 214 mknkboot(&firmware, &bootloader, &fw);
210 /* if a firmware file is given create a dualboot image. */ 215 }
211 mknkboot(&firmware, &bootloader, &fw); 216 else {
212 }
213 else {
214 /* Create a single-boot bootloader from the embedded bootloader */ 217 /* Create a single-boot bootloader from the embedded bootloader */
215 create_single_boot(bootloader.buf, bootloader.len, &fw.buf, &fw.len); 218 create_single_boot(bootloader.buf, bootloader.len, &fw.buf, &fw.len);
216 } 219 }
217 220
218 if (fw.buf == NULL) 221 if (fw.buf == NULL)
219 return 1; 222 return 1;
220 223
221 if (mtp_send_firmware(&mtp_info, fw.buf, fw.len) == 0) 224 if (mtp_send_firmware(&mtp_info, fw.buf, fw.len) == 0)
222 { 225 {
223 fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); 226 fprintf(stderr,"[INFO] Bootloader installed successfully.\n");
224 }
225 else
226 {
227 fprintf(stderr,"[ERR] Bootloader install failed.\n");
228 }
229
230 /* We are now done with the firmware image */
231 free(fw.buf);
232 } 227 }
233 else 228 else
234 { 229 {
235 fprintf(stderr,"[INFO] Installation cancelled.\n"); 230 fprintf(stderr,"[ERR] Bootloader install failed.\n");
236 } 231 }
232
233 /* We are now done with the firmware image */
234 free(fw.buf);
235 }
236 else
237 {
238 fprintf(stderr,"[INFO] Installation cancelled.\n");
237 } 239 }
238 if(bootfile) { 240 if(bootfile) {
239 free(bootloader.buf); 241 free(bootloader.buf);
diff --git a/utils/MTP/beastpatcher/beastpatcher.h b/utils/MTP/beastpatcher/beastpatcher.h
index 79246dbb17..d9a26b18b8 100644
--- a/utils/MTP/beastpatcher/beastpatcher.h
+++ b/utils/MTP/beastpatcher/beastpatcher.h
@@ -40,7 +40,7 @@
40#ifndef BEASTPATCHER_H 40#ifndef BEASTPATCHER_H
41#define BEASTPATCHER_H 41#define BEASTPATCHER_H
42 42
43int beastpatcher(const char* bootfile, const char* firmfile); 43int beastpatcher(const char* bootfile, const char* firmfile, int interactive);
44int sendfirm(const char* filename); 44int sendfirm(const char* filename);
45 45
46#endif 46#endif
diff --git a/utils/MTP/beastpatcher/main.c b/utils/MTP/beastpatcher/main.c
index 315f78b264..97d931e454 100644
--- a/utils/MTP/beastpatcher/main.c
+++ b/utils/MTP/beastpatcher/main.c
@@ -92,13 +92,18 @@ int main(int argc, char* argv[])
92 char* firmware = NULL; 92 char* firmware = NULL;
93#ifdef WITH_BOOTOBJS 93#ifdef WITH_BOOTOBJS
94 enum actions action = INSTALL; 94 enum actions action = INSTALL;
95 int interactive = 1;
95#else 96#else
96 enum actions action = NONE; 97 enum actions action = NONE;
98 int interactive = 0;
97#endif 99#endif
98 100
99 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n"); 101 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
100 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n"); 102 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
101 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); 103 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
104 if(argc > 1) {
105 interactive = 0;
106 }
102 107
103 i = 1; 108 i = 1;
104 while(i < argc) { 109 while(i < argc) {
@@ -150,12 +155,12 @@ int main(int argc, char* argv[])
150 res = sendfirm(firmware); 155 res = sendfirm(firmware);
151 } 156 }
152 else if(action == DUALBOOT) { 157 else if(action == DUALBOOT) {
153 res = beastpatcher(bootloader, firmware); 158 res = beastpatcher(bootloader, firmware, interactive);
154 } 159 }
155 else if(action == INSTALL) { 160 else if(action == INSTALL) {
156 res = beastpatcher(bootloader, NULL); 161 res = beastpatcher(bootloader, NULL, interactive);
157 /* don't ask for enter if started with command line arguments */ 162 /* don't ask for enter if started with command line arguments */
158 if(argc == 1) { 163 if(interactive) {
159 printf("\nPress ENTER to exit beastpatcher: "); 164 printf("\nPress ENTER to exit beastpatcher: ");
160 fgets(yesno,4,stdin); 165 fgets(yesno,4,stdin);
161 } 166 }