📄 atlasmgr2dlg.cpp
字号:
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAtlasMgr2Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAtlasMgr2Dlg::OnCsChange()
{
// TODO: Add your control notification handler code here
UpdateData();
}
void CAtlasMgr2Dlg::OnOpenDevice()
{
// TODO: Add your control notification handler code here
UpdateData();
AfxGetApp()->WriteProfileInt("Nboot", "Port", m_nPort);
AfxGetApp()->WriteProfileInt("Nboot", "Baud", m_nBaud);
AfxGetApp()->WriteProfileInt("Nboot", "Chip", m_nChipType);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD1Value", m_nGPIOPreLoad1Value);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD1Group", m_nGPIOPreLoad1Group);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD1Pins", m_nGPIOPreLoad1Pins);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD2Value", m_nGPIOPreLoad2Value);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD2Group", m_nGPIOPreLoad2Group);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD2Pins", m_nGPIOPreLoad2Pins);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD3Value", m_nGPIOPreLoad3Value);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD3Group", m_nGPIOPreLoad3Group);
AfxGetApp()->WriteProfileInt("Nboot", "GPIOPRELOAD3Pins", m_nGPIOPreLoad3Pins);
AfxGetApp()->WriteProfileInt("NorFlash", "Default", m_nNorFlashType);
if(!m_bOpened)
{
memset(&g_atlasdevinfo,0,sizeof(g_atlasdevinfo));
char strComPortName[10];
DWORD dwComPortIndex;
m_combo_com_port.GetLBText(m_nPort,(char *)&strComPortName);
dwComPortIndex = atoi(strComPortName+3) -1 ;
TRACE("m_nPort=%d , com name=%s,dwComPortIndex=%d \r\n",m_nPort,strComPortName, dwComPortIndex);
m_bOpened = AtlasInitSystem(m_nTransPort, dwComPortIndex, m_nBaud, GetSafeHwnd());
if(m_bOpened && (m_nTransPort == ATLAS_TRANSPORT_USB))
{
CString szDevInfo;
szDevInfo.Format("Version: %.2f\r\nCPU Type: 0x%08x\r\nHardware name: %s\r\nSoftware name: %s\r\nImage type: %s", \
(float)g_atlasdevinfo.dwBootloaderVer/100, \
g_atlasdevinfo.dwProcessorInfo,g_atlasdevinfo.szHardwareName, \
g_atlasdevinfo.szSoftwareName,g_atlasdevinfo.szImageType);
GetDlgItem(IDC_DEV_INFO)->SetWindowText(szDevInfo);
}
}
else
{
AtlasDeinitSystem();
m_bOpened = FALSE;
}
UpdateUI();
}
void CAtlasMgr2Dlg::OnUpdateNboot()
{
CString strNBootPath;
CString strInitDir = AfxGetApp()->GetProfileString("NBoot", "Path", "");
char initFile[_MAX_PATH];
char * success_message;
char * failed_message;
if(ATLAS_BOOT_STAGE_BOOTSTRAPE == g_atlasdevinfo.dwBootStage)
{
success_message = "Update BootStrap successfully!";
failed_message = "Update BootStrap failed!";
}
else
{
success_message = "Update Nboot successfully!";
failed_message = "Update Nboot failed!";
}
strcpy(initFile, strInitDir);
char strNorFlashType[_MAX_PATH];
if(g_dwTransport == ATLAS_TRANSPORT_JTAG)
{
if(-1 == m_nNorFlashType)
{
AfxMessageBox("Please select a valid NorFlash Type!");
return;
}
m_NorFlash_Type.GetLBText(m_nNorFlashType,(char *)&strNorFlashType);
TRACE("Selected NorFlash Type:%s\r\n",strNorFlashType);
}
CFileDialog fileDlg(TRUE,
NULL,
NULL,
OFN_OVERWRITEPROMPT,
"Binary Files (*.bin)|*.bin|Windows CE Raw Files (*.nb0)|*.nb0|All Files (*.*)|*.*||");
//if the initfile is the format like d:\abc\ or \\aaa, we think it is a folder
if(initFile[strlen(initFile)-1] =='\\' || (strlen(initFile) > 2 && initFile[0] == '\\' && initFile[1] == '\\' && !strchr(initFile + 2,'\\')))
{
TRACE("Is a Folder\r\n");
fileDlg.m_ofn.lpstrInitialDir = initFile;
}
else
fileDlg.m_ofn.lpstrFile = initFile;
if(fileDlg.DoModal() == IDOK)
{
strNBootPath = fileDlg.GetPathName();
AfxGetApp()->WriteProfileString("NBoot", "Path", strNBootPath);
}
else
return;
extern DWORD g_dwTransport;
//USB downloading
if(g_dwTransport != ATLAS_TRANSPORT_JTAG)
{
if(AtlasDownloadImage(strNBootPath, m_nCs, ATLAS_IMAGE_WINDOWS_CE_NBOOT))
AfxMessageBox(success_message);
else
AfxMessageBox(failed_message);
}
else if(UpdateNBootByJTAGBS(strNBootPath,strNorFlashType) == true) // Yang Jian: Boundary Scan
{
AfxMessageBox(success_message);
}
else
{
AfxMessageBox(failed_message);
}
}
void CAtlasMgr2Dlg::OnUpdateEboot()
{
// TODO: Add your control notification handler code here
CString strEBootPath;
CString strInitDir = AfxGetApp()->GetProfileString("EBoot", "Path", "");
char initFile[_MAX_PATH];
strcpy(initFile, strInitDir);
CFileDialog fileDlg(TRUE,
NULL,
NULL,
OFN_OVERWRITEPROMPT,
"Windows CE Raw Files (*.nb0)|*.nb0|All Files (*.*)|*.*||");
//if the initfile is the format like d:\abc\ or \\aaa, we think it is a folder
if(initFile[strlen(initFile)-1] =='\\' || (strlen(initFile) > 2 && initFile[0] == '\\' && initFile[1] == '\\' && !strchr(initFile + 2,'\\')))
{
TRACE("Is a Folder\r\n");
fileDlg.m_ofn.lpstrInitialDir = initFile;
}
else
fileDlg.m_ofn.lpstrFile = initFile;
if(fileDlg.DoModal() == IDOK)
{
strEBootPath = fileDlg.GetPathName();
AfxGetApp()->WriteProfileString("EBoot", "Path", strEBootPath);
}
else
return;
if(!AtlasDownloadImage(strEBootPath, m_nCs, ATLAS_IMAGE_WINDOWS_CE_EBOOT))
{
AfxMessageBox("Update EBoot failed!");
return;
}
/* if(!AtlasUpdateToc())
{
AfxMessageBox("Update EBOOT failed in writing Toc!");
return;
}
*/
AfxMessageBox("Update EBOOT sucessful!");
}
BOOL CAtlasMgr2Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::PreTranslateMessage(pMsg);
}
void CAtlasMgr2Dlg::OnUpdateNKImage()
{
// TODO: Add your control notification handler code here
CString strImagePath;
CString strInitDir = AfxGetApp()->GetProfileString("NK", "Path", "");
char initFile[_MAX_PATH];
BOOL bRet;
DWORD lastData;
if(m_nCs != 0)
{
AfxMessageBox("We only support download NK image to the booting NandFlash (CS0)!");
return;
}
strcpy(initFile, strInitDir);
CFileDialog fileDlg(TRUE,
NULL,
NULL,
OFN_OVERWRITEPROMPT,
"Windows CE MultiXIP Image(*.lst)|*.lst|Windows CE Monolithic Image(*.bin)|*.bin|All Files (*.*)|*.*||");
//if the initfile is the format like d:\abc\ or \\aaa, we think it is a folder
if(initFile[strlen(initFile)-1] =='\\' || (strlen(initFile) > 2 && initFile[0] == '\\' && initFile[1] == '\\' && !strchr(initFile + 2,'\\')))
{
TRACE("Is a Folder\r\n");
fileDlg.m_ofn.lpstrInitialDir = initFile;
}
else
fileDlg.m_ofn.lpstrFile = initFile;
if(fileDlg.DoModal() == IDOK)
{
strImagePath = fileDlg.GetPathName();
AfxGetApp()->WriteProfileString("NK", "Path", strImagePath);
}
else
return;
DWORD dwBootStage;
if(!AtlasGetOSBootStage(dwBootStage))
{
AfxMessageBox("Download NK image failed!");
return;
}
if(dwBootStage != ATLAS_BOOT_STAGE_EBOOT && dwBootStage != ATLAS_BOOT_STAGE_NORFLASH_EBOOT)
{
AfxMessageBox("Download NK image is only supported in EBOOT mode! Please enter EBOOT mode and try again!");
return;
}
if(!AtlasSetFrameLength(EBOOT_DATA_FRAME_LENGTH))
{
AfxMessageBox("Set frame length failed, check your firmware version!");
return;
}
BYTE usbFrame[0x8000];
if(strImagePath.Find(".bin") != -1)
{
lastData = 0;
//A monolithic NK image
bRet = DownloadBinFile(strImagePath, lastData, usbFrame, TRUE);
}
else if(strImagePath.Find(".lst") != -1)
{
//A multixip NK image
CStdioFile lstFile;
CString strPath;
if(!lstFile.Open(strImagePath, CFile::modeRead))
{
AfxMessageBox("Cannot open the lst file! Make sure it exists and is not opened by another process.");
return;
}
strImagePath = strImagePath.Left(strImagePath.ReverseFind('\\') + 1);
char BinFiles[BL_MAX_BIN_REGIONS][MAX_PATH];
memset(BinFiles, 0, sizeof(BinFiles));
DWORD dwNumBin = 0;
while(1)
{
CString binFile;
if(!lstFile.ReadString(binFile))
break;
binFile.TrimLeft();
binFile.TrimRight();
if(binFile.GetLength() == 0)
break;
if(binFile.Find('+') == 0)
binFile = binFile.Right(binFile.GetLength() - 1);
binFile = strImagePath + binFile;
strcpy(BinFiles[dwNumBin], binFile);
dwNumBin++;
if(dwNumBin > BL_MAX_BIN_REGIONS)
{
AfxMessageBox("Invalid list file! Too many bin regions!");
lstFile.Close();
return;
}
}
lstFile.Close();
DWORD dwChkSum;
if(dwNumBin == 0)
{
AfxMessageBox("Invalid list file! No valid bin region found!");
return;
}
// BootloaderVer = 4xx --- Eboot and images is for WinCE4.x
if (!g_bNK5_0)
{
MultiBINInfo multiBinInfo;
if(!ParseBinInfo(BinFiles, dwNumBin, multiBinInfo, dwChkSum))
{
AfxMessageBox("Corrupted bin files found!");
return;
}
strcpy((char*)usbFrame, "X000FF\x0A"); //Multi-bin packet header of WINCE4.x
lastData = BIN_HEADER_LENGTH;
memcpy(usbFrame + lastData, (void*)&dwChkSum, sizeof(DWORD));
lastData += sizeof(DWORD);
memcpy(usbFrame + lastData, (void*)&multiBinInfo, sizeof(DWORD) + multiBinInfo.dwNumRegions * sizeof(RegionInfo));
lastData += sizeof(DWORD) + multiBinInfo.dwNumRegions * sizeof(RegionInfo);
}
// BootloaderVer = 5xx --- Eboot and images is for WinCE5.x
else
{
MultiBINInfo_CE50 multiBinInfo_ce50;
if(!ParseBinInfo_CE50(BinFiles, dwNumBin, multiBinInfo_ce50, dwChkSum))
{
AfxMessageBox("Corrupted bin files found!");
return;
}
strcpy((char*)usbFrame, "N000FF\x0A"); //Multi-bin packet header of WINCE5.x
lastData = BIN_HEADER_LENGTH;
memcpy(usbFrame + lastData, (void*)&dwChkSum, sizeof(DWORD));
lastData += sizeof(DWORD);
memcpy(usbFrame + lastData, (void*)&multiBinInfo_ce50, sizeof(DWORD) + multiBinInfo_ce50.dwNumRegions * sizeof(RegionInfo_CE50));
lastData += sizeof(DWORD) + multiBinInfo_ce50.dwNumRegions * sizeof(RegionInfo_CE50);
}
for(DWORD i = 0; i < dwNumBin; i++)
{
BOOL bFlush = FALSE;
if(i == dwNumBin - 1)
bFlush = TRUE;
if((bRet = DownloadBinFile(BinFiles[i], lastData, usbFrame, bFlush)) == FALSE)
break;
}
}
if(bRet)
AfxMessageBox("Download NK image successfully!");
else
AfxMessageBox("Download NK image failed!");
}
BOOL CAtlasMgr2Dlg::DownloadBinFile(LPCSTR strBinFile, DWORD & nLastData, PBYTE pUsbFrameBuf, BOOL bFlush)
{
CFile file;
DWORD dwFileLength;
DWORD dwThisRead;
BOOL bRet = TRUE;
DWORD dwSteps;
CProgressDlg progress;
CString fileName;
DWORD dwOldThreadPrio;
HANDLE dwCurThread;
if(!file.Open(strBinFile, CFile::modeRead))
return FALSE;
if(!AtlasOpenDownloadPipe())
{
file.Close();
return FALSE;
}
//Boost the thread priority for two level to make the download more safe
dwCurThread = GetCurrentThread();
dwOldThreadPrio = GetThreadPriority(dwCurThread);
SetThreadPriority(dwCurThread, dwOldThreadPrio - 2);
dwFileLength = file.GetLength();
dwSteps = (dwFileLength + nLastData) / EBOOT_DATA_FRAME_LENGTH;
if((dwFileLength + nLastData) % EBOOT_DATA_FRAME_LENGTH)
dwSteps ++;
fileName = strBinFile;
fileName = fileName.Right(fileName.GetLength() - fileName.ReverseFind('\\') - 1);
fileName = "Downloading " + fileName;
fileName += " ...";
progress.Create(this);
progress.SetWindowText(fileName);
progress.SetStep(1);
progress.SetRange(0, dwSteps);
dwThisRead = EBOOT_DATA_FRAME_LENGTH - nLastData;
if(dwFileLength < dwThisRead)
dwThisRead = dwFileLength;
if(file.Read(pUsbFrameBuf + nLastData, dwThisRead) != dwThisRead)
{
bRet = FALSE;
goto DownloadBinFileExit;
}
if(!DownloadFrame(pUsbFrameBuf))
{
bRet = FALSE;
goto DownloadBinFileExit;
}
progress.StepIt();
dwFileLength -= dwThisRead;
while(dwFileLength)
{
if(dwFileLength > EBOOT_DATA_FRAME_LENGTH)
dwThisRead = EBOOT_DATA_FRAME_LENGTH;
else
{
dwThisRead = dwFileLength;
nLastData = dwThisRead;
}
if(file.Read(pUsbFrameBuf, dwThisRead) != dwThisRead)
{
bRet = FALSE;
goto DownloadBinFileExit;
}
if(dwThisRead == EBOOT_DATA_FRAME_LENGTH || bFlush)
{
if(!DownloadFrame(pUsbFrameBuf))
{
bRet = FALSE;
goto DownloadBinFileExit;
}
}
if (progress.CheckCancelButton() == TRUE)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -