-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFlashTerminal.py
More file actions
executable file
·1196 lines (1069 loc) · 55.9 KB
/
FlashTerminal.py
File metadata and controls
executable file
·1196 lines (1069 loc) · 55.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
## Information #########################################################################################################
splash = '''
Motorola Flash Terminal Utility v1.0
A Flash Terminal utility for various Motorola phones using Motorola Flash Protocol.
Python:
3.6+
License:
MIT
Flags:
-v - Verbose USB packets
-r - Reboot device
-l - Upload RAMDLD to RAM
-s - Switch device to Flash Mode (Bootloader Mode)
-2 - Use second USB interface for BP Bootloader
-p - Do some P2K stuff (MEMACS, P2K_INFO, FILES_DUMP)
-at_skip - Skip AT => P2K switching
-at_usb - Use AT USB writing instead of /dev/ttyACM0 writing
-h - Show help
Developers and Thanks:
- EXL, usernameak, kraze1984, dffn3, Vilko, Evy, motoprogger, b1er, dion, whoever, muromec
- MotoFan.Ru developers
- ROMphonix developers
- PUNK-398, asdf, wavvy01, diokhann, metalman87, ahsim2009, greyowls, Ivan_Fox, kostett
- SGXVII, NextG50, ronalp, CrayZor, Paschendale, fkcoder, overglube, MC4f, regenfaellt
- Den K, WN3DL, tfa8, EINEX, BonfireCZ, Neko-mata, LNRC (Unabandonware), vinnyboombottzz
- Daniel Linhart, xkonstantin
10-May-2024, Siberia
'''
## Imports #############################################################################################################
import os
import sys
import time
import serial
import logging
import usb.core
import usb.util
## Settings ############################################################################################################
usb_devices = [
{'usb_vid': 0x22B8, 'usb_pid': 0x2823, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM5100'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2A03, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM6050'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2A23, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM6100'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2B43, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM6125'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2A63, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM6500/MSM6800'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2B23, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM6550'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2C63, 'mode': 'flash', 'desc': 'Motorola PCS Flash MSM6575/MSM6800'},
{'usb_vid': 0x22B8, 'usb_pid': 0x1801, 'mode': 'flash', 'desc': 'Motorola PCS Flash Rainbow/Rainbow POG'},
{'usb_vid': 0x22B8, 'usb_pid': 0x4903, 'mode': 'flash', 'desc': 'Motorola PCS Flash LTE/LTE2/LTE2 irom0400'},
{'usb_vid': 0x22B8, 'usb_pid': 0x3803, 'mode': 'flash', 'desc': 'Motorola PCS Flash LT'},
{'usb_vid': 0x22B8, 'usb_pid': 0x4803, 'mode': 'flash', 'desc': 'Motorola PCS Flash LTS'},
{'usb_vid': 0x22B8, 'usb_pid': 0x5803, 'mode': 'flash', 'desc': 'Motorola PCS Flash ULS'},
{'usb_vid': 0x22B8, 'usb_pid': 0x1001, 'mode': 'flash', 'desc': 'Motorola PCS Flash Patriot'},
{'usb_vid': 0x22B8, 'usb_pid': 0x0001, 'mode': 'flash', 'desc': 'Motorola PCS Flash Wally'},
{'usb_vid': 0x22B8, 'usb_pid': 0x6003, 'mode': 'flash', 'desc': 'Motorola PCS Flash Dalhart'},
{'usb_vid': 0x22B8, 'usb_pid': 0x6008, 'mode': 'flash', 'desc': 'Motorola PCS Flash Dalhart RAMDLD'},
{'usb_vid': 0x22B8, 'usb_pid': 0x6023, 'mode': 'flash', 'desc': 'Motorola PCS Flash Bulverde'},
{'usb_vid': 0x22B8, 'usb_pid': 0x6403, 'mode': 'flash', 'desc': 'Motorola PCS Flash ArgonLV/SCM-A11'},
{'usb_vid': 0x22B8, 'usb_pid': 0x6460, 'mode': 'flash', 'desc': 'Motorola PCS Flash Argon+'}, # M702iG
{'usb_vid': 0x22B8, 'usb_pid': 0x6461, 'mode': 'flash', 'desc': 'Motorola PCS Flash Argon?'}, # M702iS
{'usb_vid': 0x22B8, 'usb_pid': 0x6463, 'mode': 'flash', 'desc': 'Motorola PCS Flash Argon?'}, # M704i
{'usb_vid': 0x22B8, 'usb_pid': 0x2D33, 'mode': 'flash', 'desc': 'Motorola PCS Flash Rhodes'},
{'usb_vid': 0x22B8, 'usb_pid': 0xBEEF, 'mode': 'flash', 'desc': 'Motorola PCS Flash Bulverde (gen-blob)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x405F, 'mode': 'flash', 'desc': 'Motorola PCS Flash ESPOO/HELSINKI Z8/Z10'},
{'usb_vid': 0x22B8, 'usb_pid': 0x41B3, 'mode': 'flash', 'desc': 'Motorola PCS Flash TI NEPTUNE'},
{'usb_vid': 0x22B8, 'usb_pid': 0x3002, 'mode': 'at', 'desc': 'Motorola PCS A835/E1000 GSM Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x3001, 'mode': 'p2k', 'desc': 'Motorola PCS A835/E1000 GSM Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x1C02, 'mode': 'at', 'desc': 'Motorola PCS Siemens Phone U10 (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x1C01, 'mode': 'p2k', 'desc': 'Motorola PCS Siemens Phone U10 (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x4902, 'mode': 'at', 'desc': 'Motorola PCS Triplet GSM Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x4901, 'mode': 'p2k', 'desc': 'Motorola PCS Triplet GSM Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x5802, 'mode': 'at', 'desc': 'Motorola PCS C350L Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x5801, 'mode': 'p2k', 'desc': 'Motorola PCS C350L Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x1005, 'mode': 'at', 'desc': 'Motorola PCS V60 Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x1001, 'mode': 'p2k', 'desc': 'Motorola PCS V60 Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x3802, 'mode': 'at', 'desc': 'Motorola PCS EZX Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x6009, 'mode': 'p2k', 'desc': 'Motorola PCS EZX Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x0005, 'mode': 'at', 'desc': 'Motorola PCS V120c Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x0001, 'mode': 'p2k', 'desc': 'Motorola PCS V120c Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2822, 'mode': 'at', 'desc': 'Motorola PCS V120e Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2821, 'mode': 'p2k', 'desc': 'Motorola PCS V120e Phone (P2K)'},
{'usb_vid': 0x1907, 'usb_pid': 0x0001, 'mode': 'at', 'desc': 'Elcoteq Mosel GSM Phone (AT)'},
{'usb_vid': 0x1907, 'usb_pid': 0x0002, 'mode': 'p2k', 'desc': 'Elcoteq Mosel GSM Phone (P2K)'},
{'usb_vid': 0x11F5, 'usb_pid': 0x0007, 'mode': 'at', 'desc': 'Siemens CC75 GSM Phone (AT)'},
{'usb_vid': 0x11F5, 'usb_pid': 0x0008, 'mode': 'p2k', 'desc': 'Siemens CC75 GSM Phone (P2K)'},
{'usb_vid': 0x11F5, 'usb_pid': 0x0008, 'mode': 'flash', 'desc': 'Siemens CC75 GSM Phone (Flash)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2D34, 'mode': 'at', 'desc': 'Motorola PCS Rhodes Phone (AT)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x2D31, 'mode': 'p2k', 'desc': 'Motorola PCS Rhodes Phone (P2K)'},
{'usb_vid': 0x22B8, 'usb_pid': 0x640B, 'mode': 'at', 'desc': 'Motorola PCS FOMA M704i (AT)'},
]
modem_speed = 115200
modem_device = '/dev/ttyACM0'
at_command = 'AT'
p2k_mode_command = 'AT+MODE=8'
p2k_command_list = 'P2kCommandList.txt'
delay_ack = 0.00
delay_switch = 8.00
delay_jump = 1.00
timeout_read = 5000
timeout_write = 5000
buffer_write_size = 0x2000
buffer_read_size = 0x2000
## Worksheets ##########################################################################################################
def worksheet(er, ew):
er, ew = usb_check_restart_phone(er, ew, '-r' in sys.argv)
# Various single commands.
# mfp_cmd(er, ew, 'RQHW')
# mfp_cmd(er, ew, 'RQVN')
# mfp_cmd(er, ew, 'RQSW')
# mfp_cmd(er, ew, 'RQSN')
# mfp_cmd(er, ew, 'POWER_DOWN')
# mfp_addr(er, ew, 0x00100000)
if '-l' in sys.argv:
# Upload RAMDLD to phone and wait for RAMDLD start.
logging.debug('Uploading RAMDLD to phone and wait for RAMDLD start.')
check_and_load_ezx_ap_bp_ramdlds(er, ew)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3m_RAMDLD_010C.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3m_RAMDLD_010C_Patched_Dump_SRAM.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3m_RAMDLD_010C_Patched_Dump_NAND.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/K1m_RAMDLD_0013_Patched_Dump_NAND.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/K1mm_RAMDLD_000D_Patched_Dump_NAND.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V325i_RAMDLD_010A_Patched_Dump_NAND.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V9m_RAMDLD_01B5.ldr', 0x00100000, 0x00100000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V9m_RAMDLD_01B5_Patched_Dump_SRAM.ldr', 0x00100000, 0x00100000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V9m_RAMDLD_01B5_Patched_Dump_NAND.ldr', 0x00100000, 0x00100000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/QA30_RAMDLD_0206_Patched_Dump_SRAM.ldr', 0x002F0000, 0x002F0000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/QA30_RAMDLD_0206_Patched_Dump_NAND.ldr', 0x002F0000, 0x002F0000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/QA30_RAMDLD_0206_Patched_Dump_NAND_WIDE.ldr', 0x002F0000, 0x002F0000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A830_RAMDLD_0520_Patched_Dump_NOR.ldr', 0x07800000, 0x07800010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/E398_RAMDLD_07B0_Hacked_Dump.ldr', 0x03FD0000, 0x03FD0010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/L6_RAMDLD_08D5_RSA_Read.ldr', 0x03FD0000, 0x03FD0010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/E1000_RAMDLD_0610.ldr', 0x07804000, 0x07804010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V980_32M_RAMDLD_0636.ldr', 0x08000000, 0x08000010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3x_RAMDLD_0682_RSA_Read.ldr', 0x08000000, 0x08000010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A1000_BP_RAMDLD_0651_RSA_Read.ldr', 0x08000000, 0x08000010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A835_RAMDLD_0612_Hacked_RSA_Read.ldr', 0x08000000, 0x08018818)
# mfp_uls_upload(er, ew, 'loaders/C350L_RAMDLD_0000_Patched_Dump_NOR.ldr', 0x12000000, 0x1000, False)
# mfp_upload_binary_to_addr(er, ew, 'loaders/E380_RAMDLD_0910_Hacked_Dump.ldr', 0x01FD0000, 0x01FD0010)
# mfp_uls_upload(er, ew, 'loaders/E380_RAMDLD_Blank.ldr', 0x01FD0000, 0x1000, False)
# mfp_uls_upload(er, ew, 'loaders/E380_RAMDLD_Hacked_RQHW.ldr', 0x01FD0000, 0x1000, False)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V60_RAMDLD_0355_Patched_Dump_NOR.ldr', 0x11010000, 0x11010010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V60i_RAMDLD_1007_Patched_Dump_NOR.ldr', 0x11010000, 0x11010010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/T720_RAMDLD_0370_Patched_Dump_NOR.ldr', 0x11010000, 0x11010010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/T722i_RAMDLD_0380.ldr', 0x11010000, 0x11010010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V120e_RAMDLD_0713_Patched_Dump_NOR.ldr', 0x01010000, 0x01010000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V120c_RAMDLD_0312_Patched_Dump_NOR.ldr', 0x41008000, 0x41008010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/W315_RAMDLD_0106_Patched_Dump_NOR.ldr', 0x14010000, 0x14010000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3re_RAMDLD_0CC1.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3re_RAMDLD_RFDI_0CF4.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/K1s_RAMDLD_0DC0.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/L72_RAMDLD_0C70.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/U3_RAMDLD_0CF0.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/K3_RAMDLD_0320.ldr', 0x80000000, 0x80000038, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V9_RAMDLD_R263313_05F4.ldr', 0x80000000, 0x80000038, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/VE70_RAMDLD_0101.ldr', 0x00800000, 0x00800078, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/VE70_RAMDLD_0101_Patched_Dump_NAND.ldr', 0x00800000, 0x00800078, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/VE70_RAMDLD_0101_Patched_Dump_NAND_WIDE.ldr', 0x00800000, 0x00800078, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/VE66_RAMDLD_0905.ldr', 0x90500000, 0x90500038, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A910_BP_RAMDLD_0912.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A910i_BP_RAMDLD_0982.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/M702iG_RAMDLD_0303.ldr', 0x80000000, 0x80000038, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/M702iS_RAMDLD_0303.ldr', 0x80000000, 0x80000038, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Hitagi_LTE1_AMD_16.ldr', 0x03FD0000, 0x03FD0010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Hitagi_LTE1_Intel_16.ldr', 0x03FD0000, 0x03FD0010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Hitagi_LTE2_Intel_16.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Hitagi_LTE1_Compact_Intel_16.ldr', 0x03FD0000, 0x03FD0010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Hitagi_LTE2_Compact_Intel_16.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Z6c_RAMDLD_000D.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/Z6c_RAMDLD_000D_Patched_Dump_NAND.ldr', 0x00100000, 0x00100000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/E1_RAMDLD_0A20_Patched_Dump_NOR.ldr', 0x03FD0000, 0x03FD0010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V3e_RAMDLD_0A40.ldr', 0x03FC8000, 0x03FC8010, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/V710_RAMDLD_0807_Patched_Dump_NOR.ldr', 0x10020000, 0x10020000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/C350LTS_RAMDLD_0920.ldr', 0x03FA0000, 0x03FA0010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/C350LTS_RAMDLD_0920_Patched_Dump_NOR.ldr', 0x03FA0000, 0x03FA0010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/RHODES_RAMDLD_0000.ldr', 0x00150000, 0x00150000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/RHODES_RAMDLD_0000_Patched_Dump_NAND.ldr', 0x00150000, 0x00150000, True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/RHODES_RAMDLD_0000_Patched_Dump_NAND_WIDE.ldr', 0x00150000, 0x00150000, True)
# mfp_uls_upload(er, ew, 'loaders/Hitagi_LTS1_Intel_16.ldr', 0x03FD0010, 0x1000, False)
mfp_upload_binary_to_addr(er, ew, 'loaders/A45_RAMDLD_02B0.ldr', 0x10000000, 0x10000000, True)
# Commands executed on Bootloader or RAMDLD (if loaded) side.
# mfp_cmd(er, ew, 'RQHW')
# mfp_cmd(er, ew, 'RQSW')
# mfp_cmd(er, ew, 'RQVN')
# mfp_cmd(er, ew, 'RQSN')
# mfp_cmd(er, ew, 'RQFI')
# mfp_cmd(er, ew, 'READ_OTP')
# mfp_cmd(er, ew, 'RESTART')
# mfp_cmd(er, ew, 'RQRC', '10000000,10000400'.encode())
# mfp_cmd(er, ew, 'RQRC', '60000000,60000010,00000000'.encode())
# mfp_cmd(er, ew, 'DUMP', '10000000'.encode())
# Hitagi Custom RAMDLD.
# mfp_cmd(er, ew, 'ERASE')
# mfp_cmd(er, ew, 'ERASE')
# mfp_cmd(er, ew, 'ERASE')
# mfp_upload_binary_to_addr(er, ew, 'WRITE.bin', 0x10000000, None)
# mfp_dump_read(er, ew, 'READ.bin', 0x10000000, 0x12000000, 0x100)
# Dump SRAM and NOR flash.
# mfp_dump_sram(er, ew, 'V9m_SRAM_Dump.bin', 0x00000000, 0x00004000, 0x30)
# mfp_dump_sram(er, ew, 'V9m_SRAM_Dump.bin', 0x00000000, 0x04000000, 0x30)
# mfp_dump_sram(er, ew, 'V9m_SRAM_Dump.bin', 0x00000000, 0x08000000, 0x30)
# mfp_dump_sram(er, ew, 'MSM_IRAM_Dump.bin', 0xFFFF0000, 0xFFFFFFFF, 0x10)
# mfp_dump_sram(er, ew, 'U10_ROM_Dump.bin', 0x10000000, 0x11000000, 0x30)
# mfp_dump_sram(er, ew, 'A830_IROM_Dump.bin', 0x00000000, 0x00010000, 0x30)
# mfp_dump_dump(er, ew, 'E398_ROM_Dump.bin', 0x10000000, 0x12000000, 0x100)
# mfp_dump_dump(er, ew, 'E398_IROM_Dump.bin', 0x00000000, 0x00200000, 0x100)
# mfp_dump_read(er, ew, 'L6_ROM_Dump.bin', 0x10000000, 0x12000000, 0x100)
# mfp_dump_rqrc(er, ew, 'E1000_PDS_ROM_Dump.bin', 0x10010000, 0x10030000)
# mfp_dump_read(er, ew, 'V3x_ROM_Dump.bin', 0x10000000, 0x14000000, 0x100)
# mfp_dump_sram(er, ew, 'C350L_ROM_Dump.bin', 0x10000000, 0x10800000, 0x30)
# mfp_dump_sram(er, ew, 'C350L_IROM_Dump.bin', 0x00000000, 0x00040000, 0x30)
# mfp_dump_dump(er, ew, 'C350_ROM_Dump.bin', 0x00000000, 0x00800000, 0x100)
# mfp_dump_dump(er, ew, 'C350_IROM_Dump.bin', 0x10000000, 0x10400000, 0x100)
# mfp_dump_dump(er, ew, 'C550_ROM_Dump.bin', 0x00000000, 0x01000000, 0x100)
# mfp_dump_sram(er, ew, 'V60_ROM_Dump.bin', 0x10000000, 0x10400000, 0x30)
# mfp_dump_sram(er, ew, 'V60_IROM_Dump.bin', 0x00000000, 0x00400000, 0x30)
# mfp_dump_sram(er, ew, 'V70_ROM_Dump.bin', 0x10000000, 0x10800000, 0x30)
# mfp_dump_sram(er, ew, 'V120e_ROM_Dump.bin', 0x00000000, 0x00500000, 0x30) # 4 MiB + 1 MiB
# mfp_dump_sram(er, ew, 'T720_IROM_Dump.bin', 0x00000000, 0x00400000, 0x30)
# mfp_dump_sram(er, ew, 'T720_ROM_Dump.bin', 0x10000000, 0x10800000, 0x30)
# mfp_dump_sram(er, ew, 'V120c_IROM_Dump.bin', 0x00000000, 0x00400000, 0x30)
# mfp_dump_sram(er, ew, 'V120c_ROM_Dump.bin', 0x40000000, 0x40400000, 0x30)
# mfp_dump_sram(er, ew, 'W315_ROM_Dump.bin', 0x00000000, 0x01000000, 0x30)
# mfp_dump_sram(er, ew, 'A760_AP_ROM_Dump.bin', 0x00000000, 0x02000000, 0x30)
# mfp_dump_sram(er, ew, 'A760_BP_ROM_Dump.bin', 0x00000000, 0x00400000, 0x30)
# mfp_dump_sram(er, ew, 'A760_BP_IROM_Dump.bin', 0x10000000, 0x10400000, 0x30)
# mfp_dump_read(er, ew, 'A768i_BP_ROM_Dump.bin', 0x00000000, 0x00400000, 0x400)
# mfp_dump_read(er, ew, 'A768i_BP_IROM_Dump.bin', 0x10000000, 0x10400000, 0x400)
# mfp_dump_read(er, ew, 'A780_BP_ROM_Dump.bin', 0x00000000, 0x00400800, 0x400)
# mfp_dump_read(er, ew, 'A780_BP_IROM_Dump.bin', 0x10000000, 0x10400800, 0x400)
# mfp_dump_read(er, ew, 'A1000_ROM_Dump.bin', 0x10000000, 0x11000000, 0x100)
# mfp_dump_rqrc(er, ew, 'A1000_PDS_ROM_Dump.bin', 0x10010000, 0x10020000)
# mfp_dump_read(er, ew, 'V3re_ROM_Dump.bin', 0x10000000, 0x12000000, 0x100)
# mfp_dump_read(er, ew, 'L9_ROM_Dump.bin', 0x10000000, 0x14000000, 0x100)
# mfp_dump_read(er, ew, 'U3_ROM_Dump.bin', 0x10000000, 0x12000000, 0x100)
# mfp_dump_read(er, ew, 'K3_ROM_Dump_1.bin', 0xA0000000, 0xA2000000, 0x300)
# mfp_dump_read(er, ew, 'K3_ROM_Dump_2.bin', 0xB4000000, 0xB6000000, 0x300)
# mfp_dump_read(er, ew, 'V9_ROM_Dump.bin', 0xA0000000, 0xA4000000, 0x200)
# mfp_dump_read(er, ew, 'A910_BP_ROM_Dump.bin', 0x10000000, 0x10400000, 0x100)
# mfp_dump_rbin(er, ew, 'A910_AP_ROM_Dump.bin', 0x00000000, 0x04000000, 0x1000)
# mfp_dump_rqrc(er, ew, 'M701iG_IROM_Dump_1.bin', 0x00000000, 0x00004000)
# mfp_dump_rqrc(er, ew, 'M701iG_IROM_Dump_2.bin', 0x00404000, 0x00408000)
# mfp_dump_read(er, ew, 'M701iG_ROM_Dump_1.bin', 0xA0000000, 0xA2000000, 0x300)
# mfp_dump_read(er, ew, 'M701iG_ROM_Dump_2.bin', 0xB4000000, 0xB6000000, 0x300)
# mfp_dump_read(er, ew, 'M702iS_ROM_Dump_1.bin', 0xA0000000, 0xA0040000, 0x200) # Skip PDS.
# mfp_dump_read(er, ew, 'M702iS_ROM_Dump_2.bin', 0xA0080000, 0xA2000000, 0x200) # Skip PDS.
# mfp_dump_read(er, ew, 'M702iS_ROM_Dump_3.bin', 0xB4000000, 0xB6000000, 0x200)
# mfp_dump_read(er, ew, 'V980_ROM_Dump.bin', 0x10000000, 0x12000000, 0x100)
# mfp_dump_read(er, ew, 'A1600_BP_ROM_Dump.bin', 0x10000000, 0x10400000, 0x100)
# mfp_dump_rqhw(er, ew, 'E380_ROM_Dump.bin', 0x10000000, 0x11000000, 'RQSN')
# mfp_dump_read(er, ew, 'V3i_ROM_Dump.bin', 0x10000000, 0x13000000, 0x100)
# mfp_dump_rqhw(er, ew, 'V710_ROM_Dump.bin', 0x00000000, 0x02000000, 'RQSN')
# mfp_dump_read(er, ew, 'Z10_ROM_Dump.bin', 0xA0000000, 0xA2000000, 0x200)
# mfp_dump_rqhw(er, ew, 'C350LTS_ROM_Dump.bin', 0x10000000, 0x10800000, 'RQSN')
mfp_dump_read(er, ew, 'A45_NOR_Dump.bin', 0x0C000000, 0x0FFFFFFF, 0x100)
mfp_dump_read(er, ew, 'A45_NAND_Dump.bin', 0x04000000, 0x07FFFFFF, 0x100)
# Motorola A835/A845 dumping tricks.
# mfp_cmd(er, ew, 'RQHW')
# mfp_binary_cmd(er, ew, b'\x00\x00\x05\x70', False)
# mfp_upload_raw_binary(er, ew, 'loaders/A835_Additional_Payload_1.bin', None, False)
# mfp_upload_raw_binary(er, ew, 'loaders/A835_Additional_Payload_2.bin')
# mfp_binary_cmd(er, ew, b'\x53\x00\x00\x00\x00\x00\x00\xA0\x00')
# mfp_binary_cmd(er, ew, b'\x41')
# mfp_dump_r(er, ew, 'A835_ROM_Dump.bin', 0x10000000, 0x11000000, 0x100)
# mfp_dump_r(er, ew, 'A835_IROM_Dump.bin', 0x00000000, 0x00010000, 0x100)
# mfp_dump_r(er, ew, 'C975_ROM_Dump.bin', 0x10000000, 0x12000000, 0x100)
# mfp_dump_r(er, ew, 'E1000_ROM_Dump.bin', 0x10000000, 0x14000000, 0x100)
# Dump NAND data (64 MiB / 128 MiB / 256 MiB) and spare area.
# Chunks are 528 bytes == 512 bytes is NAND page size + 16 bytes is NAND spare area.
# mfp_dump_nand(er, ew, 'Z6m_NAND_Dump.bin', 0, int(0x04000000 / 512), 0x30)
# mfp_dump_nand(er, ew, 'Z6c_NAND_Dump.bin', 0, int(0x08000000 / 512), 0x30)
# mfp_dump_nand(er, ew, 'V9m_NAND_Dump.bin', 0, int(0x08000000 / 512), 0x30)
# mfp_dump_nand(er, ew, 'VE40_NAND_Dump.bin', 0, int(0x08000000 / 512), 0x10)
# mfp_dump_nand(er, ew, 'ic902_NAND_Dump.bin', 0, int(0x08000000 / 512), 0x10)
# mfp_dump_nand(er, ew, 'QA30_NAND_Dump.bin', 0, int(0x04000000 / 512), 0x10, 4)
# mfp_dump_nand(er, ew, 'V3m_NAND_Dump.bin', 0, int(0x04000000 / 512), 0x10, 1, 0x64000000)
# mfp_dump_nand(er, ew, 'K1m_NAND_Dump.bin', 0, int(0x04000000 / 512), 0x10, 1, 0x64000000)
# mfp_dump_nand(er, ew, 'V325i_NAND_Dump.bin', 0, int(0x04000000 / 512), 0x10, 1, 0x64000000)
# Motorola C350L full 8 MiB ROM flashing! Please set timeout_read/timeout_write to 600000 (10 min)!
# mfp_cmd(er, ew, 'ERASE')
# mfp_upload_binary_to_addr(er, ew, 'С350L_ROM_Dump_8M.bin', 0x10000000, None)
# Siemens CC75 on Spansion flash memory chip flashing and reading!
# mfp_cmd(er, ew, 'ERASE')
# mfp_cmd(er, ew, 'ERASE')
# mfp_cmd(er, ew, 'ERASE')
# mfp_upload_binary_to_addr(er, ew, 'CC75_ROM_Dump.bin', 0x10000000, None)
# mfp_dump_read(er, ew, 'CC75_ROM_Dump.bin', 0x10000000, 0x12000000, 0x200)
def check_and_load_ezx_ap_bp_ramdlds(er, ew):
if not '-2' in sys.argv:
# EZX AP
# mfp_upload_binary_to_addr(er, ew, 'loaders/A760_AP_RAMDLD_0000_Patched_Dump_NOR.ldr', 0xA0200000, 0xA0200000, ezx_ap=True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A768i_AP_RAMDLD_0000_Patched_Dump_NOR.ldr', 0xA0200000, 0xA0200000, ezx_ap=True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A780g_AP_RAMDLD_0000.ldr', 0xA0200000, 0xA0200000, ezx_ap=True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/E680i_AP_RAMDLD_0000.ldr', 0xA0200000, 0xA0200000, ezx_ap=True)
# EZX AP Set Flag (command-line arguments)
# mfp_upload_binary_to_addr(er, ew, 'loaders/gen-blob/head.bin', 0xA1000000)
# mfp_upload_binary_to_addr(er, ew, 'loaders/gen-blob/blob-a780', 0xA0DE0000, 0xA0DE0000, ezx_ap=True)
# mfp_upload_binary_to_addr(er, ew, 'loaders/gen-blob/blob-a1200', 0xA0DE0000, 0xA0DE0000, ezx_ap=True)
pass
else:
# EZX BP
# mfp_upload_binary_to_addr(er, ew, 'loaders/A760_BP_RAMDLD_0372_Patched_Dump_NOR.ldr', 0x11060000, 0x11060010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A768i_BP_RAMDLD_0731_Patched_Dump_NOR.ldr', 0x12000000, 0x12000010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/A780g_BP_RAMDLD_08A0.ldr', 0x03FD0000, 0x03FD0010)
# mfp_upload_binary_to_addr(er, ew, 'loaders/E680i_BP_RAMDLD_08A0.ldr', 0x03FD0000, 0x03FD0010)
pass
def worksheet_p2k(p2k_usb_device):
# p2k_do_memacs_dump(p2k_usb_device, 'E398_MEMACS_DUMP.bin', 0x10000000, 0x12000000, 0x800)
# p2k_do_info_dump(p2k_usb_device, 'E398_P2KINFO_DUMP.txt')
# p2k_do_dump_files(p2k_usb_device, 'a')
return True
## Motorola Test Command Interface (P2K) Protocol ######################################################################
def p2k_save_file(p2k_usb_device, index, file_info):
logging.info(f'Dumping "{file_info[0]}" file of {file_info[1]} bytes size...')
# Open file with previous flags.
# 04 FC 00 4A 00 17 00 00 00 00 00 00 00 00 00 04 .ь.J..........$.
# 2F 61 2F 56 69 62 5F 64 61 73 68 2E 77 61 76 /a/Vib_dash.wav
packet_name_size = 0x10 + len(file_info[0]) - 8
ctrl_packet = int.to_bytes(index, 2, 'big') + b'\x00\x4A' + int.to_bytes(packet_name_size, 2, 'big') + \
b'\x00\x00\x00\x00\x00\x00\x00\x00' + int.to_bytes(file_info[3], 2, 'big') + file_info[0].encode('CP1251')
p2k_cmd_execute(p2k_usb_device, ctrl_packet)
# Seek file to start.
# 04 FE 00 4A 00 09 00 00 00 00 00 03 00 00 00 00 00
ctrl_packet = int.to_bytes(index + 2, 2, 'big') + b'\x00\x4A\x00\x09\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00'
p2k_cmd_execute(p2k_usb_device, ctrl_packet)
# Write file to disk.
# 05 00 00 4A 00 08 00 00 00 00 00 01 00 00 04 00
# 05 00 00 4A 00 08 00 00 00 00 00 01 00 00 01 78
step = 2
directory = '.' + os.path.dirname(file_info[0])
os.makedirs(directory, exist_ok=True)
with open('.' + file_info[0], 'wb') as file:
u = int(file_info[1] / 0x400)
d = int(file_info[1] % 0x400)
for i in range(0, u):
ctrl_packet = int.to_bytes(index + step, 2, 'big') + b'\x00\x4A\x00\x08\x00\x00\x00\x00\x00\x01' + \
int.to_bytes(0x400, 4, 'big')
result_data = p2k_cmd_execute(p2k_usb_device, ctrl_packet, None, True, True)
file.write(result_data)
step += 2
if d > 0:
ctrl_packet = int.to_bytes(index + step, 2, 'big') + b'\x00\x4A\x00\x08\x00\x00\x00\x00\x00\x01' + \
int.to_bytes(d, 4, 'big')
result_data = p2k_cmd_execute(p2k_usb_device, ctrl_packet, None, True, True)
file.write(result_data)
# Close file.
# 05 02 00 4A 00 04 00 00 00 00 00 04
ctrl_packet = int.to_bytes(index + (step * 2) + 2, 2, 'big') + b'\x00\x4A\x00\x04\x00\x00\x00\x00\x00\x04'
p2k_cmd_execute(p2k_usb_device, ctrl_packet)
def p2k_get_file_list(p2k_usb_device, index, disk):
ctrl_packet = int.to_bytes(index, 2, 'big') + b'\x00\x4A\x00\x05\x00\x00\x00\x00\x00\x08\x03'
path_size = 0x10C # 268 bytes.
# FIXME: Something nasty here.
answer_size = 0x330
files = []
while answer_size > 0x10:
result = p2k_cmd_execute(p2k_usb_device, ctrl_packet)
answer_size = len(result)
if answer_size > 0x10:
file_path_count = result[0]
for i in range(0, file_path_count):
start = 3
slice = result[start + i * path_size:(i * path_size) + path_size + start]
strings = bytes(slice).split(b'\x00')
files.append((
strings[0].decode('CP1251', errors='ignore'), # Path
int.from_bytes(slice[-4:], 'big'), # Size
int.from_bytes(slice[-6:-4], 'big'), # User
int.from_bytes(slice[-8:-6], 'big'), # Flags
))
return files
def p2k_disk_init(p2k_usb_device, index, disk):
ctrl_packet = int.to_bytes(index, 2, 'big') + b'\x00\x4A\x02\x00\x00\x00\x00\x00\x00\x0B\xFF\xFE\x00\x2F\x00' \
+ disk.encode() + (b'\x00' * 0x1E6) # 486
p2k_cmd_execute(p2k_usb_device, ctrl_packet)
ctrl_packet = int.to_bytes(index + 2, 2, 'big') + b'\x00\x4A\x00\x10\x00\x00\x00\x00\x00\x07\x00\x2F\x00' \
+ disk.encode() + b'\x00\x2F\xFF\xFE\x00\x2A\x00\x00'
p2k_cmd_execute(p2k_usb_device, ctrl_packet)
def p2k_get_volume_list(p2k_usb_device, index):
ctrl_packet = int.to_bytes(index, 2, 'big') + b'\x00\x4A\x00\x04\x00\x00\x00\x00\x00\x0A'
result = p2k_cmd_execute(p2k_usb_device, ctrl_packet)
volumes = []
for byte in result:
if byte >= 97 and byte <= 122: # Only lowercase ASCII check.
volumes.append(chr(byte))
logging.info(f'Phone disks are {volumes}!')
return volumes
def p2k_get_info(p2k_usb_device, index, feature, fixup=False):
# 00 0A 00 39 00 02 00 00 FF FF
# 00 0C 00 39 00 02 00 00 00 01
ctrl_packet = int.to_bytes(index, 2, 'big') + b'\x00\x39\x00\x02\x00\x00' + int.to_bytes(feature, 2, 'big')
return p2k_cmd_execute(p2k_usb_device, ctrl_packet, None, True, fixup)
def p2k_read_seem(p2k_usb_device, index, seem, rec, file_path=None):
# 00 06 00 20 00 08 00 00 01 17 00 01 00 00 00 00
# 00 08 00 20 00 08 00 00 01 7F 00 01 00 00 00 00
ctrl_packet = int.to_bytes(index, 2, 'big') + b'\x00\x20\x00\x08\x00\x00' + \
int.to_bytes(seem, 2, 'big') + int.to_bytes(rec, 2, 'big') + b'\x00\x00\x00\x00'
result_data = p2k_cmd_execute(p2k_usb_device, ctrl_packet)
if file_path:
with open(file_path, 'wb') as file:
file.write(result_data)
return bytes(result_data)
def p2k_memacs(p2k_usb_device, index, addr_s, step, file_path=None):
# MEMACS P2K Command.
# 00 02 00 16 00 08 00 00 10 00 00 00 08 00 00 00
# 00 03 00 16 00 08 00 00 10 00 08 00 08 00 00 00
ctrl_packet = int.to_bytes(index + 2, 2, 'big') + b'\x00\x16\x00\x08\x00\x00' + \
int.to_bytes(addr_s, 4, 'big') + int.to_bytes(step, 2, 'big') + b'\x00\x00'
return p2k_cmd_execute(p2k_usb_device, ctrl_packet)
def p2k_cmd_execute(p2k_usb_device, ctrl_packet, size=None, trim_usb_packet=True, fixup=False):
usb_additional_payload_size = 0x06
# Send control packet.
p2k_usb_device.ctrl_transfer(0x41, 0x02, 0x00, 0x08, ctrl_packet, timeout_write)
logging.debug(
f'>>> Send USB control packet '
f'(bmRequestType=0x41, bmRequest=0x02, wValue=0x00, wIndex=0x08) '
f'to device...\n{hexdump(ctrl_packet)}'
)
# Stabilization.
retry = 0
while not retry:
result = p2k_usb_device.ctrl_transfer(0xC1, 0x00, 0x00, 0x08, 0x08, timeout_read)
logging.debug(
f'>>> Send USB control packet '
f'(bmRequestType=0xC1, bmRequest=0x00, wValue=0x00, wIndex=0x08, size=0x08) to device...'
f'\nresult =\n{hexdump(result)}'
)
retry = int.from_bytes(result, 'little')
# Read count of packets and packet size.
usb_packet_count = int.from_bytes(result[:2], 'big')
usb_packet_size = int.from_bytes(result[2:], 'big')
logging.debug(
f'usb_packet_count={usb_packet_count}|0x{usb_packet_count:02X}, '
f'usb_packet_size={usb_packet_size}|0x{usb_packet_size:02X}'
)
if not size:
size = usb_packet_size + usb_additional_payload_size
# Read data.
result = p2k_usb_device.ctrl_transfer(0xC1, 0x01, 0x01, 0x08, size, timeout_read)
logging.debug(
f'>>> Send USB control packet '
f'(bmRequestType=0xC1, bmRequest=0x01, wValue=0x01, wIndex=0x08, size=0x{size:08X}) to device...'
f'\nresult =\n{hexdump(result)}'
)
if trim_usb_packet:
usb_packet_answer_header_size = size - int.from_bytes(result[10:12], 'big')
if not fixup:
usb_packet_answer_header_size += 1
result_data = result[usb_packet_answer_header_size:] # Drop first bytes from pipe answer.
else:
result_data = result
if (not result_data) or (len(result_data) == 0):
result_data = 'NO DATA'.encode()
return result_data
def p2k_do_dump_files(p2k_usb_device, disk, skip_files=[]):
logging.info(f'Dumping files from disk /{disk}/!')
volumes = p2k_get_volume_list(p2k_usb_device, 0x0002)
if disk not in volumes:
logging.error(f'There is no disk /{disk}/ in volumes {volumes} on the phone!')
return False
p2k_disk_init(p2k_usb_device, 0x0004, disk)
logging.info(f'Getting file list from disk /{disk}/...')
file_list = p2k_get_file_list(p2k_usb_device, 0x0008, disk)
file_list.sort()
str_list_files = ''
for file, size, user, flags in file_list:
str_list_files += f'{file} user=0x{user:02X} flags=0x{flags:02X} size={size} bytes.\n'
logging.info(str_list_files)
index = 0x1000
for file_info in file_list:
save_flag = True
for skip in skip_files:
if file_info[0].endswith(skip):
save_flag = False
if save_flag:
p2k_save_file(p2k_usb_device, index, file_info)
else:
logging.info(f'Skipped dumping of "{file_info[0]}" file!')
index += 2
def p2k_do_info_dump(p2k_usb_device, file_path):
logging.info(f'Dumping P2K Information to the "{file_path}" file!')
with open(file_path, 'w') as file:
file.write('\nSEEM 0074_0001:\n' + hexdump(p2k_read_seem(p2k_usb_device, 0x0003, 0x0074, 0x0001)))
file.write('\nSEEM 0076_0001:\n' + hexdump(p2k_read_seem(p2k_usb_device, 0x0004, 0x0076, 0x0001)))
file.write('\nSEEM 0117_0001:\n' + hexdump(p2k_read_seem(p2k_usb_device, 0x0006, 0x0117, 0x0001)))
file.write('\nSEEM 0117_0001:\n' + hexdump(p2k_read_seem(p2k_usb_device, 0x0008, 0x017F, 0x0001)))
file.write('\nFTR FFFF:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x000A, 0xFFFF, True)))
file.write('\nFTR 0001:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x000C, 0x0001, True)))
file.write('\nFTR 0002:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x000E, 0x0002, True)))
file.write('\nFTR 0003:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0010, 0x0003, True)))
file.write('\nFTR 1107:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0012, 0x1107, True)))
file.write('\nFTR 0006:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0014, 0x0006, True)))
file.write('\nFTR 0007:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0016, 0x0007, True)))
file.write('\nFTR 0008:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0018, 0x0008, True)))
file.write('\nFTR 0009:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x001A, 0x0009, True)))
file.write('\nFTR 1000:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x001C, 0x1000, True)))
file.write('\nFTR 1001:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x001E, 0x1001, True)))
file.write('\nFTR 1002:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0020, 0x1002, True)))
file.write('\nFTR 1003:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0022, 0x1003, True)))
file.write('\nFTR 1100:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0024, 0x1100, True)))
file.write('\nFTR 1101:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0026, 0x1101, True)))
file.write('\nFTR 1102:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0028, 0x1102, True)))
file.write('\nFTR 1103:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x002A, 0x1103, True)))
file.write('\nFTR 1104:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x002C, 0x1104, True)))
file.write('\nFTR 1105:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x002E, 0x1105, True)))
file.write('\nFTR 1106:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0030, 0x1106, True)))
file.write('\nFTR 0004:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0032, 0x0004, True)))
file.write('\nFTR 1108:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0034, 0x1108, True)))
file.write('\nFTR 1109:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0036, 0x1109, True)))
file.write('\nFTR 110A:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0038, 0x110A, True)))
file.write('\nFTR 110B:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x003A, 0x110B, True)))
file.write('\nFTR 110C:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x003C, 0x110C, True)))
file.write('\nFTR 110D:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x003E, 0x110D, True)))
file.write('\nFTR 1200:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0040, 0x1200, True)))
file.write('\nFTR 1300:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0042, 0x1300, True)))
file.write('\nFTR 1301:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0044, 0x1301, True)))
file.write('\nFTR 1302:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0046, 0x1302, True)))
file.write('\nFTR 1303:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0048, 0x1303, True)))
file.write('\nFTR 1304:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x004A, 0x1304, True)))
file.write('\nFTR 1305:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x004C, 0x1305, True)))
file.write('\nFTR 1306:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x004E, 0x1306, True)))
file.write('\nFTR 1307:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0050, 0x1307, True)))
file.write('\nFTR 1308:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0052, 0x1308, True)))
file.write('\nFTR 1309:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0054, 0x1309, True)))
file.write('\nFTR 130A:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0056, 0x130A, True)))
file.write('\nFTR 1400:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x0058, 0x1400, True)))
file.write('\nFTR 1401:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x005A, 0x1401, True)))
file.write('\nFTR 2000:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x005C, 0x2000, True)))
file.write('\nFTR FFFE:\n' + hexdump(p2k_get_info(p2k_usb_device, 0x005E, 0xFFFE, True)))
return True
def p2k_do_memacs_dump(p2k_usb_device, file_path, start = 0x10000000, end = 0x12000000, step = 0x0800):
logging.info(f'Dumping 0x{start:08X}-0x{end:08X} memory region to the "{file_path}" file!')
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end:
if addr_e > end:
addr_e = end
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % 0x50 == 0):
time_start = progress(step, time_start, 0x50, index * step, file_path, addr_s, addr_e, end)
result_data = p2k_memacs(p2k_usb_device, index, addr_s, step)
if len(result_data) != step:
logging.error(f'Result data is smaller than step: {len(result_data)} != {step}, MEMACS disabled?')
return False
file.write(result_data)
addr_s = addr_s + step
addr_e = addr_s + step
index += 1
return True
def do_p2k_work(modem_device, modem_speed, usb_devices):
if switch_atmode_to_p2kmode(modem_device, modem_speed, usb_devices):
p2k_usb_device = find_usb_device(usb_devices, 'p2k')
if p2k_usb_device:
# p2k_usb_device.set_configuration()
config = p2k_usb_device.get_active_configuration()
logging.debug(config)
worksheet_p2k(p2k_usb_device)
else:
logging.error('Cannot find P2K device!')
sys.exit(0)
## Motorola Flash Protocol #############################################################################################
def calculate_checksum(data):
checksum = 0
for byte in data:
checksum = (checksum + byte) % 256
return checksum
def mfp_dump_rqhw(er, ew, file_path, start, end, command = 'RQHW', step = 0x10):
logging.warning(f'Please check that "{start:08X}" address is defined in RDL patch source code!')
logging.warning(f'Step "{step:02X}" should be same as defined in RDL patch source code!')
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end:
if addr_e > end:
addr_e = end
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
result_data = mfp_cmd(er, ew, command)
result_data = result_data[6:] # Drop start marker and command.
result_data = result_data[:-1] # Drop end marker.
file.write(bytearray.fromhex(result_data.decode()))
addr_s = addr_s + step
addr_e = addr_s + step
index += step
def mfp_dump_rqrc(er, ew, file_path, start, end, step = 0x01):
addr_s = start
addr_e = start + step + 0x400
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end + 0x400:
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
result_data1 = mfp_cmd(er, ew, 'RQRC', f'{addr_s:08X},{addr_e:08X}'.encode())
result_data1 = result_data1[6:] # Drop start marker and command.
result_data1 = result_data1[:-1] # Drop end marker.
result_data1_int = int.from_bytes(bytes.fromhex(result_data1.decode()), 'big')
result_data2 = mfp_cmd(er, ew, 'RQRC', f'{addr_s + 0x01:08X},{addr_e:08X}'.encode())
result_data2 = result_data2[6:] # Drop start marker and command.
result_data2 = result_data2[:-1] # Drop end marker.
result_data2_int = int.from_bytes(bytes.fromhex(result_data2.decode()), 'big')
result_byte = (result_data1_int - result_data2_int) % 256
result = int.to_bytes(result_byte,1, 'big')
file.write(result)
addr_s = addr_s + step
addr_e = addr_s + step + 0x400
index += step
def mfp_dump_r(er, ew, file_path, start, end, step = 0x100):
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end:
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
binary_cmd = bytearray()
binary_cmd.extend('R'.encode())
binary_cmd.extend(addr_s.to_bytes(4, byteorder = 'big'))
binary_cmd.extend(step.to_bytes(4, byteorder = 'big'))
result_data = mfp_binary_cmd(er, ew, binary_cmd)
result_data = mfp_binary_cmd(er, ew, binary_cmd)
result_data = result_data[:-1] # Drop checksum.
file.write(result_data)
addr_s = addr_s + step
addr_e = addr_s + step
index += step
def mfp_dump_read(er, ew, file_path, start, end, step = 0x100):
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end:
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
result_data = mfp_cmd(er, ew, 'READ', f'{addr_s:08X},{step:04X}'.encode())
result_data = result_data[6:] # Drop start marker and command.
result_data = result_data[2:] # Drop size step.
result_data = result_data[:-1] # Drop checksum.
result_data = result_data[:-1] # Drop end marker.
file.write(result_data)
addr_s = addr_s + step
addr_e = addr_s + step
index += step
def mfp_dump_rbin(er, ew, file_path, start, end, step = 0x1000):
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end:
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
command_arg = f'{addr_s:08X}{step:04X}'.encode()
command_arg_chk = f'{addr_s:08X}{step:04X}{calculate_checksum(command_arg):02X}'.encode()
result_data = mfp_cmd(er, ew, 'RBIN', command_arg_chk)
result_data = result_data[6:] # Drop start marker and command.
result_data = result_data[:-1] # Drop checksum.
result_data = result_data[:-1] # Drop end marker.
file.write(result_data)
addr_s = addr_s + step
addr_e = addr_s + step
index += step
def mfp_dump_dump(er, ew, file_path, start, end, step = 0x100):
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end:
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
result_data = mfp_cmd(er, ew, 'DUMP', f'{addr_s:08X}'.encode())
file.write(result_data)
addr_s = addr_s + step
addr_e = addr_s + step
index += step
def mfp_dump_nand(er, ew, file_path, start, end, step = 0x30, wide_nand = 1, nand_buffer = 0x60000000, fixup = None):
if fixup:
nand_buffer += fixup
addr_s = nand_buffer
addr_e = addr_s + step
addr_h = nand_buffer + 0x210
with open(file_path, 'wb') as dump, open(insert_to_filename('_spare_area', file_path), 'wb') as spare:
index = 0
time_start = time.time()
for page in range(start, end):
for wide in range(wide_nand):
logging.debug(f'Dumping NAND {page:08} page ({wide:02}), 512+16 bytes to "{file_path}" +spare_area...')
if index > 0 and (index % 100 == 0):
time_start = progress(
528, time_start, 100, index, file_path,
addr_s, addr_h, end, (end - start) * wide_nand, True
)
while addr_e <= addr_h:
if wide_nand > 1:
result_data = mfp_cmd(er, ew, 'RQRC',
f'{addr_s:08X},{addr_e:08X},{page:08X},{wide:08X}'.encode())
else:
result_data = mfp_cmd(er, ew, 'RQRC', f'{addr_s:08X},{addr_e:08X},{page:08X}'.encode())
result_data = result_data[6:] # Drop start marker and command.
result_data = result_data[:-1] # Drop end marker.
# Last chunk page. Be careful! Will work only with 0x10 and 0x30 step values!
if addr_e == addr_h:
spare_area = result_data[-16 * 2:] # 16 * 2 because in HEX byte length is 2.
result_data = result_data[:-16 * 2] # Trim spare area from the last packet.
spare.write(bytearray.fromhex(spare_area.decode()))
dump.write(bytearray.fromhex(result_data.decode()))
addr_s = addr_s + step
addr_e = addr_s + step
index += 1
addr_s = nand_buffer
addr_e = addr_s + step
def mfp_dump_sram(er, ew, file_path, start, end, step = 0x30):
addr_s = start
addr_e = start + step
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e <= end + step:
if addr_e > end:
addr_e = end
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (step * 0x100) == 0):
time_start = progress(step, time_start, 0x100, index, file_path, addr_s, addr_e, end)
result_data = mfp_cmd(er, ew, 'RQRC', f'{addr_s:08X},{addr_e:08X}'.encode())
result_data = result_data[6:] # Drop start marker and command.
result_data = result_data[:-1] # Drop end marker.
file.write(bytearray.fromhex(result_data.decode()))
addr_s = addr_s + step
addr_e = addr_s + step
index += step
def mfp_dump_byte(er, ew, file_path, start, end):
addr_s = start
addr_e = start
with open(file_path, 'wb') as file:
index = 0
time_start = time.time()
while addr_e < end:
logging.debug(f'Dumping 0x{addr_s:08X}-0x{addr_e:08X} bytes to "{file_path}"...')
if index > 0 and (index % (0x01 * 0x100) == 0):
time_start = progress(0x01, time_start, 0x100, index, file_path, addr_s, addr_e, end)
result_data = mfp_cmd(er, ew, 'RQRC', f'{addr_s:08X},{addr_e:08X}'.encode())
result_data = result_data[6:] # Drop start marker and command.
result_data = result_data[:-1] # Drop end marker.
result_data = result_data[2:] # Drop leading zero byte.
file.write(bytearray.fromhex(result_data.decode()))
addr_s += 1
addr_e += 1
index += 1
def mfp_upload_binary_to_addr(er, ew, file_path, start, jump = None, rsrc = None, ezx_ap = None, read_response = True):
address = start
logging.info(f'Uploading "{file_path}" to 0x{address:08X} with {buffer_write_size} bytes chunks...')
end = start + os.path.getsize(file_path)
with open(file_path, 'rb') as file:
index = 0
time_start = time.time()
while True:
chunk = file.read(buffer_write_size)
if not chunk:
break
step = len(chunk)
logging.debug(f'Uploading {step},0x{step:08X} bytes from "{file_path}" to 0x{address:08X}...')
if index > 0 and (index % (step * 0x10) == 0):
time_start = progress(step, time_start, 0x10, index, file_path, address, address + step, end)
mfp_addr(er, ew, address)
mfp_bin(er, ew, chunk)
address += step
index += step
logging.info(f'Uploading "{file_path}" to 0x{start:08X}-0x{address:08X} region is done.')
if jump:
if rsrc:
loader_file_size = os.path.getsize(file_path)
end = start + loader_file_size - 1
logging.info(f'Calculate checksum of "{start:08X},{end:08X}" region.')
mfp_cmd(er, ew, 'RQRC', f'{start:08X},{end:08X}'.encode())
logging.info(f'Jumping to 0x{jump:08X} address.')
mfp_cmd(er, ew, 'JUMP', mfp_get_addr_with_chksum(jump), read_response)
logging.info(f'Waiting {delay_jump} seconds for RAMDLD init on device...')
time.sleep(delay_jump)
if ezx_ap:
logging.info(f'EZX AP RAMDLD was loaded. Please remove the "-l" flag or add the "-2" flag and rerun script.')
sys.exit(0)
def mfp_uls_upload(er, ew, file_path, load_address = 0x12000000, chunk_size = None, read_response = False):
binary_file_size = os.path.getsize(file_path)
with open(file_path, 'rb') as file:
chunk = file.read()
chunk = bytearray(chunk)
payload_magic = b'\x55\x55\x55\xAA'
payload_body = load_address.to_bytes(4, 'big') + int(binary_file_size << 16).to_bytes(4, 'big')
chunk = payload_body + chunk
checksum = 0xFF - calculate_checksum(chunk)
mfp_upload_raw_binary(er, ew, file_path, chunk_size, read_response, checksum, payload_magic + payload_body)
def mfp_upload_raw_binary(er, ew, file_path, chunk_size = None, read_response = True, checksum = None, payload = None):
binary_file_size = os.path.getsize(file_path)
if not chunk_size:
chunk_size = binary_file_size
logging.info(f'Uploading "{file_path}" of {binary_file_size} bytes size on {chunk_size} chunk_size...')
with open(file_path, 'rb') as file:
index = 0
while True:
# First frame.
if index == 0 and payload:
chunk = bytearray(payload)
chunk.extend(file.read(chunk_size - len(payload)))
else:
chunk = file.read(chunk_size)
if not chunk:
break
# Last frame.
if len(chunk) < chunk_size:
if checksum:
chunk = bytearray(chunk)
chunk.extend(checksum.to_bytes(1, 'big'))
logging.debug(f'Uploading {len(chunk)},0x{len(chunk):08X} bytes from "{file_path}"...')
mfp_binary_cmd(er, ew, chunk, read_response)
index += 1
logging.info(f'Uploading "{file_path}" is done.')
def mfp_get_addr_with_chksum(address):
addr_data = bytearray()
addr_data.extend(f'{address:08X}'.encode())
addr_data.extend(f'{calculate_checksum(addr_data):02X}'.encode())
return addr_data
def mfp_addr(er, ew, address):
result = mfp_cmd(er, ew, 'ADDR', mfp_get_addr_with_chksum(address))
return result
def mfp_bin(er, ew, data):
packet = bytearray()
packet.extend(len(data).to_bytes(2, 'big'))
packet.extend(data)
packet.append(calculate_checksum(packet))
logging.debug(f'BIN packet: size={len(data)}, chksum={calculate_checksum(packet)}')
result = mfp_cmd(er, ew, 'BIN', packet)
return result
def mfp_cmd(er, ew, cmd, data = None, read_response = True):
packet = bytearray(b'\x02') # Start marker.
packet.extend(cmd.encode())
if data:
packet.extend(b'\x1E') # Data separator.
packet.extend(data)
packet.extend(b'\x03') # End marker.
logging.debug(f'>>> Send to device...\n{hexdump(packet)}')
result = mfp_send_recv(er, ew, packet, read_response)
logging.debug(f'<<< Read from device...\n{hexdump(result)}')
return result
def mfp_binary_cmd(er, ew, binary_cmd, read_response = True):
if binary_cmd:
logging.debug(f'>>> Send to device...\n{hexdump(binary_cmd)}')
result = mfp_send_recv(er, ew, binary_cmd, read_response)
if result:
logging.debug(f'<<< Read from device...\n{hexdump(result)}')
return result
def mfp_recv(er):
return bytearray(er.read(buffer_read_size, timeout_read))
def mfp_send(ew, data):
return ew.write(data, timeout_write)
def mfp_send_recv(er, ew, data, read_response = True):
if data:
mfp_send(ew, data)
response = None
if read_response:
while not response:
try:
response = mfp_recv(er)
except usb.USBError as error:
# TODO: Proper USB errors handling.
logging.error(f'USB Error: {error}')
sys.exit(1)
time.sleep(delay_ack)
else:
response = 'NO DATA'.encode()
return response
## USB Routines ########################################################################################################
def usb_check_restart_phone(er, ew, restart_flag):
if restart_flag:
mfp_cmd(er, ew, 'RESTART')
time.sleep(2.0)
er, ew = usb_init(usb_devices, 'flash')
if not er or not ew:
logging.error('Cannot find USB device!')
sys.exit(1)
return er, ew
def get_usb_device_information(usb_device):
return f'{usb_device["desc"]}: usb_vid={usb_device["usb_vid"]:04X}, usb_pid={usb_device["usb_pid"]:04X}'