Extend beastpatcher command line.
- prepare for building without included bootloader binary - allow specifying a bootloader.bin file on the command line git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22479 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
7feb639938
commit
d6b219387c
5 changed files with 102 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
CFLAGS=-Wall -W
|
||||
CFLAGS=-Wall -W -DWITH_BOOTOBJS
|
||||
|
||||
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
|
||||
OUTPUT=beastpatcher.exe
|
||||
|
|
|
@ -127,12 +127,40 @@ static void create_single_boot(unsigned char* boot, int bootlen,
|
|||
return;
|
||||
}
|
||||
|
||||
int beastpatcher(void)
|
||||
int beastpatcher(const unsigned char* bootfile)
|
||||
{
|
||||
char yesno[4];
|
||||
unsigned char* fwbuf;
|
||||
int fwsize;
|
||||
struct mtp_info_t mtp_info;
|
||||
unsigned char* bootloader = bootimg;
|
||||
unsigned int len_bootloader = LEN_bootimg;
|
||||
|
||||
if (bootfile) {
|
||||
int res;
|
||||
FILE* fp;
|
||||
size_t bread;
|
||||
#ifdef _LARGEFILE64_SOURCE
|
||||
struct stat64 sb;
|
||||
res = stat64(bootfile, &sb);
|
||||
#else
|
||||
struct stat sb;
|
||||
res = stat(bootfile, &sb);
|
||||
#endif
|
||||
if(res == -1) {
|
||||
fprintf(stderr, "[ERR] Getting bootloader file size failed!\n");
|
||||
return 1;
|
||||
}
|
||||
len_bootloader = sb.st_size;
|
||||
bootloader = (unsigned char*)malloc(len_bootloader);
|
||||
/* load bootloader binary to memory. */
|
||||
fp = fopen(bootfile, "rb");
|
||||
bread = fread(bootloader, sizeof(unsigned char), len_bootloader, fp);
|
||||
if(bread * sizeof(unsigned char) != len_bootloader) {
|
||||
fprintf(stderr, "[ERR] Error reading firmware file!\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mtp_init(&mtp_info) < 0) {
|
||||
fprintf(stderr,"[ERR] Can not init MTP\n");
|
||||
|
@ -158,7 +186,7 @@ int beastpatcher(void)
|
|||
if (yesno[0]=='i')
|
||||
{
|
||||
/* Create a single-boot bootloader from the embedded bootloader */
|
||||
create_single_boot(bootimg, LEN_bootimg, &fwbuf, &fwsize);
|
||||
create_single_boot(bootloader, len_bootloader, &fwbuf, &fwsize);
|
||||
|
||||
if (fwbuf == NULL)
|
||||
return 1;
|
||||
|
@ -180,6 +208,9 @@ int beastpatcher(void)
|
|||
fprintf(stderr,"[INFO] Installation cancelled.\n");
|
||||
}
|
||||
}
|
||||
if(bootfile) {
|
||||
free(bootloader);
|
||||
}
|
||||
|
||||
mtp_finished(&mtp_info);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#ifndef BEASTPATCHER_H
|
||||
#define BEASTPATCHER_H
|
||||
|
||||
int beastpatcher(void);
|
||||
int beastpatcher(const unsigned char* bootfile);
|
||||
int sendfirm(const char* filename);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,47 +47,98 @@
|
|||
#include "../MTP_DLL/MTP_DLL.h"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_BOOTOBJS
|
||||
#define VERSION "1.0 with v1 bootloader"
|
||||
#else
|
||||
#define VERSION "1.0"
|
||||
#endif
|
||||
|
||||
enum actions {
|
||||
NONE,
|
||||
INSTALL,
|
||||
SEND,
|
||||
HELP
|
||||
};
|
||||
|
||||
static void print_usage(void)
|
||||
{
|
||||
fprintf(stderr,"Usage: beastpatcher [action]\n");
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr,"Where [action] is one of the following options:\n");
|
||||
fprintf(stderr," -i, --install (default)\n");
|
||||
fprintf(stderr," -h, --help\n");
|
||||
#ifdef WITH_BOOTOBJS
|
||||
fprintf(stderr," -i, --install <bootloader.bin>\n");
|
||||
#else
|
||||
fprintf(stderr," -i, --install bootloader.bin\n");
|
||||
#endif
|
||||
fprintf(stderr," -s, --send nk.bin\n");
|
||||
fprintf(stderr," -h, --help\n");
|
||||
fprintf(stderr,"\n");
|
||||
#ifdef WITH_BOOTOBJS
|
||||
fprintf(stderr,"With bootloader file omitted the embedded one will be used.\n");
|
||||
fprintf(stderr,"\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int res;
|
||||
int res = 0;
|
||||
char yesno[4];
|
||||
int i;
|
||||
unsigned char* bootloader = NULL;
|
||||
unsigned char* firmware = NULL;
|
||||
#ifdef WITH_BOOTOBJS
|
||||
int action = INSTALL;
|
||||
#else
|
||||
int action = NONE;
|
||||
#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 || strcmp(argv[1],"-i")==0 || strcmp(argv[1],"--install")==0) {
|
||||
res = beastpatcher();
|
||||
i = 1;
|
||||
while(i < argc) {
|
||||
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||
action = HELP;
|
||||
}
|
||||
else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--install") == 0) {
|
||||
action = INSTALL;
|
||||
if(((i + 1) < argc) && argv[i + 1][0] != '-') {
|
||||
bootloader = argv[++i];
|
||||
}
|
||||
#ifndef WITH_BOOTOBJS
|
||||
else {
|
||||
action = NONE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if(((strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--send") == 0)
|
||||
&& (i + 1) < argc)) {
|
||||
action = SEND;
|
||||
firmware = argv[++i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(action == NONE) {
|
||||
print_usage();
|
||||
res = -1;
|
||||
}
|
||||
else if(action == HELP) {
|
||||
print_usage();
|
||||
res = 0;
|
||||
}
|
||||
else if(action == SEND) {
|
||||
res = sendfirm(firmware);
|
||||
}
|
||||
else if(action == INSTALL) {
|
||||
res = beastpatcher(bootloader);
|
||||
/* don't ask for enter if started with command line arguments */
|
||||
if(argc == 1) {
|
||||
printf("\nPress ENTER to exit beastpatcher: ");
|
||||
fgets(yesno,4,stdin);
|
||||
}
|
||||
}
|
||||
else if((argc > 2) && ((strcmp(argv[1],"-s")==0) || (strcmp(argv[1],"--send")==0))) {
|
||||
res = sendfirm(argv[2]);
|
||||
}
|
||||
else {
|
||||
print_usage();
|
||||
res = -1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="c:\wmsdk\wmfsdk95\include;c:\wmsdk\wmfsdk95\wmdm\inc"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;MTP_NODLL"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;MTP_NODLL;WITH_BOOTOBJS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="0"
|
||||
|
|
Loading…
Reference in a new issue