📄 debugtooldlg.cpp
字号:
msg(m_index++, "Frequency value is out of range!");
return;
}
Jtag.GetjtagFrequency(&frequencyIsSafe, &frequencyIsInCMDQ, &frequencyInCMDQ, &frequencyInICE);
CString fre;
fre.Format("detected frequency : %dHz", frequencyInICE);
msg(m_index++, fre);
int deviceid[255] = {{0}};
int venderid[255] = {{0}};
int m = 0;
int count = 0;
CString str = "";
// collect ahb master device
Jtag.ReadAhbmasterDevice(venderid,deviceid);
while(venderid[m] != 0 && deviceid[m] !=0 )
{
for (count = 0; count < 35; count ++)
{
if ((venderid[m] == jsms[count].VenderId) && \
(deviceid[m] == jsms[count].DeviceId))
{
msg(m_index++, jsms[count].Vendor);
break;
}
}
m++;
}
// collect ahb slave device
m = 0;
Jtag.ReadAhbDevice(venderid,deviceid);
while(venderid[m] != 0 && deviceid[m] != 0)
{
for (count = 0; count < 35; count ++)
{
if ((venderid[m] == jsms[count].VenderId) && \
(deviceid[m] == jsms[count].DeviceId))
{
msg(m_index++, jsms[count].Vendor);
break;
}
}
m++;
}
// collect apb slave device
m = 0;
Jtag.ReadApbDevice(venderid,deviceid);
while(venderid[m]!=0 &&deviceid[m]!=0)
{
for (count = 0; count < 35; count ++)
{
if ((venderid[m] == jsms[count].VenderId) && \
(deviceid[m] == jsms[count].DeviceId))
{
msg(m_index++, jsms[count].Vendor);
break;
}
}
m++;
}
}
else if(nOpenJtag == IceNotConnection)
{
m_bOpen = FALSE;
msg(m_index++, "Amontec AmtXHAL : PORT of ICE has not connection!");
}
else if(nOpenJtag == IceNotInitialized)
{
m_bOpen = FALSE;
msg(m_index++, "Amontec AmtXHAL : ICE cannot be initialized!");
}
else if(nOpenJtag == IceNotAvailable)
{
m_bOpen = FALSE;
msg(m_index++, "Amontec AmtXHAL : ICE is not available!");
}
else
{
m_bOpen = FALSE;
msg(m_index++, "can not open jtag port !");
}
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: close jtag
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnClose()
{
if(m_bOpen)
{
if (Jtag.CloseJtag())
{
msg(m_index++, "jtagkey is closed !");
m_bOpen = false;
}
else
msg(m_index++, "jtagkey is not closed");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
}
/****************************************/
// function: get addr from editBox and write
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnWrite()
{
CString sAddr = _T("");
CString sData = _T("");
CString sWriteAddr = _T("");
CString sWriteData = _T("");
int nAddr = 0, nData = 0;
GetDlgItem(IDC_WriteAddr)->GetWindowText(sWriteAddr);
GetDlgItem(IDC_WriteData)->GetWindowText(sWriteData);
// get address value
if((sWriteAddr.GetAt(1) == 'x')||(sWriteAddr.GetAt(1) == 'X'))
{
for(int i = 2; i<sWriteAddr.GetLength(); i++)
{
sAddr = sAddr + sWriteAddr.GetAt(i);
}
}
else
{
sAddr = sWriteAddr;
}
// get data value
if((sWriteData.GetAt(1) == 'x')||(sWriteData.GetAt(1) == 'X'))
{
for(int i = 2; i<sWriteData.GetLength(); i++)
{
sData = sData + sWriteData.GetAt(i);
}
}
else
{
sData = sWriteData;
}
nAddr = StrToHex(sAddr);
nData = StrToHex(sData);
if (!Jtag.UsbJtagWrite(nAddr,nData))
msg(m_index++, "write fail !");
else
msg(m_index++, "write success !");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: Open file and download
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnOpenFile()
{
CString sFile = _T("");
CString sFileLen = _T("");
CFileDialog fwFileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"binary file (*.exe)|*.exe|all file (*.*)|*.*||",NULL);
if(fwFileDlg.DoModal() == IDCANCEL)
m_sFwName.Empty();
else
{
m_sFwName = fwFileDlg.GetPathName();
GetDlgItem(IDC_FileName)->SetWindowText(m_sFwName);
msg(m_index++, "BIN Path: " + m_sFwName);
CFile f(m_sFwName,CFile::modeRead);
DWORD dwLength = f.GetLength();
f.Close();
sFileLen.Format("BIN File length: %4d byte",dwLength);
msg(m_index++, sFileLen);
}
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
}
/****************************************/
// function: download file to ram
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnDown()
{
// open file and read file in byte array
CString sFileName = _T("");
CString startAddr;
sFileName = m_sFwName;
bool flag = true;
int disAddr = 0;
// read file data to buffer
CFile f(sFileName,CFile::modeRead);
DWORD dwLength = f.GetLength();
BYTE *btFileContents = new BYTE[dwLength];
VERIFY(f.ReadHuge(btFileContents,dwLength)==dwLength);
f.Close();
// kenichi+ 2007/08/22
// extract from .exe file
BYTE *newFileContents = new BYTE[1024 * 256];
Elf32_Ehdr *ehdr;
Elf32_Shdr *shdr;
long elf = (long)btFileContents;
long elfend = (long)btFileContents + dwLength;
ehdr = (Elf32_Ehdr *) elf;
shdr = (Elf32_Shdr *)(elf + E_EL(ehdr->e_shoff));
int shstrndx = E_ES(ehdr->e_shstrndx);
char * strtab = NULL;
char *sh_name;
DWORD fSize = 0;
CString dbg;
unsigned char *temp = NULL;
// get section string table address
if (E_EL(shdr[shstrndx].sh_type) == SHT_STRTAB)
strtab = (char *) (elf + E_EL(shdr[shstrndx].sh_offset));
else
{
msg(m_index++, "file is bad !");
return ;
}
// loop section header to find ".init0 .text .data"
for (int i = 0; i < E_ES(ehdr->e_shnum); i++)
{
if (strtab == NULL)
{
msg(m_index++, "file is bad !");
return ;
}
else
sh_name = &strtab[E_EL(shdr[i].sh_name)];
int dataptr = E_EL(shdr[i].sh_offset);
if (!strcmp(sh_name, ".init0") || !strcmp(sh_name, ".text") || !strcmp(sh_name, ".data"))
{
// yes, copy to buffer
temp = (unsigned char *)(elf+dataptr);
for (int j = 0; j < E_EL(shdr[i].sh_size); j ++)
{
newFileContents[fSize] = temp[j];
fSize ++;
}
}
}
// end
// change 8 bit data to 32 bit data
int *nFileContents = new int[fSize/4+1];
int j = 0;
int nMod = (fSize) %4 ;
for(DWORD m = 0;m < fSize-nMod; m = m+4)
{
nFileContents[j] = (int)(newFileContents[m]<<24) +(int)(newFileContents[m+1]<<16)+(int)(newFileContents[m+2]<<8)+(int)(newFileContents[m+3]);
j++;
}
if(nMod == 1)
nFileContents[j] = (newFileContents[fSize-nMod] << (24));
if(nMod == 2)
nFileContents[j] = (newFileContents[fSize-nMod] << (24)) + (newFileContents[fSize-nMod+1]<<(16));
if(nMod == 3)
nFileContents[j] = (newFileContents[fSize-nMod] << (24)) + (newFileContents[fSize-nMod+1]<<(16)) + (newFileContents[fSize-nMod+2]<<(8));
nMod = fSize %4 ;
int Length = 0;
if(nMod > 0)
Length = fSize/4 + 1;
else
Length = fSize/4;
// Down File
// clear first
m_Disas.ResetContent();
m_pc.ResetContent();
m_pcindex = 0;
int naddr = 0 ;
CString saddr = _T("");
CString sfileaddr = _T("");
GetDlgItem(IDC_FileAddr)->GetWindowText(sfileaddr);
if((sfileaddr.GetAt(1) == 'x')||(sfileaddr.GetAt(1) == 'X'))
{
for(int i = 2; i<sfileaddr.GetLength();i++)
{
saddr=saddr+sfileaddr.GetAt(i);
}
}
else
{
saddr = sfileaddr;
}
naddr = StrToHex(saddr);
disAddr = naddr;
startAddr.Format("Download address start : 0x%8.8x", naddr);
msg(m_index++, startAddr);
// kenichi 2007.08.17 >>
// start download file
if (!Jtag.UsbJtagWriteBlock(naddr, nFileContents, Length))
{
flag = false;
}
// kenichi+ 2007.08.16 >>
CString info;
if (flag)
{
naddr = disAddr;
for (int p = 0; p < Length; p++)
{
clear_buf();
info = ins2st(naddr, nFileContents[p]);
naddr = naddr + 4;
showV8(m_pcindex, info);
showpc(m_pcindex, " ");
m_pcindex ++;
}
}
m_pcindex = 0;
delpc(m_pcindex);
showpc(m_pcindex, ">>");
// <<
if (flag)
msg(m_index++, "Download file succesfully !");
else
msg(m_index++, "Download file fail !");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
delete[] btFileContents;
delete[] nFileContents;
delete[] newFileContents;
}
/****************************************/
// function: clear listbox
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnClear()
{
m_list.ResetContent();
m_Disas.ResetContent();
m_pc.ResetContent();
m_index = 0;
m_pcindex = 0;
}
/****************************************/
// function: download bin fiel to flash
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnFlashDown()
{
// open file and read file in byte array
CString sFileName = _T("");
sFileName = m_sFwName;
// read file data to buffer
CFile f(sFileName,CFile::modeRead);
DWORD dwLength = f.GetLength();
BYTE *btFileContents = new BYTE[dwLength];
VERIFY(f.ReadHuge(btFileContents,dwLength)==dwLength);
f.Close();
// kenichi+ 2007/08/22
// extract from .exe file
BYTE *newFileContents = new BYTE[1024 * 256];
Elf32_Ehdr *ehdr;
Elf32_Shdr *shdr;
long elf = (long)btFileContents;
long elfend = (long)btFileContents + dwLength;
ehdr = (Elf32_Ehdr *) elf;
shdr = (Elf32_Shdr *)(elf + E_EL(ehdr->e_shoff));
int shstrndx = E_ES(ehdr->e_shstrndx);
char * strtab = NULL;
char *sh_name;
DWORD fSize = 0;
CString dbg;
unsigned char *temp = NULL;
// get section string table address
if (E_EL(shdr[shstrndx].sh_type) == SHT_STRTAB)
strtab = (char *) (elf + E_EL(shdr[shstrndx].sh_offset));
else
{
msg(m_index++, "file is bad !");
return ;
}
// loop section header to find ".init0 .text .data"
for (int i = 0; i < E_ES(ehdr->e_shnum); i++)
{
if (strtab == NULL)
{
msg(m_index++, "file is bad !");
return ;
}
else
sh_name = &strtab[E_EL(shdr[i].sh_name)];
int dataptr = E_EL(shdr[i].sh_offset);
if (!strcmp(sh_name, ".init0") || !strcmp(sh_name, ".text") || !strcmp(sh_name, ".data"))
{
// yes, copy to buffer
temp = (unsigned char *)(elf+dataptr);
for (int j = 0; j < E_EL(shdr[i].sh_size); j ++)
{
newFileContents[fSize] =temp[j];
fSize ++;
}
}
}
// end
// change 8bit data to 16bit
int *nFileContents = new int[fSize/2+1];
int j = 0;
int nMod=(fSize) %2 ;
for(DWORD m = 0;m < fSize-nMod; m = m+2)
{
nFileContents[j] = (int)(newFileContents[m]<<24) + (int)(newFileContents[m+1]<<16);
j++;
}
if(nMod == 1)
nFileContents[j] = newFileContents[fSize-nMod] << (24);
nMod = fSize %2 ;
int Length = 0;
if(nMod > 0)
Length = fSize/2+1;
else
Length = fSize/2;
// Down File
int naddr = 0 ;
CString saddr = _T("");
CString sfileaddr = _T("");
GetDlgItem(IDC_FileAddr)->GetWindowText(sfileaddr);
if((sfileaddr.GetAt(1) == 'x')||(sfileaddr.GetAt(1) == 'X'))
{
for(int i = 2; i<sfileaddr.GetLength(); i++)
{
saddr = saddr+sfileaddr.GetAt(i);
}
}
else
{
saddr = sfileaddr;
}
naddr = StrToHex(saddr);
if (Jtag.UsbJtagFlashWriteBlock(naddr, nFileContents, Length))
msg(m_index++, "download file success !");
else
msg(m_index++, "download file fail !");
msg(m_index++, ">>");
m_list.SetTopIndex(m_index - 1);
delete[] btFileContents;
delete[] nFileContents;
delete[] newFileContents;
}
/****************************************/
// function: delay time
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::delay(int i)
{
for(int m=0;m < i;m++)
;
}
/****************************************/
// function: write data to flash
// input:
// none
// output:
// none
/****************************************/
void CDebugToolDlg::OnFlashWrite()
{
CString sAddr = _T("");
CString sData = _T("");
CString sData1 = _T("");
CString sWriteAddr = _T("");
CString sWriteData = _T("");
int nRet = 0;
int nAddr = 0, nData = 0 ;
int readcmd = 0; // kenichi 06 +
GetDlgItem(IDC_WriteAddr)->GetWindowText(sWriteAddr);
GetDlgItem(IDC_WriteData)->GetWindowText(sWriteData);
// get address value
if((sWriteAddr.GetAt(1)=='x')||(sWriteAddr.GetAt(1)=='X'))
{
for(int i = 2;i <sWriteAddr.GetLength(); i++)
{
sAddr = sAddr + sWriteAddr.GetAt(i);
}
}
else
{
sAddr = sWriteAddr;
}
//data
if((sWriteData.GetAt(1) == 'x')||(sWriteData.GetAt(1) == 'X'))
{
for(int i = 2; i<sWriteData.GetLength(); i++)
{
sData = sData+sWriteData.GetAt(i);
}
}
else
{
sData = sWriteData;
}
nAddr = StrToHex(sAddr);
if(nAddr%4==0)
{
nData = StrToHex(sData);
nData = nData<<16;
readcmd = 0x00100000; // kenichi 06 +
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -