forked from len0rd/rockbox
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
This commit is contained in:
parent
092a36bc77
commit
0cab10e2f5
3 changed files with 40 additions and 33 deletions
|
|
@ -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 (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 (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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue