diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-09-24 17:07:08 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-09-24 17:07:08 +0000 |
commit | 0cab10e2f5b16d0425713c6dfe691007510c2f4a (patch) | |
tree | 330a6b3d6dfbc138d1ba8b127cbe91df764caf51 | |
parent | 092a36bc77a8046c3c78efa2004b7b016efab0b3 (diff) |
Add non-interactive mode to beastpatcher.
- Extend beastpatcher() to optionally work non-interactively.
- Don't ask for confirmation if beastpatcher was started with command line arguments.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22820 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/MTP/beastpatcher/beastpatcher.c | 64 | ||||
-rw-r--r-- | utils/MTP/beastpatcher/beastpatcher.h | 2 | ||||
-rw-r--r-- | utils/MTP/beastpatcher/main.c | 11 |
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) } -int beastpatcher(const char* bootfile, const char* firmfile) +int beastpatcher(const char* bootfile, const char* firmfile, int interactive) { char yesno[4]; struct mtp_info_t mtp_info; @@ -195,45 +195,47 @@ int beastpatcher(const char* bootfile, const char* firmfile) mtp_info.modelname); printf("[INFO] Device version: \"%s\"\n",mtp_info.version); - if(firmfile) { - printf("\nEnter i to install the Rockbox dualboot bootloader or c to cancel and do nothing (i/c): "); - } - else { - printf("\nEnter i to install the Rockbox bootloader or c to cancel and do nothing (i/c): "); + if (interactive) { + if(firmfile) { + printf("\nEnter i to install the Rockbox dualboot bootloader or c " + "to cancel and do nothing (i/c): "); + } + else { + printf("\nEnter i to install the Rockbox bootloader or c to cancel " + "and do nothing (i/c): "); + } + fgets(yesno,4,stdin); } - if (fgets(yesno,4,stdin)) + if (!interactive || yesno[0]=='i') { - if (yesno[0]=='i') - { - if(firmfile) { - /* if a firmware file is given create a dualboot image. */ - mknkboot(&firmware, &bootloader, &fw); - } - else { + if(firmfile) { + /* if a firmware file is given create a dualboot image. */ + mknkboot(&firmware, &bootloader, &fw); + } + else { /* Create a single-boot bootloader from the embedded bootloader */ create_single_boot(bootloader.buf, bootloader.len, &fw.buf, &fw.len); - } - - if (fw.buf == NULL) - return 1; - - if (mtp_send_firmware(&mtp_info, fw.buf, fw.len) == 0) - { - fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); - } - else - { - fprintf(stderr,"[ERR] Bootloader install failed.\n"); - } - - /* We are now done with the firmware image */ - free(fw.buf); + } + + if (fw.buf == NULL) + return 1; + + if (mtp_send_firmware(&mtp_info, fw.buf, fw.len) == 0) + { + fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); } else { - fprintf(stderr,"[INFO] Installation cancelled.\n"); + fprintf(stderr,"[ERR] Bootloader install failed.\n"); } + + /* We are now done with the firmware image */ + free(fw.buf); + } + else + { + fprintf(stderr,"[INFO] Installation cancelled.\n"); } if(bootfile) { 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 @@ #ifndef BEASTPATCHER_H #define BEASTPATCHER_H -int beastpatcher(const char* bootfile, const char* firmfile); +int beastpatcher(const char* bootfile, const char* firmfile, int interactive); int sendfirm(const char* filename); #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[]) char* firmware = NULL; #ifdef WITH_BOOTOBJS enum actions action = INSTALL; + int interactive = 1; #else enum actions action = NONE; + int interactive = 0; #endif fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n"); fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n"); fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); + if(argc > 1) { + interactive = 0; + } i = 1; while(i < argc) { @@ -150,12 +155,12 @@ int main(int argc, char* argv[]) res = sendfirm(firmware); } else if(action == DUALBOOT) { - res = beastpatcher(bootloader, firmware); + res = beastpatcher(bootloader, firmware, interactive); } else if(action == INSTALL) { - res = beastpatcher(bootloader, NULL); + res = beastpatcher(bootloader, NULL, interactive); /* don't ask for enter if started with command line arguments */ - if(argc == 1) { + if(interactive) { printf("\nPress ENTER to exit beastpatcher: "); fgets(yesno,4,stdin); } |