-
Notifications
You must be signed in to change notification settings - Fork 7
/
PCMemoryChecksumProgress.cpp
232 lines (188 loc) · 7.44 KB
/
PCMemoryChecksumProgress.cpp
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
#include "PCMemoryChecksumProgress.h"
#include "Form\form_MultiLoad.h"
#include "MultiPortFlashDownloadTool.h"
#define DLCALL(a) {if((a)) {return -1;}}
PCMemoryChecksumProgress::PCMemoryChecksumProgress(bool CreateSuspended) : TThread(CreateSuspended),mHint("")
{
}
void __fastcall PCMemoryChecksumProgress::Execute()
{
SyncStart();
SyncEnd();
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::Start()
{
mPrefix = "";
m_ucProgressPercentage = 0;
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::SyncStart()
{
Synchronize(Start);
if (!TformPCMemoryChecksum::mChecksumFlag)
{
TformPCMemoryChecksum::mChecksumFlag = VerifyHostBufferBeforeStart();
}
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::End()
{
formPCMemoryChecksum->Close();
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::SyncEnd()
{
Synchronize(End);
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::InitProgress()
{
formPCMemoryChecksum->PCMemoryChecksumProgressBar->Progress = 0;
formPCMemoryChecksum->checksumImageNameLabel->Caption = mPrefix;
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::SyncInitProgress()
{
Synchronize(InitProgress);
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::UpdateProgressPercentage()
{
formPCMemoryChecksum->PCMemoryChecksumProgressBar->Progress = m_ucProgressPercentage;
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::SyncUpdateProgressPercentage(int precentage)
{
m_ucProgressPercentage = precentage;
Synchronize(UpdateProgressPercentage);
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::UpdateProgressColor()
{
formPCMemoryChecksum->PCMemoryChecksumProgressBar->BackColor = _bk_col;
formPCMemoryChecksum->PCMemoryChecksumProgressBar->ForeColor = _ft_col;
formPCMemoryChecksum->PCMemoryChecksumProgressBar->Hint = mHint;
}
//---------------------------------------------------------------------------
void _fastcall PCMemoryChecksumProgress::SyncUpdateProgressColor(TColor bk, TColor ft)
{
_bk_col = bk;
_ft_col = ft;
Synchronize(UpdateProgressColor);
}
//---------------------------------------------------------------------------
static int __stdcall cb_checksum_init(void *usr_arg, const char*image_name)
{
PCMemoryChecksumProgress *t=(PCMemoryChecksumProgress *)usr_arg;
AnsiString imageName = (AnsiString)image_name;
int iLD = imageName.LastDelimiter("\\");
imageName = imageName.SubString(iLD + 1, imageName.Length());
GC_TRACE("<TBOOT1> cb_checksum_init(): imageName = %s", imageName);
t->mPrefix = "ChkSum(" + (AnsiString)imageName + ")";
t->mHint = (AnsiString) image_name;
t->SyncInitProgress();
t->SyncUpdateProgressColor(clWhite, clFuchsia);
return 0;
}
//---------------------------------------------------------------------------
static int __stdcall cb_checksum_progress(unsigned char finished_percentage, unsigned int finished_bytes, unsigned int total_bytes, void *usr_arg)
{
PCMemoryChecksumProgress *t=(PCMemoryChecksumProgress *)usr_arg;
t->SyncUpdateProgressPercentage(finished_percentage);
return 0;
}
//---------------------------------------------------------------------------
void PCMemoryChecksumProgress::InitChecksumArgs(RomMemChecksumArg &checksumArg, RomMemChecksumResult &checksumResult)
{
memset(&checksumArg, 0, sizeof(checksumArg));
memset(&checksumResult, 0, sizeof(checksumResult));
checksumArg.m_cb_rom_mem_checksum_init = cb_checksum_init;
checksumArg.m_cb_rom_mem_checksum = cb_checksum_progress;
checksumArg.m_cb_rom_mem_checksum_arg = this;
checksumArg.m_cb_rom_mem_checksum_init_arg = this;
checksumArg.p_stopflag = NULL;
}
int PCMemoryChecksumProgress::VerifyHostBufferCksm(RomMemChecksumArg &checksumArg, RomMemChecksumResult &checksumResult)
{
DL_HANDLE_T &dl_handle = *MainForm->Get_DlHandle(0);
CksmVector::iterator it;
unsigned short count;
ROM_INFO rom[MAX_LOAD_SECTIONS];
int ret = S_DONE;
bool failFlag = false;
GC_TRACE("[PCMemoryChecksumProgress] VerifyHostBufferCksm(): begin VerifyHostBufferCksm. index is %d", checksumArg.index);
if(frmMultiLoad->m_cksmVt.empty())
{
GC_TRACE("<MDLF> VerifyHostBufferCksm(): Cksm vector is empty, no golden value!");
return -1;
}
DLCALL(DL_GetCount(dl_handle, &count));
DLCALL(DL_Rom_GetInfoAll(dl_handle, rom, MAX_LOAD_SECTIONS));
for( it = frmMultiLoad->m_cksmVt.begin(); (it != frmMultiLoad->m_cksmVt.end()) /*&& (0xFFFFFFFF != (*it).second)*/; it++ )
{
int k = 0;
for(; k < count; k++)
{
if(0 == (*it).first.compare(rom[k].name))
{
//ret = DL_VerifyROMMemBuf(dl_handle, rom[k].index, (*it).second);
checksumArg.index = rom[k].index;
checksumArg.chksum = (*it).second;
ret = DL_VerifyROMMemBuf(dl_handle, &checksumArg, &checksumResult);
if(S_DONE != ret)
{
GC_TRACE("<MDLF> VerifyHostBufferCksm(): %s(0x%x) checksum verify fail!", (*it).first.c_str(), (*it).second);
failFlag = true;
break;
}
else
{
GC_TRACE("<MDLF> VerifyHostBufferCksm(): %s(0x%x) checksum verify pass.", (*it).first.c_str(), (*it).second);
break;
}
}
}
/*if(k >= count)
{
GC_TRACE("<MDLF> VerifyHostBufferCksm(): Cannot find ROM info(%s)!", (*it).first.c_str());
return -1;
}*/
}
return (failFlag)?(-1):(0);
}
bool PCMemoryChecksumProgress::VerifyHostBufferBeforeStart()
{
if(frmMultiLoad->IsHostBufferCksmFileExisted())
{
frmMultiLoad->LoadHostBufferStdCksm();
RomMemChecksumArg checksumArg;
RomMemChecksumResult checksumResult;
InitChecksumArgs(checksumArg, checksumResult);
//md5 check sum
if( frmMultiLoad->GetCheckSumVer())
{
formPCMemoryChecksum->MD5ChecksumLabel1->Caption ="Md5 check sum running";
if(frmMultiLoad->MD5Checksum())
{
formPCMemoryChecksum->MD5ChecksumLabel1->Caption ="Md5 check sum Pass";
}
else
{
formPCMemoryChecksum->MD5ChecksumLabel1->Caption ="Md5 check sum fail";
return false;
}
}
if(VerifyHostBufferCksm( checksumArg, checksumResult ))
{
Application->MessageBox( "The memory buffer for loading image verification fail!", "FAIL", MB_OK );
return false;
}
return true;
}
else
{
Application->MessageBox( "Can not find Checksum.ini file! Please use ChecksumGenerateTool to generate the Checksum.ini .", "FAIL", MB_OK );
}
return false;
}