📄 dload.cpp
字号:
// dload.cpp :
//
// NAME: BurnFlash.cpp
//--------------------------------------------------------------------------------------------------
//
// GENERAL DESCRIPTION
//
// This module defines the entry point for the console application.
//--------------------------------------------------------------------------------------------------
//
// Revision History:
// Modification Tracking
// Author Date Number Description of Changes
// ------------------------- ------------ ---------- ----------------------------------------
/*
when who what, where, why
-------- -------- ---------------------------------------------------------------
01/20/05 nony.wu change surfcr.bin to surfcmos.bin
============================================================================ */
//
//
// Portability:
// This module can be portable to other C++ compilers or Win32 platforms.
//
//--------------------------------------------------------------------------------------------------
// INCLUDE FILES
//--------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include "dload.h"
#include "common.h"
#include "UART.h"
#include "Hex2Bin.h"
#include "BurnFlash.h"
#include "ProcDiag.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//--------------------------------------------------------------------------------------------------
// STRUCTURES AND OTHER TYPEDEFS
//--------------------------------------------------------------------------------------------------
enum {
SWITCH,
DLOAD_SW,
DLOAD_ALL,
MAX_OPR_NUM
};
char* OprArray[]=
{
"SWITCH",
"CODE",
"ALL"
};
char* OprString[] =
{
"convert code from hex to binary",
"download phone code",
"download phone code"
};
char* ResultString[] =
{
"successfully",
"failed: NO_VALID_RAM_FILE",
"failed: ERR_NO_VALID_PHONE_FILE",
"failed: ERR_NO_VALID_TARGET_FILE",
"failed: ERR_NO_VALID_TARGET_FILE",
"failed: ERR_SND_CHG_TO_OFFLINE_CMD",
"failed: ERR_SND_DLOAD_CMD",
"failed: ERR_SND_RAM_FILE",
"failed: ERR_COMM_FAIL",
"failed: ERR_ERASE_FLASH_FAIL",
"failed: ERR_WRITE_FLASH_FAIL",
"failed: ERR_RESET_PHONE_FAIL",
"failed: ERR_UNKNOWN"
};
//--------------------------------------------------------------------------------------------------
// GLOBAL VARIABLES
//--------------------------------------------------------------------------------------------------
CWinApp theApp;
using namespace std;
int baudrate=999;
void DispHelp();
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
int nRlt = SUCCESS;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("Fatal Error: MFC initialization failed") << endl;
return 1;
}
//check the invalid parameters
if(argc != 2 && argc != 3 && argc !=4)
{
DispHelp();
return 1;
}
//check the first parameter
char *pOpr = _strupr(argv[1] + 1);
for(int opr= 0; opr < MAX_OPR_NUM; opr++)
{
if(strcmp(pOpr, OprArray[opr]) == 0)
break;
}
if( opr == MAX_OPR_NUM)
{
DispHelp();
return 1;
}
//check the second parameter
int nPort = COM1;
if(argc >= 3)
{
pOpr = _strupr(argv[2] + 1);
if(strcmp(pOpr, "COM1") == 0)
nPort = COM1;
else if(strcmp(pOpr, "COM2") == 0)
nPort = COM2;
else if(strcmp(pOpr, "COM3") == 0)
nPort = COM3;
else if(strcmp(pOpr, "COM4") == 0)
nPort = COM4;
else if(strcmp(pOpr, "COM5") == 0)
nPort = COM5;
else if(strcmp(pOpr, "COM6") == 0)
nPort = COM6;
else if(strcmp(pOpr, "COM7") == 0)
nPort = COM7;
else if(strcmp(pOpr, "COM8") == 0)
nPort = COM8;
else if(strcmp(pOpr, "COM9") == 0)
nPort = COM9;
else if(strcmp(pOpr, "COM10") == 0)
nPort = COM10;
else
{
DispHelp();
return 1;
}
}
//check the third parameter
if(argc >= 4)
{
pOpr = _strupr(argv[3] + 1);
if(strcmp(pOpr, "UT0") == 0)
baudrate= 0;
else if(strcmp(pOpr, "UT1") == 0)
baudrate= 1;
else if(strcmp(pOpr, "UT2") == 0)
baudrate= 2;
else if(strcmp(pOpr, "UT4") == 0)
baudrate= 4;
else
{
DispHelp();
return 1;
}
}
//init the serial port
if(!theComm.InitComm(nPort))
{
cout << TAB_PROMPT << "init comm failed!" << endl;
return 1;
}
// execute all kinds of actions
cout << endl;
cout << TAB_OPR << "start to " << OprString[opr] << endl;
switch(opr)
{
case SWITCH:
if(!theCnvrt.GoGoGo("surfcmos.hex"))
nRetCode = ERR_UNKNOWN;
else
cout << TAB_SUB_OPR << "create a binary file: surfcmos.bin." <<endl;
break;
case DLOAD_SW:
nRetCode = theFlash.LoadData("surfcmos.bin", CODE_BASE, CODE_SIZE, TRUE);
break;
case DLOAD_ALL:
nRetCode = theFlash.LoadData("surfcmos.bin", CODE_BASE, ALL_SIZE, TRUE);
break;
}
if(opr == DLOAD_SW || opr == DLOAD_ALL)
theFlash.ResetPhone();
cout << TAB_OPR << OprString[opr] << " "<< ResultString[nRetCode] << endl;
theComm.CloseComm();
return 0;
}
void DispHelp()
{
cout<<" dload -switch: convert the hex file to bin file."<<endl;
cout<<" dload -all: erase all the flash memory, the NV and"<<endl;
cout<<" EFS will rebuild when power up."<<endl;
cout<<" dload -code: only erase the 8M code region, the NV"<<endl;
cout<<" and EFS will not rebuild when power up."<<endl;
cout<<" -com[n]: n support 1-10 "<<endl;
cout<<" -ut[n]: n support 0,1,2,4"<<endl;
cout<<" ut0: 57600 ut1: 115200 "<<endl;
cout<<" ut2: 230400 ut4: 460800"<<endl;
cout<<" dload -code -com8 -ut0: use com8, uart 57600 "<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -