📄 main.cpp
字号:
//---------------------------------------------------------------------------
__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;
}
// clean Flash device info
HWStatusBarClear();
if(UpdateDA()) {
return;
}
// check BootLoader
if( NFB_OPERATION == g_OperationMethod ) {
BL_INFO bl_info;
if( FTHND_FILE_IS_UPDATED == BL_IsReady(g_BL_HANDLE, &bl_info, _TRUE) ) {
BL_LoadByFilepath(g_BL_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();
}
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 == BL_GetInfo(g_BL_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(AnsiString asMapFileName, bool bAutoLoad)
{
int ret;
unsigned short count;
// load scatter
if(ret=DL_LoadScatter(g_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;
}
asMap = asMapFileName;
if(bAutoLoad) {
// auto load download bin files
DL_AutoLoadByScatRegionName(g_DL_HANDLE, asMap.c_str(), NORMAL_ROM|RESOURCE_BIN|JUMPTABLE_BIN);
ROM_INFO rom_info;
if( FTHND_OK == (ret=DL_IsReady(g_DL_HANDLE, &rom_info, _TRUE)) ) {
// check if NFB enabled
_BOOL bIsNFB=_FALSE;
if( FTHND_OK == DL_IsNFB(g_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 load boot loader
if(bIsNFB) {
BL_AutoLoad(g_BL_HANDLE, asMap.c_str(), "*_BOOTLOADER_*.bin");
}
// auto select DA and baseband chip type
AutoSelectDAandBBChip();
}
else {
// reset to NOR operation
m_Menu_OPM_NORClick(NULL);
}
}
RedrawDownloadList();
return true;
}
//------------------------------------------------------------------------------
bool TMainForm::FileOpenLinkMapExecute()
{
int iLastDel=0;
if (ScatBaseDir.Length()>0)
{
OpenLdMapDialog->InitialDir = ScatBaseDir;
OpenLdMapDialog->FileName = "";
}
else if( 0 < ed_LinkMapFile->Text.Length() ) {
iLastDel = ed_LinkMapFile->Text.LastDelimiter("\\:");
if ( iLastDel > 0)
{
OpenLdMapDialog->InitialDir = ed_LinkMapFile->Text.SubString(1, iLastDel-1 );
OpenLdMapDialog->FileName = "";
}
}
if ( OpenLdMapDialog->Execute() )
{
if(Parse(OpenLdMapDialog->FileName, true)) {
iLastDel = asMap.LastDelimiter("\\:");
if ( iLastDel > 0)
{
ScatBaseDir = asMap.SubString(1, iLastDel-1 );
ROMBaseDir = ScatBaseDir;
}
return true;
}
else {
return false;
}
}
// do not add "else" !
return false;
}
//------------------------------------------------------------------------------
void __fastcall TMainForm::FileOpenLinkMapExecute(TObject *Sender)
{
FileOpenLinkMapExecute();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
unsigned int i;
int ret;
m_pUpdateListLock = new TCriticalSection();
// init META_DLL
META_Init(NULL);
DL_Create(&g_DL_HANDLE);
DA_Create(&g_DA_HANDLE);
RB_Create(&g_RB_HANDLE);
BL_Create(&g_BL_HANDLE);
lb_DA_File->Height =27;
ed_DA_File->Height = lb_DA_File->Height-2;
lb_LinkMapFile->Height =27;
ed_LinkMapFile->Height = lb_LinkMapFile->Height-2;
ed_DA_File->Top = lb_DA_File->Top;
ed_LinkMapFile->Top = lb_LinkMapFile->Top;
Timer_Download->Enabled = false;
UART_Com = NULL;
br_115200Execute(Sender); // new 2002.3.12
TIniFile *ini;
ini = new TIniFile(
ChangeFileExt( Application->ExeName, ".INI" ) );
// load download history
for(i=0; i<MAX_DOWNLOAD_HISTORY; i++) {
DownloadSet dl_set;
int file_count=0;
dl_set.m_Scatter = ini->ReadString("DL_HISTORY_"+IntToStr(i), "scatter_file", "");
if(dl_set.m_Scatter.IsEmpty()) {
break;
}
dl_set.m_BootLoader = ini->ReadString("DL_HISTORY_"+IntToStr(i), "bootloader", "");
dl_set.m_BootLoader_Enable = ini->ReadBool("DL_HISTORY_"+IntToStr(i), "bootloader_enable", true);
file_count = ini->ReadInteger("DL_HISTORY_"+IntToStr(i), "file_count", 1);
for(int j=0; j<file_count; j++) {
DownloadBinFile dl_bin;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -