summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-08-23 20:06:46 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-08-23 20:06:46 +0000
commitd6b219387c2a5c31c070186e08b02e68b266d21d (patch)
treeabb85c387ee3a387b8d41c840ef2e0f1cf52622c
parent7feb6399383eb3b5cb63ba5f1d2db3117fd09528 (diff)
downloadrockbox-d6b219387c2a5c31c070186e08b02e68b266d21d.tar.gz
rockbox-d6b219387c2a5c31c070186e08b02e68b266d21d.zip
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
-rw-r--r--utils/MTP/beastpatcher/Makefile2
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.c35
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.h2
-rw-r--r--utils/MTP/beastpatcher/main.c81
-rw-r--r--utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj2
5 files changed, 102 insertions, 20 deletions
diff --git a/utils/MTP/beastpatcher/Makefile b/utils/MTP/beastpatcher/Makefile
index 590473a50f..52887f06b2 100644
--- a/utils/MTP/beastpatcher/Makefile
+++ b/utils/MTP/beastpatcher/Makefile
@@ -1,4 +1,4 @@
1CFLAGS=-Wall -W 1CFLAGS=-Wall -W -DWITH_BOOTOBJS
2 2
3ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) 3ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
4OUTPUT=beastpatcher.exe 4OUTPUT=beastpatcher.exe
diff --git a/utils/MTP/beastpatcher/beastpatcher.c b/utils/MTP/beastpatcher/beastpatcher.c
index 72de1b57b8..d6c49ac596 100644
--- a/utils/MTP/beastpatcher/beastpatcher.c
+++ b/utils/MTP/beastpatcher/beastpatcher.c
@@ -127,12 +127,40 @@ static void create_single_boot(unsigned char* boot, int bootlen,
127 return; 127 return;
128} 128}
129 129
130int beastpatcher(void) 130int beastpatcher(const unsigned char* bootfile)
131{ 131{
132 char yesno[4]; 132 char yesno[4];
133 unsigned char* fwbuf; 133 unsigned char* fwbuf;
134 int fwsize; 134 int fwsize;
135 struct mtp_info_t mtp_info; 135 struct mtp_info_t mtp_info;
136 unsigned char* bootloader = bootimg;
137 unsigned int len_bootloader = LEN_bootimg;
138
139 if (bootfile) {
140 int res;
141 FILE* fp;
142 size_t bread;
143#ifdef _LARGEFILE64_SOURCE
144 struct stat64 sb;
145 res = stat64(bootfile, &sb);
146#else
147 struct stat sb;
148 res = stat(bootfile, &sb);
149#endif
150 if(res == -1) {
151 fprintf(stderr, "[ERR] Getting bootloader file size failed!\n");
152 return 1;
153 }
154 len_bootloader = sb.st_size;
155 bootloader = (unsigned char*)malloc(len_bootloader);
156 /* load bootloader binary to memory. */
157 fp = fopen(bootfile, "rb");
158 bread = fread(bootloader, sizeof(unsigned char), len_bootloader, fp);
159 if(bread * sizeof(unsigned char) != len_bootloader) {
160 fprintf(stderr, "[ERR] Error reading firmware file!\n");
161 return 1;
162 }
163 }
136 164
137 if (mtp_init(&mtp_info) < 0) { 165 if (mtp_init(&mtp_info) < 0) {
138 fprintf(stderr,"[ERR] Can not init MTP\n"); 166 fprintf(stderr,"[ERR] Can not init MTP\n");
@@ -158,7 +186,7 @@ int beastpatcher(void)
158 if (yesno[0]=='i') 186 if (yesno[0]=='i')
159 { 187 {
160 /* Create a single-boot bootloader from the embedded bootloader */ 188 /* Create a single-boot bootloader from the embedded bootloader */
161 create_single_boot(bootimg, LEN_bootimg, &fwbuf, &fwsize); 189 create_single_boot(bootloader, len_bootloader, &fwbuf, &fwsize);
162 190
163 if (fwbuf == NULL) 191 if (fwbuf == NULL)
164 return 1; 192 return 1;
@@ -180,6 +208,9 @@ int beastpatcher(void)
180 fprintf(stderr,"[INFO] Installation cancelled.\n"); 208 fprintf(stderr,"[INFO] Installation cancelled.\n");
181 } 209 }
182 } 210 }
211 if(bootfile) {
212 free(bootloader);
213 }
183 214
184 mtp_finished(&mtp_info); 215 mtp_finished(&mtp_info);
185 216
diff --git a/utils/MTP/beastpatcher/beastpatcher.h b/utils/MTP/beastpatcher/beastpatcher.h
index d5a4eb0dce..f523979662 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(void); 43int beastpatcher(const unsigned char* bootfile);
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 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
diff --git a/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj b/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
index e87ad04dce..69925a8d2c 100644
--- a/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
+++ b/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
@@ -42,7 +42,7 @@
42 Name="VCCLCompilerTool" 42 Name="VCCLCompilerTool"
43 Optimization="0" 43 Optimization="0"
44 AdditionalIncludeDirectories="c:\wmsdk\wmfsdk95\include;c:\wmsdk\wmfsdk95\wmdm\inc" 44 AdditionalIncludeDirectories="c:\wmsdk\wmfsdk95\include;c:\wmsdk\wmfsdk95\wmdm\inc"
45 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;MTP_NODLL" 45 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;MTP_NODLL;WITH_BOOTOBJS"
46 MinimalRebuild="true" 46 MinimalRebuild="true"
47 BasicRuntimeChecks="3" 47 BasicRuntimeChecks="3"
48 RuntimeLibrary="0" 48 RuntimeLibrary="0"