📄 atlasapi.cpp
字号:
BOOL AtlasSetDataBlockLength(DWORD nLength)
{
if(g_dwTransport == ATLAS_TRANSPORT_USB)
{
if(!AtlasIsUsbOpened())
return FALSE;
g_msg.FormatMsg(ATLAS_MSG_SET_FRAME_LENGTH, (PBYTE)&nLength);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
return TRUE;
}
else if(g_dwTransport == ATLAS_TRANSPORT_RS232)
{
WORD w;
w = MAKEWORD(P_CMD_SET_REG, P_CMD_FRAME_LEN);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)nLength) == FALSE)
return FALSE;
return TRUE;
}
return FALSE;
}
BOOL AtlasSetDataBlock()
{
if(g_dwTransport == ATLAS_TRANSPORT_USB)
{
if(!AtlasIsUsbOpened())
return FALSE;
g_msg.FormatMsg(ATLAS_MSG_WRITE_DATA, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
return TRUE;
}
else if(g_dwTransport == ATLAS_TRANSPORT_RS232)
{
return TRUE;
}
return FALSE;
}
BOOL AtlasGetEBOOTPositon(DWORD dwCS,DWORD *pEbootStart,DWORD *pEbootEnd)
{
DWORD dwRet;
if(g_dwTransport == ATLAS_TRANSPORT_USB)
{
if(!AtlasIsUsbOpened())
return FALSE;
g_msg.FormatMsg(ATLAS_MSG_GET_EBOOT_POSITION, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&dwRet, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
*pEbootEnd=dwRet&0xffff;
*pEbootStart=dwRet>>16;
return TRUE;
}
else if(g_dwTransport == ATLAS_TRANSPORT_RS232)
{
return TRUE;
}
return FALSE;
}
BOOL AtlasGetNfInfo(DWORD dwCS)
{
if(g_dwTransport == ATLAS_TRANSPORT_USB)
{
if(!AtlasIsUsbOpened())
return FALSE;
g_msg.FormatMsg(ATLAS_MSG_GET_NF_INFO, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_DumpNFInfo, g_msg.GetMsg()->dataBuf, sizeof(DumpNFInfo));
return TRUE;
}
else if(g_dwTransport == ATLAS_TRANSPORT_RS232)
{
return TRUE;
}
return FALSE;
}
BOOL AtlasInitJTAG()
{
return InitializeWinIo();
}
BOOL AtlasDeinitJTAG()
{
ShutdownWinIo();
return TRUE;
}
BOOL AtlasJTAGDownImage(LPCSTR lpszFileName,int cs)
{
return JtagDownloadImage(lpszFileName,cs);
}
BOOL AtlasGetDeviceInfo()
{
memset(&g_atlasdevinfo,0,sizeof(ATLAS_DEV_INFO));
if(g_dwTransport == ATLAS_TRANSPORT_USB)
{
if(!AtlasIsUsbOpened())
return FALSE;
g_msg.FormatMsg(ATLAS_MSG_GET_BOOTLOADER_VERSION, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwBootloaderVer, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_CPU_INFO, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwProcessorInfo, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_HARDWARE_NAME, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(g_atlasdevinfo.szHardwareName, g_msg.GetMsg()->dataBuf, 20);
g_msg.FormatMsg(ATLAS_MSG_GET_SOFTWARE_NAME, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(g_atlasdevinfo.szSoftwareName, g_msg.GetMsg()->dataBuf, 20);
g_msg.FormatMsg(ATLAS_MSG_GET_IMG_TYPE, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(g_atlasdevinfo.szImageType, g_msg.GetMsg()->dataBuf, 20);
g_msg.FormatMsg(ATLAS_MSG_GET_NANDXIP_INFO, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwNandXIPInfo, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_EBOOT_RESERVEDBLOCKS, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwEbootReservedSize, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_DM_RESERVEDBLOCKS, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwDMReservedSize, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_NK_RESERVEDBLOCKS, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwNKReservedSize, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_NBOOT_RESERVEDBLOCKS, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwNBootReservedSize, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
g_msg.FormatMsg(ATLAS_MSG_GET_BOOT_STAGE, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&g_atlasdevinfo.dwBootStage, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
/* CString s;
s.Format("%x-%d-%d-%d-%d",g_atlasdevinfo.dwNandXIPInfo,
g_atlasdevinfo.dwEbootReservedSize,g_atlasdevinfo.dwDMReservedSize,
g_atlasdevinfo.dwNKReservedSize,g_atlasdevinfo.dwNBootReservedSize);
MessageBox(AfxGetMainWnd()->m_hWnd,s,"",MB_OK);*/
return TRUE;
}
else if(ATLAS_TRANSPORT_RS232 == g_dwTransport)
{
WORD w;
DWORD dwRetrievedData;
w = MAKEWORD(P_CMD_GET_REG, P_CMD_BOOT_STAGE);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)&dwRetrievedData) == FALSE)
return FALSE;
memcpy(&g_atlasdevinfo.dwBootStage, &dwRetrievedData, sizeof(DWORD));
TRACE("Bootstage is %x\r\n",g_atlasdevinfo.dwBootStage);
w = MAKEWORD(P_CMD_GET_REG, P_CMD_NBOOT_RESERVED_BYTE);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)&dwRetrievedData) == FALSE)
return FALSE;
memcpy(&g_atlasdevinfo.dwNBootReservedSize, &dwRetrievedData, sizeof(DWORD));
w = MAKEWORD(P_CMD_GET_REG, P_CMD_EBOOT_RESERVED_BYTE);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)&dwRetrievedData) == FALSE)
return FALSE;
memcpy(&g_atlasdevinfo.dwEbootReservedSize, &dwRetrievedData, sizeof(DWORD));
w = MAKEWORD(P_CMD_GET_REG, P_CMD_DM_RESERVED_BYTE);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)&dwRetrievedData) == FALSE)
return FALSE;
memcpy(&g_atlasdevinfo.dwDMReservedSize, &dwRetrievedData, sizeof(DWORD));
w = MAKEWORD(P_CMD_GET_REG, P_CMD_NK_RESERVED_BYTE);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)&dwRetrievedData) == FALSE)
return FALSE;
memcpy(&g_atlasdevinfo.dwNKReservedSize, &dwRetrievedData, sizeof(DWORD));
w = MAKEWORD(P_CMD_GET_REG, P_CMD_XIP_INFO);
if (AtlasSendRs232Msg(WM_API_COMMAND, (WPARAM)w, (LPARAM)&dwRetrievedData) == FALSE)
return FALSE;
memcpy(&g_atlasdevinfo.dwNandXIPInfo, &dwRetrievedData, sizeof(DWORD));
return TRUE;
}
else
return FALSE;
}
BOOL AtlasGetUsbPipeIndex(DWORD &dwDownloadIndex, DWORD &dwDevStatusIndex, DWORD &dwDbgMsgToDevIndex, DWORD &dwDbgMsgFromDevIndex)
{
DWORD dwIndex;
g_msg.FormatMsg(ATLAS_MSG_GET_USB_PIPE_INDEX, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
memcpy(&dwIndex, g_msg.GetMsg()->dataBuf, sizeof(DWORD));
dwDownloadIndex = dwIndex & 0xff;
dwDevStatusIndex = (dwIndex >> 8) & 0xff;
dwDbgMsgToDevIndex = (dwIndex >> 16) & 0xff;
dwDbgMsgFromDevIndex = (dwIndex >> 24) & 0xff;
return TRUE;
}
BOOL AtlasGetDevStatus(DWORD &dwDevStatus,UINT &nReadBytes)
{
return g_usb.ReadPipe(g_usbPipeIndexInfo.dwStatusIndex, (PBYTE)&dwDevStatus, sizeof(DWORD),nReadBytes);
}
BOOL AtlasBeginSession()
{
g_msg.FormatMsg(ATLAS_MSG_BEGIN_SESSION, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
return TRUE;
}
BOOL AtlasEndSession()
{
g_msg.FormatMsg(ATLAS_MSG_END_SESSION, NULL);
if(!g_usb.SendVendorCommand(g_msg.GetMsg()))
return FALSE;
return TRUE;
}
BOOL AtlasWriteDbgMsg(char * pMsg)
{
char * p = pMsg;
UINT nBytesWriten;
DWORD len = strlen(p);
if(len == 0)
return TRUE;
while(len)
{
if(len > 16)
{
if(!(g_usb.WritePipe(g_usbPipeIndexInfo.dwMessageInIndex, (PBYTE)p, 16, nBytesWriten) && nBytesWriten== 16))
return FALSE;
p += 16;
len -= 16;
}
else
{
if(!(g_usb.WritePipe(g_usbPipeIndexInfo.dwMessageInIndex, (PBYTE)p, len, nBytesWriten) && nBytesWriten == len))
return FALSE;
p+= len;
len = 0;
}
}
return TRUE;
}
BOOL g_bInNboot = TRUE;
#define ONCEREADBYTES (64*1024 )
BOOL ReadDumpNFData(BYTE *pByte,DWORD dwCount)
{
DWORD dwTimes=dwCount/ONCEREADBYTES;
UINT nReadBytes;
memset(pByte,0,dwCount);
for(DWORD i=0;i<dwTimes;i++)
{
if(!(g_usb.ReadPipe(2,pByte+i*ONCEREADBYTES,ONCEREADBYTES,nReadBytes) && nReadBytes))
{
TRACE("Got a zero length packet");
return FALSE;
}
}
if(dwCount%ONCEREADBYTES)
{
if(!(g_usb.ReadPipe(2,pByte+dwTimes*ONCEREADBYTES,dwCount%ONCEREADBYTES, nReadBytes) && nReadBytes))
{
TRACE("Read error or got a zero length packet\r\n");
return FALSE;
}
}
return TRUE;
}
UINT TerminalThread( LPVOID pParam )
{
DWORD dwDeviceStatus = 0;
BYTE * message;
UINT nLen;
TRACE("TerminalThread Started");
g_bInNboot = TRUE;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);
while(TRUE)
{
Sleep(10);
if(g_hWnd == NULL)
return 0;
//TRACE(" Try to read status\r\n");
if(!(AtlasGetDevStatus(dwDeviceStatus,nLen) && nLen))
{
TRACE("Failed to get device status. Exit");
::SendMessage(g_hWnd, WM_ATALS_CONNECT_BROKEN, (WPARAM)message, (LPARAM)0);
return 0;
}
//TRACE(" dwDeviceStatus %d\r\n", dwDeviceStatus);
switch(dwDeviceStatus)
{
case ATLAS_DEV_STATUS_SENDING_MSG_EBOOT:
if(g_bInNboot)
{
TRACE("Bootloader changed\r\n");
g_bInNboot = FALSE;
::SendMessage(g_hWnd, WM_ATLAS_DBG_ENTER_EBOOT, (WPARAM)message, (LPARAM)0);
}
//Fall through
case ATLAS_DEV_STATUS_SENDING_MSG_NBOOT:
message = new BYTE[260];
if( g_usb.ReadPipe(g_usbPipeIndexInfo.dwMessageOutIndex, message, 256 , nLen) && nLen)
{
if(nLen == 0)
{
delete message;
}
else
{
message[nLen] = 0;
if(strlen((char*)message) == 0)
{
delete message;
}
else
{
//The recieve wnd should delete this
::PostMessage(g_hWnd, WM_ATLAS_DBG_OUT_MESSAGE, (WPARAM)message, (LPARAM)0);
}
}
}
else
{
TRACE("Got a zero length packet");
delete message;
}
Sleep(5);
break;
case ATLAS_DEV_STATUS_IDLE_EBOOT:
if(g_bInNboot)
{
TRACE("Bootloader changed\r\n");
g_bInNboot = FALSE;
::SendMessage(g_hWnd, WM_ATLAS_DBG_ENTER_EBOOT, (WPARAM)message, (LPARAM)0);
}
case ATLAS_DEV_STATUS_IDLE_NBOOT:
Sleep(10);
break;
case ATLAS_DEV_STATUS_IN_USB_SESSION_EBOOT:
if(g_bInNboot)
{
TRACE("Bootloader changed\r\n");
g_bInNboot = FALSE;
::SendMessage(g_hWnd, WM_ATLAS_DBG_ENTER_EBOOT, (WPARAM)message, (LPARAM)0);
}
break;
case ATLAS_DEV_STATUS_DOWNLOADING_CE_5_IMG_EBOOT:
::SendMessage(g_hWnd, WM_ATLAS_DBG_DOWNLOAD_NK_5, (WPARAM)message, (LPARAM)0);
break;
case ATLAS_DEV_STATUS_DOWNLOADING_CE_4_IMG_EBOOT:
::SendMessage(g_hWnd, WM_ATLAS_DBG_DOWNLOAD_NK_4, (WPARAM)message, (LPARAM)0);
break;
case ATLAS_DEV_STATUS_DUMP_NF:
::SendMessage(g_hWnd,WM_ATLAS_DUMP_NF,(WPARAM)message, (LPARAM)0);
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -