-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlTools.cs
More file actions
131 lines (124 loc) · 3.97 KB
/
Copy pathPlTools.cs
File metadata and controls
131 lines (124 loc) · 3.97 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
using System;
using System.IO;
using MtkClient.Library.Config;
using MtkClient.Library.Connection;
using MtkClient.Library.Hardware;
using MtkClient.Library.Utils;
namespace MtkClient.Library
{
public class PlTools : LogBase
{
private readonly MtkConfig _config;
private readonly Port _port;
private readonly Preloader _preloader;
public PlTools(MtkConfig config, Port port, Preloader preloader, LogLevel logLevel = LogLevel.Info)
{
InitLogger(logLevel);
_config = config;
_port = port;
_preloader = preloader;
}
public byte[] DumpSram()
{
Info("Dumping SRAM...");
try
{
const uint sramAddr = 0x00100000;
const int sramSize = 0x20000;
var data = _preloader.Read32(sramAddr, sramSize);
if (data != null)
Info($"SRAM dumped: {data.Length} bytes");
return data;
}
catch (Exception ex)
{
Error($"SRAM dump failed: {ex.Message}");
return null;
}
}
public byte[] DumpDram()
{
Info("Dumping DRAM...");
try
{
const uint dramAddr = 0x40000000;
const int dramSize = 0x20000;
var data = _preloader.Read32(dramAddr, dramSize);
if (data != null)
Info($"DRAM dumped: {data.Length} bytes");
return data;
}
catch (Exception ex)
{
Error($"DRAM dump failed: {ex.Message}");
return null;
}
}
public byte[] DumpBrom()
{
Info("Dumping BROM...");
try
{
const uint bromAddr = 0x00000000;
const int bromSize = 0x20000;
var data = _preloader.Read32(bromAddr, bromSize);
if (data != null)
Info($"BROM dumped: {data.Length} bytes");
return data;
}
catch (Exception ex)
{
Error($"BROM dump failed: {ex.Message}");
return null;
}
}
public byte[] DumpPreloader()
{
Info("Dumping preloader...");
try
{
const uint plAddr = 0x00201000;
const int plSize = 0x40000;
var data = _preloader.Read32(plAddr, plSize);
if (data != null)
{
Info($"Preloader dumped: {data.Length} bytes");
_config.Preloader = data;
if (_config.WritePreloaderToFile && !string.IsNullOrEmpty(_config.PreloaderFilename))
{
File.WriteAllBytes(_config.PreloaderFilename, data);
Info($"Preloader saved to: {_config.PreloaderFilename}");
}
}
return data;
}
catch (Exception ex)
{
Error($"Preloader dump failed: {ex.Message}");
return null;
}
}
public byte[] DumpEfuse()
{
Info("Dumping eFuse...");
try
{
if (!_config.ChipConfig.EfuseAddr.HasValue)
{
Warning("eFuse address not set for this chip");
return null;
}
var addr = _config.ChipConfig.EfuseAddr.Value;
var data = _preloader.Read32(addr, 0x1000);
if (data != null)
Info($"eFuse dumped: {data.Length} bytes from 0x{addr:X}");
return data;
}
catch (Exception ex)
{
Error($"eFuse dump failed: {ex.Message}");
return null;
}
}
}
}