📄 atlasfunc.cpp
字号:
// AtlasFunc.cpp: implementation of the AtlasFunc class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "AtlasFunc.h"
#include "AtlasApi.h"
#include "jtag\\define.h"
#include "resource.h"
#include "progdlg.h"
typedef struct _SectorInfo
{
DWORD dwReserved1; // Reserved - used by FAL
BYTE bOEMReserved; // For use by OEM
BYTE bBadBlock; // Indicates if block is BAD
WORD wReserved2; // Reserved - used by FAL
}SectorInfo, *PSectorInfo;
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern DWORD g_dwTransport;
extern DWORD g_dwComPort;
extern DWORD g_dwComBaud;
extern DWORD g_dwChip;
extern DWORD g_dwFlashWP_GPIO_GROUP;
extern DWORD g_dwFlashWP_GPIO_PINS;
extern ATLAS_DEV_INFO g_atlasdevinfo;
extern DumpNFInfo g_DumpNFInfo;
extern DWORD dwBytesPerSector;
extern DWORD dwSectorsPerBlock;
extern DWORD dwBlocks;
extern DWORD dwDataWidth;
extern DWORD dwSpareDataLength;
BOOL AtlasInitSystem(DWORD dwTransport, DWORD dwPort, DWORD dwBaud, HWND hParentWnd)
{
g_dwTransport = dwTransport;
if(g_dwTransport == ATLAS_TRANSPORT_USB)
{
if(AtlasInitUsb())
{
return AtlasOpenUsb(hParentWnd);
}
}
else if(g_dwTransport == ATLAS_TRANSPORT_RS232)
{
g_dwComPort = dwPort;
g_dwComBaud = dwBaud;
return AtlasInitRs232(dwPort , dwBaud);
}
else if(g_dwTransport == ATLAS_TRANSPORT_JTAG)
{
return AtlasInitJTAG();
}
return FALSE;
}
VOID AtlasDeinitSystem()
{
if(g_dwTransport == ATLAS_TRANSPORT_USB)
AtlasCloseUsb();
else if(g_dwTransport == ATLAS_TRANSPORT_RS232)
AtlasDeinitRs232();
else if(g_dwTransport == ATLAS_TRANSPORT_JTAG)
AtlasDeinitJTAG();
}
BOOL AtlasDownloadImage(LPCSTR lpcstrFile, DWORD dwTargetMedia, DWORD dwImgType)
{
//First we need to allocate a buffer on the device and download
//all the image to the buffer first
CFile file;
DWORD deviceAddr;
PBYTE pBuf = NULL;
DWORD dwReservedSize=0;
DWORD dwCheckSum=0;
DWORD dwFile_ChecksumSize;
DWORD j;
BOOL bRet = FALSE;
int i, nSteps;
//Yang Jian: we boundary scan now, so that we return false only
if(g_dwTransport == ATLAS_TRANSPORT_JTAG)
return FALSE;
if(!file.Open(lpcstrFile, CFile::modeRead))
return FALSE;
DWORD dwFileSize = file.GetLength();
switch(dwImgType)
{
case ATLAS_IMAGE_WINDOWS_CE_NBOOT:
dwReservedSize=g_atlasdevinfo.dwNBootReservedSize;
break;
case ATLAS_IMAGE_WINDOWS_CE_EBOOT:
dwReservedSize=g_atlasdevinfo.dwEbootReservedSize;
break;
case ATLAS_IMAGE_WINDOWS_NANDXIP:
dwReservedSize=g_atlasdevinfo.dwNandXIPInfo>>16;
break;
case ATLAS_IMAGE_WINDOWS_CE_DM:
dwReservedSize=g_atlasdevinfo.dwDMReservedSize;
break;
default:
dwReservedSize=0xffffffff;
break;
}
if(dwFileSize>dwReservedSize)
{
MessageBox(AfxGetMainWnd()->m_hWnd,"The image size more than the device reserved size,Than it can't download into device.",
"AltasMgr",MB_OK);
goto FreeAndExit;
}
TRACE("Begin to download image ------\r\n");
if(!AtlasRequestImageBuf(dwFileSize, deviceAddr))
{
TRACE("RequestImageBuf failed\r\n");
goto FreeAndExit;
}
if(!AtlasSetNandCS(dwTargetMedia))
{
TRACE("AtlasSetNandCS failed\r\n");
goto FreeAndExit;
}
if(!AtlasSetCurImageType(dwImgType))
{
TRACE("AtlasSetNandCS failed\r\n");
goto FreeAndExit;
}
Sleep(500);
dwFile_ChecksumSize = dwFileSize + sizeof(dwCheckSum);
pBuf = new BYTE[dwFile_ChecksumSize];
if(pBuf == NULL)
goto FreeAndExit;
if(!AtlasOpenDownloadPipe())
goto FreeAndExit;
AfxGetApp()->BeginWaitCursor();
TRACE("Downloading....\r\n");
if ((dwFile_ChecksumSize % NBOOT_DATA_FRAME_LENGTH) == 0)
nSteps = dwFile_ChecksumSize / NBOOT_DATA_FRAME_LENGTH;
else
nSteps = (dwFile_ChecksumSize / NBOOT_DATA_FRAME_LENGTH) + 1;
file.Read(pBuf, dwFileSize);
//make check sum
for(j = 0; j < dwFileSize; j++)
{
dwCheckSum += *(pBuf+j);
}
//add check sum info end of the buf
memcpy((pBuf+dwFileSize),(PVOID)&dwCheckSum,sizeof(dwCheckSum));
for(i = 0; i < nSteps ; i++)
{
//file.Read(pBuf, NBOOT_DATA_FRAME_LENGTH);
TRACE("Downloading step=%d\r\n",i);
TRACE("%02x %02x %02x \r\n",pBuf[0],pBuf[1],pBuf[2]);
if(i != nSteps - 1)
{
if(!AtlasWriteBlock2Device((pBuf+i*NBOOT_DATA_FRAME_LENGTH), NBOOT_DATA_FRAME_LENGTH))
goto FreeAndExit;
}
else
{
if(!AtlasWriteLastBlock2Device((pBuf+i*NBOOT_DATA_FRAME_LENGTH), dwFile_ChecksumSize-(i*NBOOT_DATA_FRAME_LENGTH)))
goto FreeAndExit;
}
}
AfxGetApp()->EndWaitCursor();
bRet = AtlasWriteImage2Nand();
TRACE("WriteImage to Nand Ret=%x\r\n",bRet);
FreeAndExit:
if(pBuf)
delete pBuf;
file.Close();
AtlasCloseDownloadPipe();
TRACE("end to download image ++++++\r\n");
return bRet;
}
BOOL AtlasUpdateToc()
{
return AtlasUpdateNandToc();
}
BOOL AtlasGetOSBootStage(DWORD &dwBootStage)
{
return AtlasGetBootStage(dwBootStage);
}
BOOL AtlasSetFrameLength(DWORD dwFrameLength)
{
return AtlasSetDataBlockLength(dwFrameLength);
}
BOOL AtlasSyncDataBlock()
{
return AtlasSetDataBlock();
}
BOOL AtlasGetNandFlashBlockData(DWORD dwBlockIndex)
{
return AtlasGetNFBlockData(dwBlockIndex);
}
BOOL AtlasDumpNandFlashBlocks(CWnd *pWnd,DWORD dwCs, DWORD dwStartBlock, DWORD dwReadBlockCount,BOOL bSkipBadBlock)
{
BOOL bRet = TRUE;
BYTE *pbData;
CProgressDlg progress;
CString szDataFileName;
CString szSprFileName;
CFile DataFile;
CFile SprFile;
CFileDialog filesavedlg(FALSE,
NULL,
NULL,
OFN_OVERWRITEPROMPT,
"All Files (*)|*||");
CString szProcessBarText;
if(filesavedlg.DoModal() != IDOK)
return TRUE;
szDataFileName.Format("%s.bin",filesavedlg.GetPathName());
szSprFileName.Format("%s.spr",filesavedlg.GetPathName());
// DWORD dwReadBlockCount=dwEndBlock-dwStartBlock+1;
pbData = new BYTE[g_DumpNFInfo.dwPageSize*dwSectorsPerBlock];
progress.Create(pWnd);
szProcessBarText.Format("%d/%d",0,dwReadBlockCount);
progress.SetWindowText(szProcessBarText);
progress.SetStep(1);
progress.SetRange(0, dwReadBlockCount);
if(!DataFile.Open(szDataFileName,CFile::modeCreate|CFile::modeWrite))
return FALSE;
if(!SprFile.Open(szSprFileName,CFile::modeCreate|CFile::modeWrite))
{
DataFile.Close();
return FALSE;
}
for(DWORD i=0;i<dwReadBlockCount;i++)
{
AtlasGetNandFlashBlockData(dwStartBlock+i);
if(!ReadDumpNFData(pbData,g_DumpNFInfo.dwPageSize*dwSectorsPerBlock))
{
bRet=FALSE;
break;
}
progress.StepIt();
szProcessBarText.Format("%d/%d",i,dwReadBlockCount);
progress.SetWindowText(szProcessBarText);
DataFile.Write(pbData,dwBytesPerSector*dwSectorsPerBlock);
SprFile.Write(pbData+dwBytesPerSector*dwSectorsPerBlock,dwSpareDataLength*dwSectorsPerBlock);
if((((PSectorInfo)(pbData+dwBytesPerSector*dwSectorsPerBlock))->bBadBlock==0xFF) && bSkipBadBlock)
{
dwReadBlockCount++;
}
}
delete []pbData;
DataFile.Close();
SprFile.Close();
return bRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -