Skip to content

Commit 811c359

Browse files
committed
meizu_dfu: supports a single argument to run some code from RAM
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26708 a1c6a512-1295-4272-9138-f99709370657
1 parent 592324e commit 811c359

File tree

2 files changed

+60
-47
lines changed

2 files changed

+60
-47
lines changed

utils/meizu_dfu/README

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
Meizu DFU tool for Linux
32

43
This tool can restore the firmware on M3, M6 SP, M6 TP and M6 SL.
4+
It can also run a single provided file from RAM.
55

66
Notes:
77
1. SST39VF800.dfu is taken from the official dfu tool provided by Meizu.
88
2. updateNAND_BE_070831.dfu is taken from the unofficial dfu tool for M6 SL.
99
3. To compile, just run `make'.
10-

utils/meizu_dfu/meizu_dfu.c

+59-45
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343

4444
void usage()
4545
{
46-
fprintf(stderr, "usage: meizu_dfu m3 <SST39VF800.dfu> <M3.EBN>\n");
47-
fprintf(stderr, " meizu_dfu m6 <SST39VF800.dfu> <M6.EBN>\n");
48-
fprintf(stderr, " meizu_dfu m6sl <updateNAND_BE_070831.dfu> <M6SL.EBN>\n");
46+
fprintf(stderr, "usage: meizu_dfu m3 [SST39VF800.dfu] <M3.EBN>\n");
47+
fprintf(stderr, " meizu_dfu m6 [SST39VF800.dfu] <M6.EBN>\n");
48+
fprintf(stderr, " meizu_dfu m6sl [updateNAND_BE_070831.dfu] <M6SL.EBN>\n");
4949
exit(1);
5050
}
5151

@@ -328,33 +328,39 @@ void dfu_m3_m6(char *file1, char *file2)
328328
memcpy(attr1.suf_sig, "RON", 3);
329329
attr1.suf_len = 0x10;
330330

331-
attr2.delay = 1000;
332-
attr2.pre_off = 0x20;
333-
attr2.pre_sig = 0x44465543;
334-
attr2.suf_dev = 0x0100;
335-
attr2.suf_prod = 0x0140;
336-
attr2.suf_ven = 0x0419;
337-
attr2.suf_dfu = 0x0100;
338-
memcpy(attr2.suf_sig, "UFD", 3);
339-
attr2.suf_len = 0x10;
340-
341331
init_img(&img1, file1, &attr1);
342-
init_img(&img2, file2, &attr2);
332+
333+
if (file2) {
334+
attr2.delay = 1000;
335+
attr2.pre_off = 0x20;
336+
attr2.pre_sig = 0x44465543;
337+
attr2.suf_dev = 0x0100;
338+
attr2.suf_prod = 0x0140;
339+
attr2.suf_ven = 0x0419;
340+
attr2.suf_dfu = 0x0100;
341+
memcpy(attr2.suf_sig, "UFD", 3);
342+
attr2.suf_len = 0x10;
343+
344+
init_img(&img2, file2, &attr2);
345+
}
343346

344347
device = usb_dev_open(USB_VID_SAMSUNG, USB_PID_M3_M6);
345348
// usb_mimic_windows();
346349
get_cpu(device);
347350
get_cpu(device);
348351
send_file(device, &img1);
349352

350-
printf("Wait a sec (literally)...");
351-
sleep(1);
352-
printf(" OK\n");
353+
if (file2) {
354+
printf("Wait a sec (literally)...");
355+
sleep(1);
356+
printf(" OK\n");
357+
358+
clear_status(device);
359+
get_cpu(device);
360+
send_file(device, &img2);
361+
dfu_detach(device);
362+
}
353363

354-
clear_status(device);
355-
get_cpu(device);
356-
send_file(device, &img2);
357-
dfu_detach(device);
358364
usb_dev_close(device);
359365
}
360366

@@ -374,51 +380,59 @@ void dfu_m6sl(char *file1, char *file2)
374380
memcpy(attr1.suf_sig, "UFD", 3);
375381
attr1.suf_len = 0x10;
376382

377-
attr2.delay = 1000;
378-
attr2.pre_off = 0x20;
379-
attr2.pre_sig = 0x44465543;
380-
attr2.suf_dev = 0x0100;
381-
attr2.suf_prod = 0x0140;
382-
attr2.suf_ven = 0x0419;
383-
attr2.suf_dfu = 0x0100;
384-
memcpy(attr2.suf_sig, "UFD", 3);
385-
attr2.suf_len = 0x10;
386-
387383
init_img(&img1, file1, &attr1);
388-
init_img(&img2, file2, &attr2);
384+
385+
if (file2) {
386+
attr2.delay = 1000;
387+
attr2.pre_off = 0x20;
388+
attr2.pre_sig = 0x44465543;
389+
attr2.suf_dev = 0x0100;
390+
attr2.suf_prod = 0x0140;
391+
attr2.suf_ven = 0x0419;
392+
attr2.suf_dfu = 0x0100;
393+
memcpy(attr2.suf_sig, "UFD", 3);
394+
attr2.suf_len = 0x10;
395+
396+
init_img(&img2, file2, &attr2);
397+
}
389398

390399
device = usb_dev_open(USB_VID_SAMSUNG, USB_PID_M6SL);
391400
get_cpu(device);
392401
get_cpu(device);
393402
send_file(device, &img1);
394403

395-
printf("Wait a sec (literally)...");
396-
sleep(1);
397-
printf(" OK\n");
398-
usb_dev_close(device);
404+
if (file2) {
405+
printf("Wait a sec (literally)...");
406+
sleep(1);
407+
printf(" OK\n");
408+
usb_dev_close(device);
409+
410+
device = usb_dev_open(USB_VID_SAMSUNG, USB_PID_M6SL);
411+
get_cpu(device);
412+
get_cpu(device);
413+
send_file(device, &img2);
414+
dfu_detach(device);
415+
}
399416

400-
device = usb_dev_open(USB_VID_SAMSUNG, USB_PID_M6SL);
401-
get_cpu(device);
402-
get_cpu(device);
403-
send_file(device, &img2);
404-
dfu_detach(device);
405417
usb_dev_close(device);
406418
}
407419

408420

409421
int main(int argc, char **argv)
410422
{
411-
if (argc != 4)
423+
if (argc < 3 || argc > 4)
412424
usage();
413425

414426
setvbuf(stdout, NULL, _IONBF, 0);
415427

428+
char *second_file = (argc == 4) ? argv[3] : NULL;
429+
416430
if (!strcmp(argv[1], "m3"))
417-
dfu_m3_m6(argv[2], argv[3]);
431+
dfu_m3_m6(argv[2], second_file);
418432
else if (!strcmp(argv[1], "m6"))
419-
dfu_m3_m6(argv[2], argv[3]);
433+
dfu_m3_m6(argv[2], second_file);
420434
else if (!strcmp(argv[1], "m6sl"))
421-
dfu_m6sl(argv[2], argv[3]);
435+
dfu_m6sl(argv[2], second_file);
422436
else
423437
usage();
424438

0 commit comments

Comments
 (0)