?? main.cpp
字號:
OptionMethod_E g_OperationMethod;
NUTL_EraseFlag_E g_EraseFlag;
bool g_bNFI_SelectCS1 = false;
unsigned short g_PacketLength=256;
unsigned int g_MaxBromStartCmdRetryCount=DEFAULT_BROM_START_CMD_RETRY_COUNT;
DL_HANDLE_T g_DL_HANDLE = NULL;
DL_HANDLE_LIST_T g_DL_HANDLE_LIST = NULL;
std::vector<DL_HANDLE_T> g_DL_HANDLE_LIST_nodes;
DA_HANDLE_T g_DA_HANDLE = NULL;
RB_HANDLE_T g_RB_HANDLE = NULL;
BL_HANDLE_T g_BL_HANDLE = NULL;
unsigned int g_CostTimeSec;
unsigned int g_ProgressTimeSec;
unsigned int g_DisplayFinishedBytes;
int g_stopflag;
EMI_Config_S g_EMI_Config[8];
DRAM_NFI_Setting g_EMI_NFI_Setting={ 0, false, 0, 0, 0, 0, 0, 0 }; // apply BootLoader's DRAM setting by default
AnsiString g_asNormalModeDAPath;
AnsiString g_asTestModeDAPath;
//int iDownloadDataNACK_Count =0;
TargetDownloadErrorCount TDEC;
int iGlobal_Progress;
AnsiString asGlobal_StatusBar0Text;
TTreeNode * g_rootLoad;
static bool OpenReadDA_File( AnsiString asFileName)
{
int ret;
if(ret=DA_LoadByFilepathEx(g_DA_HANDLE, asFileName.c_str(), g_bDebugDA?_FALSE:_TRUE)) {
if( FTHND_HANDLE_BUSY_NOW == ret ) {
ShowMessage("Program is busy! Can not reload DA right now.");
}
else if( FTHND_DA_INVALID == ret ) {
ShowMessage(" \"" + asFileName + "\" is not a valid DA format!");
}
else {
ShowMessage(" Load DA \"" + asFileName + "\" fail!");
}
return false;
}
MainForm->ed_DA_File->Text = asFileName;
return true;
}
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
static unsigned char change_DA_BaudRate_to_BROM_BaudRate( unsigned char uc_baud_rate )
{
switch ( uc_baud_rate )
{
case UART_BAUD_460800 :
case UART_BAUD_230400 :
return UART_BAUD_4800; // High speed
case UART_BAUD_115200 :
case UART_BAUD_57600 :
case UART_BAUD_38400 :
case UART_BAUD_19200 :
default:
return UART_BAUD_19200; // Normal speed
} // switch;
}
//----------------------------------------------------------------------
void __fastcall TMainForm::Download1Click(TObject *Sender)
{
int i;
int RealReadLen =0;
g_flashtool_function = FLASHTOOL_DOWNLOAD;
if ( MT6208!=g_BBCHIP_TYPE && asBin.IsEmpty() )
if (! FileOpenDownloadAgentExecute() )
{
ShowMessage(" You must open download agent file before downloading. ");
return;
}
if ( !g_bDebugDA && asMap.IsEmpty() )
if ( ! FileOpenLinkMapExecute() )
{
ShowMessage(" You must open link map file before downloading. ");
return;
}
if ( !g_bDebugDA && mi_MultiLoad->Checked){
int handleNumber = 0;
DL_GetHandleNumber(g_DL_HANDLE_LIST,&handleNumber);
if( 0 == handleNumber){
ShowMessage(" You must add at least 1 load in Multi-Load mode. ");
return ;
}
}
// clean Flash device info
HWStatusBarClear();
if(UpdateDA()) {
return;
}
// check BootLoader
if( NFB_OPERATION == g_OperationMethod ) {
BL_INFO bl_info;
if( FTHND_FILE_IS_UPDATED == DL_BL_IsReady(g_DL_HANDLE, &bl_info, _TRUE) ) {
DL_BL_LoadByFilepath(g_DL_HANDLE, bl_info.m_filepath);
}
}
int ret;
AnsiString s1, s2;
ROM_INFO rom_info;
while(ret=DL_IsReady(g_DL_HANDLE, &rom_info, _TRUE)) {
if( FTHND_FILE_IS_UPDATED == ret ) {
if(DL_Rom_LoadByFilepath(g_DL_HANDLE, rom_info.index, rom_info.filepath)) {
s1 = rom_info.name;
s2 = rom_info.filepath;
if( FTHND_SCAT_REGION_IS_OVERLAP == ret ) {
#if 0
/* // reload all multibin files
ret = DL_AutoLoadByScatRegionName(g_DL_HANDLE, rom_info.filepath, NORMAL_ROM|RESOURCE_BIN|JUMPTABLE_BIN);
if( FTHND_OK == ret ) {
break;
}
else {
ShowMessage( "\"" + s2 + "\" is too large and causes region overlap!\nTry to reload all multi-bin files but it's failed!");
return;
}
}*/
#else
ShowMessage( "\"" + s2 + "\" is too large and causes region overlap!");
return;
}
#endif
else {
ShowMessage(" Load " + s1 + " from file \"" + s2 + "\" fail!");
return;
}
}
}
else {
break;
}
}
if(g_bDebugDA) {
DebugDAWindow->Text = "";
}
else {
// auto select DA and baseband chip type
AutoSelectDAandBBChip(g_DL_HANDLE);
}
if(!g_bDebugDA) {
// construct current download set
DownloadSet dl_set;
{
// get scatter file path
dl_set.m_Scatter = asMap;
// get bin file info
unsigned short count=0;
if( (FTHND_OK==DL_GetCount(g_DL_HANDLE, &count)) && (0<count) ) {
ROM_INFO rom[MAX_LOAD_SECTIONS];
if( FTHND_OK == DL_Rom_GetInfoAll(g_DL_HANDLE, rom, MAX_LOAD_SECTIONS) ) {
for(i=0; i<count; i++) {
DownloadBinFile dl_bin;
dl_bin.m_Filepath = rom[i].filepath;
dl_bin.m_Enable = rom[i].enable?true:false;
dl_set.m_BinFiles.push_back(dl_bin);
}
}
}
// check if NFB enabled
_BOOL bIsNFB=_FALSE;
if( FTHND_OK == DL_IsNFB(g_DL_HANDLE, &bIsNFB) ) {
if(bIsNFB) {
// get BootLoader info
BL_INFO bl_info;
if( FTHND_OK == DL_BL_GetInfo(g_DL_HANDLE, &bl_info) ) {
dl_set.m_BootLoader = bl_info.m_filepath;
dl_set.m_BootLoader_Enable = bl_info.m_enable?true:false;
}
}
}
}
// update download history
DownloadHistoryList::iterator iter;
for(iter=g_DownloadHistory.begin(); iter!=g_DownloadHistory.end(); iter++) {
if( dl_set == (*iter) ) {
if( iter != g_DownloadHistory.begin() ) {
// if download set already exist, move it to the top of history
g_DownloadHistory.erase(iter);
g_DownloadHistory.push_front(dl_set);
}
goto download;
}
}
// delete the oldest history
if( MAX_DOWNLOAD_HISTORY == g_DownloadHistory.size() ) {
g_DownloadHistory.pop_back();
}
// insert new download set to the top of history
g_DownloadHistory.push_front(dl_set);
}
download:
if( MT6205 != g_BBCHIP_TYPE )
start_DL(true);
else
Form_DL_GO->ShowModal();
}
//------------------------------------------------------------------------------
void TMainForm::start_DL( bool b_start_DL )
{
g_CostTimeSec = 0; // reset download time
g_ProgressTimeSec = 0;
sb_Main->Panels->Items[4]->Text = " 0:00 sec ";
p1 = new tboot_1( true );
p1->FreeOnTerminate = true;
p1->Resume();
}
//---------------------------------------------------------------------------
bool TMainForm::FileOpenDownloadAgentExecute()
{
// index = 0; // ??
static AnsiString asDA_Path;
int iLastDel=0;
if (asDA_Path.Length()>0)
{
OpenDownloadAgentDialog->InitialDir = asDA_Path;
}
else if( 0 < ed_DA_File->Text.Length() ) {
iLastDel = ed_DA_File->Text.LastDelimiter("\\:");
if ( iLastDel > 0)
{
OpenDownloadAgentDialog->InitialDir = ed_DA_File->Text.SubString(1, iLastDel-1 );
}
}
if ( OpenDownloadAgentDialog->Execute() ) // *.bin file
{
if ( OpenReadDA_File( OpenDownloadAgentDialog->FileName ))
{
asBin = OpenDownloadAgentDialog->FileName;
if(g_bDebugDA) {
// save TestMode DA path
g_asTestModeDAPath = asBin;
}
else {
// save NormalMode DA path
g_asNormalModeDAPath = asBin;
}
iLastDel = asBin.LastDelimiter("\\:");
if ( iLastDel > 0)
{
asDA_Path = asBin.SubString(1, iLastDel-1 );
}
return true;
}
else
return false;
}
else
return false;
}
void __fastcall TMainForm::FileOpenDownloadAgentExecute(TObject *Sender)
{
FileOpenDownloadAgentExecute();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OptionsSetupExecute(TObject *Sender)
{
// OptiForm->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::test_tray_iconClick(TObject *Sender)
{
// TrayIcon1->Animate = true;
}
//---------------------------------------------------------------------------
bool TMainForm::Parse(DL_HANDLE_T dl_handle,AnsiString asMapFileName, bool bAutoLoad)
{
int ret;
unsigned short count;
// load scatter
if(ret=DL_LoadScatter(dl_handle, asMapFileName.c_str())) {
if( FTHND_HANDLE_BUSY_NOW == ret ) {
ShowMessage("Program is busy! Can not reload scat file right now.");
}
else if( FTHND_SCAT_OFFSET_IS_NOT_WORD_ALIGN == ret ) {
ShowMessage("Failed to load scatter file \"" + asMapFileName + "\"!\n\nThe offset value of one load region is not WORD alignment!");
}
else if( FTHND_SCAT_ADDR_IS_NOT_WORD_ALIGN == ret ) {
ShowMessage("Failed to load scatter file \"" + asMapFileName + "\"!\n\nThe region begin address of one load region is not WORD alignment!");
}
else if( FTHND_SCAT_ADDR_IS_NOT_ASCENDING_ORDER == ret ) {
ShowMessage("Failed to load scatter file \"" + asMapFileName + "\"!\n\nThe region begin address of one load region is not ascending sorting sequence!");
}
else {
ShowMessage("Incorrect scatter file format!");
}
return false;
}
if( dl_handle == g_DL_HANDLE){
asMap = asMapFileName;
}
if(bAutoLoad) {
// auto load download bin files
DL_AutoLoadByScatRegionName(dl_handle, asMapFileName.c_str(), NORMAL_ROM|RESOURCE_BIN|JUMPTABLE_BIN);
ROM_INFO rom_info;
if( FTHND_OK == (ret=DL_IsReady(dl_handle, &rom_info, _TRUE)) ) {
// check if NFB enabled
_BOOL bIsNFB=_FALSE;
if( FTHND_OK == DL_IsNFB(dl_handle, &bIsNFB) ) {
// update operation method
if( bIsNFB && (NFB_OPERATION!=g_OperationMethod) ) {
m_Menu_OPM_NFBClick(NULL);
}
else if( !bIsNFB && (NFB_OPERATION==g_OperationMethod) ) {
m_Menu_OPM_NORClick(NULL);
}
}
// auto select DA and baseband chip type
AutoSelectDAandBBChip(dl_handle);
}
else {
// reset to NOR operation
m_Menu_OPM_NORClick(NULL);
}
}
RedrawDownloadList(dl_handle);
return true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -