summaryrefslogtreecommitdiff
path: root/tools/fwpatcher/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/fwpatcher/main.c')
-rw-r--r--tools/fwpatcher/main.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/tools/fwpatcher/main.c b/tools/fwpatcher/main.c
index 1ec67678df..3015c8fc61 100644
--- a/tools/fwpatcher/main.c
+++ b/tools/fwpatcher/main.c
@@ -56,15 +56,21 @@ static struct sumpairs h120pairs[] = {
56#include "h120sums.h" 56#include "h120sums.h"
57}; 57};
58 58
59/* precalculated checksums for H320/H340 */
60static struct sumpairs h300pairs[] = {
61#include "h300sums.h"
62};
63
59HICON rbicon; 64HICON rbicon;
60HFONT deffont; 65HFONT deffont;
61HWND controls[CTL_NUM]; 66HWND controls[CTL_NUM];
62 67
63/* begin mkboot.c excerpt */ 68/* begin mkboot.c excerpt */
64 69
65unsigned char image[0x200000 + 0x220 + 0x200000/0x200]; 70unsigned char image[0x400000 + 0x220 + 0x400000/0x200];
66 71
67int mkboot(TCHAR *infile, TCHAR *outfile, unsigned char *bldata, int bllen) 72int mkboot(TCHAR *infile, TCHAR *outfile, unsigned char *bldata, int bllen,
73 int origin)
68{ 74{
69 FILE *f; 75 FILE *f;
70 int i; 76 int i;
@@ -101,7 +107,7 @@ int mkboot(TCHAR *infile, TCHAR *outfile, unsigned char *bldata, int bllen)
101 107
102 fclose(f); 108 fclose(f);
103 109
104 memcpy(image + 0x220 + 0x1f0000, bldata, bllen); 110 memcpy(image + 0x220 + origin, bldata, bllen);
105 111
106 f = _tfopen(outfile, TEXT("wb")); 112 f = _tfopen(outfile, TEXT("wb"));
107 if(!f) { 113 if(!f) {
@@ -110,13 +116,13 @@ int mkboot(TCHAR *infile, TCHAR *outfile, unsigned char *bldata, int bllen)
110 } 116 }
111 117
112 /* Patch the reset vector to start the boot loader */ 118 /* Patch the reset vector to start the boot loader */
113 image[0x220 + 4] = image[0x1f0000 + 0x220 + 4]; 119 image[0x220 + 4] = image[origin + 0x220 + 4];
114 image[0x220 + 5] = image[0x1f0000 + 0x220 + 5]; 120 image[0x220 + 5] = image[origin + 0x220 + 5];
115 image[0x220 + 6] = image[0x1f0000 + 0x220 + 6]; 121 image[0x220 + 6] = image[origin + 0x220 + 6];
116 image[0x220 + 7] = image[0x1f0000 + 0x220 + 7]; 122 image[0x220 + 7] = image[origin + 0x220 + 7];
117 123
118 /* This is the actual length of the binary, excluding all headers */ 124 /* This is the actual length of the binary, excluding all headers */
119 actual_length = 0x1f0000 + bllen; 125 actual_length = origin + bllen;
120 126
121 /* Patch the ESTFBINR header */ 127 /* Patch the ESTFBINR header */
122 image[0x20c] = (actual_length >> 24) & 0xff; 128 image[0x20c] = (actual_length >> 24) & 0xff;
@@ -216,16 +222,24 @@ int PatchFirmware(int series, int table_entry)
216 DWORD blsize; 222 DWORD blsize;
217 int i; 223 int i;
218 struct sumpairs *sums; 224 struct sumpairs *sums;
225 int origin;
219 226
220 /* get pointer to the correct bootloader.bin */ 227 /* get pointer to the correct bootloader.bin */
221 switch(series) { 228 switch(series) {
222 case 100: 229 case 100:
223 res = FindResource(NULL, MAKEINTRESOURCE(IDI_BOOTLOADERH100), TEXT("BIN")); 230 res = FindResource(NULL, MAKEINTRESOURCE(IDI_BOOTLOADERH100), TEXT("BIN"));
224 sums = &h100pairs[0]; 231 sums = &h100pairs[0];
232 origin = 0x1f0000;
225 break; 233 break;
226 case 120: 234 case 120:
227 res = FindResource(NULL, MAKEINTRESOURCE(IDI_BOOTLOADERH120), TEXT("BIN")); 235 res = FindResource(NULL, MAKEINTRESOURCE(IDI_BOOTLOADERH120), TEXT("BIN"));
228 sums = &h120pairs[0]; 236 sums = &h120pairs[0];
237 origin = 0x1f0000;
238 break;
239 case 300:
240 res = FindResource(NULL, MAKEINTRESOURCE(IDI_BOOTLOADERH300), TEXT("BIN"));
241 sums = &h300pairs[0];
242 origin = 0x3f0000;
229 break; 243 break;
230 } 244 }
231 resload = LoadResource(NULL, res); 245 resload = LoadResource(NULL, res);
@@ -246,7 +260,7 @@ int PatchFirmware(int series, int table_entry)
246 TEXT("Error"), MB_ICONERROR); 260 TEXT("Error"), MB_ICONERROR);
247 goto error; 261 goto error;
248 } 262 }
249 if (!mkboot(name1, name2, bootloader, blsize)) { 263 if (!mkboot(name1, name2, bootloader, blsize, origin)) {
250 MessageBox(NULL, TEXT("Error in patching"), 264 MessageBox(NULL, TEXT("Error in patching"),
251 TEXT("Error"), MB_ICONERROR); 265 TEXT("Error"), MB_ICONERROR);
252 goto error; 266 goto error;
@@ -380,8 +394,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
380 else { 394 else {
381 table_entry = intable(md5sum_str, &h100pairs[0], 395 table_entry = intable(md5sum_str, &h100pairs[0],
382 sizeof(h100pairs)/sizeof(struct sumpairs)); 396 sizeof(h100pairs)/sizeof(struct sumpairs));
383 if (table_entry >= 0) 397 if (table_entry >= 0) {
384 series = 100; 398 series = 100;
399 }
400 else {
401 table_entry =
402 intable(md5sum_str, &h300pairs[0],
403 sizeof(h300pairs)/sizeof(struct sumpairs));
404 if (table_entry >= 0)
405 series = 300;
406 }
385 } 407 }
386 if (series == 0) { 408 if (series == 0) {
387 MessageBox(NULL, TEXT("Unrecognised firmware"), TEXT("Fail"), MB_OK); 409 MessageBox(NULL, TEXT("Unrecognised firmware"), TEXT("Fail"), MB_OK);