www.pudn.com > FlashTool_src_v2.9.1006.zip > tboot_1.cpp
/***************************************************************************** * Copyright Statement: * -------------------- * This software is protected by Copyright and the information contained * herein is confidential. The software may not be copied and the information * contained herein may not be used or disclosed except with the written * permission of MediaTek Inc. (C) 2002 * *****************************************************************************/ /******************************************************************************* * Filename: * --------- * tboot_1.cpp * * Project: * -------- * Flash tool set * * Description: * ------------ * a thread * 1.write command to Boot ROM * 2.then jump to execute download agent * * Author: * ------- * FZ Hsu (mtk00303) * *============================================================================== * HISTORY * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! *------------------------------------------------------------------------------ * $Revision: 1.37 $ * $Modtime: Jan 13 2006 21:45:40 $ * $Log: //mtkvs01/vmdata/flash_tool/archives/tboot_1.cpp-arc $ * * Aug 11 2006 mtk01413 * [STP100001053] FlashTool v2.9.1004 release * Bug fixes: * 1. [BROM_DLL] Fix Test DA download fail on MT6205/MT6205B. * * Jul 21 2006 mtk01413 * [STP100001021] FlashTool v2.9.1002 release * * * Jun 12 2006 mtk01413 * [STP100000922] FlashTool v2.9.1001 release * New features: * 1. [FlashTool/BROM_DLL] Support Multi-Load Autodetection Download. * * * May 24 2006 mtk01413 * [STP100000879] FlashTool v2.8.1001 release * 1. [FlashTool][NEW] Support 6229 Download, add m_emi_gen_c in DRAM setting * 2. [FlashTool][BUG_FIX] Fix a bug to prevent Scroll back to Page1 when redrawing Test DA message. * * * Mar 22 2006 mtk00539 * [STP100000703] FlashTool v2.7.1017 * [FlashTool] Use known BBCHIP_TYPE and EXT_CLOCK to increase start command hit rate in "Reset to Factory Default" procedure. * * Rev 1.37 Jan 14 2006 00:49:58 mtk00539 * Bug fixes: * 1. [FlashTool] Fix scatter file path doesn't update on UI. * * Enhancements: * 1. [FlashTool] Record normal mode and test mode DA path separatedly. * Resolution for 159: [FlashTool v2.7.1015] * * Rev 1.36 Jan 04 2006 14:23:30 mtk00539 * 1. [FlashTool] Fix NFI CS1 device takes no effect problem while selecting "enable NFI-CS1" flag. * Resolution for 158: [FlashTool v2.7.1014][New] Support Spansion MirrorBit Buffer-Program method. * * Rev 1.35 Dec 29 2005 10:57:26 mtk00539 * 1. [FlashTool] Add download history feature. * Resolution for 156: [FlashTool v2.7.1013][BUG FIX] Fix BootROM start command failure while manually selecting NMT6226 or MT6227 baseband chip. * * Rev 1.34 Oct 19 2005 14:47:26 mtk00539 * 1. [FlashTool][New] Adapt new BROM_DLL&DA v2.7.1008. * Resolution for 141: [FlashTool v2.7.1008][New] Support NFB download and many new features. * * Rev 1.33 May 24 2005 20:03:42 mtk00539 * 1. [FlashTool][New] Reset FAT to factory default setting. * 2. [FlashTool][New] Option to enable/disable resource project id comparison. * Resolution for 116: [FlashTool v2.6.1012][New] Reset FAT to factory default setting. * * Rev 1.32 Feb 16 2005 17:27:44 mtk00539 * 1. [FlashTool][New] Adapt new BROM_DLL&DA v2.4.1009 to support SPANSION S71AL016D and SHARP LRS18C8A flash. * 2. [FlashTool][Enhance] Allow to setup EMI setting in TestMode. * 3. [FlashTool][Enhance] Keep TestMode unless you disable it. In order to allow users to do test continuously. * 4. [FlashTool][Enhance] Add CTRL+S hot-key to save TestMode log into file. * Resolution for 106: [FlashTool v2.6.1009][New] Adapt new BROM_DLL&DA v2.4.1009 to support SPANSION S71AL016D and SHARP LRS18C8A flash. * * Rev 1.31 Nov 30 2004 14:22:42 mtk00539 * Modify the skip auto-format warning message. * Resolution for 100: [FlashTool v2.6.1008][New] Adapt new BROM_DLL&DA v2.4.1008 to enable/disable speed-up baudrate in BootROM stage. * * Rev 1.30 Nov 25 2004 09:59:00 mtk00539 * tboot_1::InitProgress() should not intialize g_ProgressTimeSec = 0 while bUpdateFinishBytes is false. * Resolution for 100: [FlashTool v2.6.1008][New] Adapt new BROM_DLL&DA v2.4.1008 to enable/disable speed-up baudrate in BootROM stage. * * Rev 1.29 Nov 22 2004 14:30:12 mtk00539 * 1. [FlashTool][New] Adapt new BROM_DLL&DA v2.4.1008 to enable/disable speed-up baudrate in BootROM stage. * Resolution for 100: [FlashTool v2.6.1008][New] Adapt new BROM_DLL&DA v2.4.1008 to enable/disable speed-up baudrate in BootROM stage. * * Rev 1.28 Nov 05 2004 10:40:04 mtk00539 * 1. [FlashTool][New] Adapt new BROM_DLL&DA v2.4.1007 to support S/W compatible mechanism for MT6218B_FN and MT6218B_GN and some enhancement. * Resolution for 97: [FlashTool v2.6.1007][New] Adapt new BROM_DLL&DA v2.4.1007 to support S/W compatible mechanism for MT6218B_FN and MT6218B_GN and some enhancement. * * Rev 1.27 Oct 29 2004 11:49:22 mtk00539 * 1. [FlashTool][New] Adapt new BROM_DLL&DA v2.4.1006 to fix AM49DL3208GT & S71PL032J download fail problem and some enhancement. * 2. [FlashTool][New] Add auto-detect base band chip type flag. * Resolution for 1: META MAUI v1.0 * * Rev 1.26 Sep 17 2004 17:04:08 mtk00539 * process new error code FT_DA_HW_ERROR * Resolution for 91: [FlashTool v2.6.1005][New] Adapt new BROM_DLL&DA v2.4.1005 to fix MT6217 download fail problem. * * Rev 1.25 Aug 03 2004 22:42:28 mtk00539 * remove unnecessar include files * * Rev 1.24 Aug 03 2004 15:07:06 mtk00539 * [FlashTool v2.6.1002][New] Adapt with BROM_DLL v2.4.1002 and many enhancement. * * Reason: * 1. [FlashTool][New] Adapt new BROM_DLL v2.4.1002 for many features and bug fix. * 2. [FlashTool][Enhance] Display external SRAM size of target NOR flash MCP. * * How to verify this SCR? * 1. use FlashTool to verify. * Resolution for 84: [FlashTool v2.6.1002][New] Adapt with BROM_DLL v2.4.1002 and many enhancement. * * Rev 1.23 Jul 19 2004 11:13:26 mtk00539 * add baudrate full sync count option * Resolution for 82: [FlashTool v2.6.1001][New] Adapt with BROM_DLL v2.4.1001 and many enhancement. * * Rev 1.22 Jul 19 2004 02:10:56 mtk00539 * 1. [FlashTool][New] Adapt new BROM_DLL v2.4.1001 for many features and bug fix. * 2. [FlashTool][Enhance] Export COM port read/write timeout setting. * 3. [FlashTool][Enhance] Change EMI setting to 32 bits. * Resolution for 82: [FlashTool v2.6.1001][New] Adapt with BROM_DLL v2.4.1001 and many enhancement. * * Rev 1.21 Jun 16 2004 16:38:12 mtk00539 * 1. [FlashTool][Enhance] Re-org format option panel to prevent users confused. * 2. [FlashTool][Enhance] Do not close OK window when operation is done. * Resolution for 78: [FlashTool v2.5.1013][Enhance] Re-org format option panel to prevent users confused. * * Rev 1.20 May 26 2004 21:54:58 mtk00539 * [FlashTool][New] Using BROM_DLL_v2.3.1005 new feature to add BootROM stage callback function to disable vibrator to avoid MT6218B series board layout issue. * Resolution for 74: [FlashTool v2.5.1011][New] Add new flag to pull down GPIO17. * * Rev 1.19 May 21 2004 15:54:54 mtk00539 * 1. [FlashTool][BUF FIX] fix incorrect error message of resource detection. * Resolution for 71: [FlashTool v2.5.1010][BUF FIX] fix incorrect error message of resource detection. * * Rev 1.18 May 17 2004 12:58:14 mtk00539 * [New] keep old interfaces of Boot_META, Boot_FlashTool & Brom_Verify * Resolution for 69: [BootRom v2.3.1002][BUG FIX] fix RB_HANDLE deadlock. * * Rev 1.17 May 14 2004 17:04:22 mtk00539 * 1. [FlashTool][New] add CTRL+ALT+O hot-key to toggle Advanced Option Mode. * 2. [FlashTool][New] add FAT auto format mechanism. * 3. [FlashTool][New] add DA auto selection mechanism. * 4. [FlashTool][New] add STOP button. * 5. [FlashTool][Enhance] start timer when BootROM start cmd pass. * 6. [FlashTool][New] display flash info in status bar hint. * 7. [FlashTool][New] display format range info in format progress bar hint. * 8. [FlashTool][New] record the DA, Scatter and DL path separately. * Resolution for 68: [FlashTool v2.5.1009][New] add FAT auto format, DA auto selection mechanism and lots of enhancements. * * Rev 1.16 Mar 29 2004 14:20:16 mtk00539 * [New] add baseband chip ECO revision checking flag for FlashDownload. * Resolution for 65: [FlashTool v2.5.1008][New] add baseband chip ECO revision checking flag for FlashDownload. * * Rev 1.15 Mar 12 2004 19:07:48 mtk00539 * change log format * * Rev 1.14 Mar 09 2004 21:06:56 mtk00539 * [Enhance] adapt new Boot_FlashTool interface. * * Rev 1.13 Mar 02 2004 00:28:20 mtk00539 * 1. [FlashTool][Enhance] automatically select bbchip according to rom bbchip id.. * 2. [FlashTool][Enhance] automatically load all the resource files. * 3. [FlashTool][Enhance] display resource and jump table information. * 4. [FlashTool][New] add MT6219 support. * Resolution for 54: [FlashTool v2.5.1006][Enhance] bbchip id detection and resource autoload. * * Rev 1.12 Feb 05 2004 13:40:36 mtk00539 * adapt to BROM DLL v2.2.1001 * Resolution for 47: [FlashTool v2.5.1001][New] support multiple concatanated bin files download. * * Rev 1.11 Nov 14 2003 15:48:48 mtk00539 * add SOC feature. * Resolution for 35: [BootRom v2.1.1005][New] Add SOC feature. * * Rev 1.10 Oct 18 2003 14:06:20 mtk00539 * 1. modify for MT6218B boot rom verification. * 2. change version info. * Resolution for 31: [BootRom v2.1.1002][BUG FIX] Fix DA checksum error on Windows ME and 2000. * * Rev 1.9 Sep 26 2003 11:37:16 mtk00539 * check new return code * Resolution for 28: [BootRom v2.1.1001][New] See the reasons below. * Resolution for 29: [FlashTool v2.4.1001][New] See the reasons below. * * Rev 1.8 Sep 25 2003 14:03:28 mtk00539 * adapt brom.dll v2.1.1001, please see SCR(29) for more details. * Resolution for 29: [FlashTool v2.4.1001][New] See the reasons below. * * Rev 1.7 Jul 09 2003 13:36:06 mtk00539 * 1. reduce default timeout period and read/write incomplete retry times. * 2. increase version to 2.3.1002 * Resolution for 14: [BootRom v2.0.1004] fine tune for high speed download card behavior. * * Rev 1.6 Jun 30 2003 19:19:36 mtk00539 * 1. [FlashTool][Add Features] Split flashtool function into brom.dll * 2. [FlashTool][Add Features] Format function: users can format any range you want without downloading procedure. * 3. [FlashTool][Add Features] Report format percentage. * 4. [FlashTool][Add Features] Check format range. * 5. [FlashTool][Add Features] Merge FlashTool for Pluto version. * 6. [FlashTool][Add Features] Runtime debug log: you can press (CTRL+ALT+T) to enable/disable debug log whenever you want. * 7. [FlashTool][Add Features] Forcedly Stop hot-key: you can forcedly stop FlashTool by pressing CTRL+Z. * 8. [FlashTool][BUG FIXED] Fix FlashTool MEM_CMD end_addr bug, FlashTool should use (begin_addr+length-1) as end_addr. * Resolution for 11: [FlashTool v2.3.1001][New Version] Split flashtool function into brom.dll * * Rev 1.5 Jun 03 2003 22:24:56 mtk00539 * 1. extend timeout to 10 sec for large image download in boot_2.cpp * 2. disable unnecesssary debug hot-key. * 3. add shift+ctrl+A for Jensen's DA debug tool kit. * 4. enable build number, and start from 1003. * 5. save baseband chip type, mcu frequency and auto-memory wait state setup flag to ini file. * 6. add DA_SET_REG_CMD command and remove FINISH_CMD, so that release power key could be issued from FlashTool, not hardcoded in DA. * 7. add DA_MCU_FREQ_CMD command, so that we don't have to select different DA while switching frequency. * 8. add new flash MB84VD23280FA-70 for Chicago project. * 9. remove DEVICE_CMD, DA will check flash automatically and report the flash type to PC. * 10. add DA_FORMAT_CMD command to support range format. * 11. display flash type on FlashTool. * 12. merge the DOWNLOAD.H header file, both FlashTool and DA will use the same header file. * 13. modify SPEED_CMD handshake by adding a sync mechanism to detect whether if the speed change is done by both sides. * Resolution for 7: [FlashTool v2.2.1003][AddFeature] Enhanced for KLM and Chicago project. * * Rev 1.4 May 22 2003 19:23:58 mtk00539 * support brom.lib v1.0.1010 * Resolution for 6: [FlashTool v2.2][AddFeature] Support 6205/6205B at 13MHz, 26MHz and 52MHz. * * Rev 1.3 May 20 2003 16:22:30 mtk00539 * Support 6205/6205B at 13MHz, 26MHz and 52MHz * Resolution for 6: [FlashTool v2.2][AddFeature] Support 6205/6205B at 13MHz, 26MHz and 52MHz. * * Rev 1.2 Nov 20 2002 19:52:58 mtk00303 * update for reference phone * * Rev 1.1 Jul 26 2002 11:52:20 admin * ver 0726 * * Rev 1.0 Jul 20 2002 19:26:16 admin * Initial revision. * *------------------------------------------------------------------------------ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! *============================================================================== *******************************************************************************/ //--------------------------------------------------------------------------- #include#pragma hdrstop #include "tboot_1.h" #include "main.h" #include "ok_wnd.h" #include "com_util.h" #include "flashtool.h" #include "DA_Option.h" #include "meta.h" #pragma package(smart_init) //#define SKIP 1 //--------------------------------------------------------------------------- // Important: Methods and properties of objects in VCL can only be // used in a method called using Synchronize, for example: // // Synchronize(UpdateCaption); // // where UpdateCaption could look like: // // void __fastcall Unit4::UpdateCaption() // { // Form1->Caption = "Updated in a thread"; // } //--------------------------------------------------------------------------- __fastcall tboot_1::tboot_1(bool CreateSuspended ) : TThread(CreateSuspended) { } //--------------------------------------------------------------------------- void _fastcall tboot_1::ShowMsg() { ShowMessage( asMsg ); } void _fastcall tboot_1::InitProgress() { MainForm->CGauge1->Hint = progress_hint; MainForm->CGauge1->ForeColor = progress_forecolor; MainForm->CGauge1->Progress = progress_percentage; if(bUpdateFinishBytes) { g_ProgressTimeSec = 0; MainForm->sb_Main->Panels->Items[0]->Text = IntToStr(progress_finished_bytes) + " Bytes / 0 Bps"; } } void _fastcall tboot_1::SyncInitProgress() { Synchronize(InitProgress); } void _fastcall tboot_1::UpdateProgress() { unsigned int Bps; float KBps; AnsiString rate; MainForm->CGauge1->Progress = progress_percentage; if(bUpdateFinishBytes) { g_DisplayFinishedBytes = progress_finished_bytes; if( 0 >= g_ProgressTimeSec ) { rate = "0 Bps"; } else if( 1024 < (Bps=progress_finished_bytes/g_ProgressTimeSec) ) { KBps = Bps; rate = FloatToStrF( KBps/1024, ffFixed, 7, 2) + " KBps"; } else { rate = IntToStr(Bps) + " Bps"; } MainForm->sb_Main->Panels->Items[0]->Text = IntToStr(progress_finished_bytes) + " Bytes / " + rate; } } void _fastcall tboot_1::SyncUpdateProgress() { Synchronize(UpdateProgress); } void _fastcall tboot_1::DisplayFlashType() { ConvertDAReportToString(&da_report, m_strStorageHint, sizeof(m_strStorageHint), m_strHWDetectionReport, sizeof(m_strHWDetectionReport)); MainForm->HWStatusBarUpdate(&da_report, m_strStorageHint, m_strHWDetectionReport); } void _fastcall tboot_1::SyncDisplayFlashType() { Synchronize(DisplayFlashType); } void _fastcall tboot_1::SyncShowMsg() { Synchronize(ShowMsg); } void _fastcall tboot_1::ShowOK_Form() { Form_OK->Visible = true; StopTimer(); } void _fastcall tboot_1::StopTimer() { MainForm->Timer_Download->Enabled = false; } void _fastcall tboot_1::UpdateDebugDAWindow() { SCROLLINFO si; AnsiString s; //s = MainForm->DebugDAWindow->Text + IntToHex(m_RecvChar, 2) + " "; //s.printf("%s%c", MainForm->DebugDAWindow->Text.c_str(), m_RecvChar); MainForm->DebugDAWindow->Text = m_RecvString; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; if(::GetScrollInfo(MainForm->DebugDAWindow->Handle, SB_VERT, &si) == TRUE){ si.nTrackPos = si.nMax - si.nPage; ::SetScrollInfo(MainForm->DebugDAWindow->Handle, SB_VERT, &si, TRUE); } } static int __stdcall cb_download_da_init(void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; MainForm->Timer_Download->Enabled = true; t->progress_hint = "Download DA now..."; t->progress_forecolor = clRed; t->progress_percentage = 0; t->progress_finished_bytes = 0; t->bUpdateFinishBytes = true; t->SyncInitProgress(); return 0; } static int __stdcall cb_download_da(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_percentage = percent; t->progress_finished_bytes = sent_bytes; t->progress_total_bytes = total_bytes; t->bUpdateFinishBytes = true; t->SyncUpdateProgress(); return 0; } static int __stdcall cb_download_flash_init(void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_hint = "Download to flash now..."; t->progress_forecolor = clBlue; t->progress_percentage = 0; t->progress_finished_bytes = 0; t->bUpdateFinishBytes = true; t->SyncInitProgress(); return 0; } static int __stdcall cb_download_flash(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_percentage = percent; t->progress_finished_bytes = sent_bytes; t->progress_total_bytes = total_bytes; t->bUpdateFinishBytes = true; t->SyncUpdateProgress(); return 0; } static int __stdcall cb_download_bloader_init(void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_hint = "Download BootLoader now..."; t->progress_forecolor = 0x00A00070; t->progress_percentage = 0; t->progress_finished_bytes = 0; t->bUpdateFinishBytes = true; t->SyncInitProgress(); return 0; } static int __stdcall cb_download_bloader(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_percentage = percent; t->progress_finished_bytes = sent_bytes; t->progress_total_bytes = total_bytes; t->bUpdateFinishBytes = true; t->SyncUpdateProgress(); return 0; } static int __stdcall cb_format_report_init(void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; if( FLASHTOOL_DOWNLOAD == g_flashtool_function ) { if( FORMAT_FAT_AUTO == t->dl_arg.fmt_fat.option ) { if( 0 < t->da_report.m_fat_length ) { t->progress_hint.printf("AUTO FORMAT FAT: begin_addr(0x%08X), length(0x%08X). ", t->da_report.m_fat_begin_addr, t->da_report.m_fat_length); } else { // skip auto format } } else { t->progress_hint.printf("MANUAL FORMAT FAT: begin_addr(0x%08X), length(0x%08X). ", t->dl_arg.fmt_fat.fat_begin_addr, t->dl_arg.fmt_fat.fat_length); } } else if( FLASHTOOL_FORMAT == g_flashtool_function ) { t->progress_hint.printf("MANUAL FORMAT FLASH: begin_addr(0x%08X), length(0x%08X). ", t->fmt_arg.format_addr, t->fmt_arg.format_length); } else { t->progress_hint.printf("???"); } t->progress_forecolor = clGreen; t->progress_percentage = 0; t->bUpdateFinishBytes = false; t->SyncInitProgress(); return 0; } static int __stdcall cb_format_report(unsigned char percent, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_percentage = percent; t->bUpdateFinishBytes = false; t->SyncUpdateProgress(); return 0; } static int __stdcall cb_readback_flash_init(const char *rb_filepath, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; AnsiString s; s.printf("Readback \"%s\" now...", rb_filepath); t->progress_hint = s; t->progress_forecolor = clBlue; t->progress_percentage = 0; t->progress_finished_bytes = 0; t->bUpdateFinishBytes = true; t->SyncInitProgress(); return 0; } static int __stdcall cb_readback_flash(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->progress_percentage = percent; t->progress_finished_bytes = sent_bytes; t->progress_total_bytes = total_bytes; t->bUpdateFinishBytes = true; t->SyncUpdateProgress(); return 0; } static int __stdcall cb_before_process(const DA_REPORT_T *p_da_report, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; t->SyncDisplayFlashType(); return 0; } static int __stdcall cb_in_brom_stage(unsigned int brom_handle, HANDLE hCOM, void *usr_arg) { int ret; unsigned short value16; BBCHIP_TYPE *p_bbchip=(BBCHIP_TYPE *)usr_arg; if( g_bPullDownGPIO17 && NULL!=p_bbchip && MT6218B==*p_bbchip ) { // configure GPIO17 mode to GPIO value16 = 0x000C; ret = Brom_Write16Cmd(brom_handle, hCOM, (0x80120000+0x0120+0x08)/*GPIO_MODE3_CLR*/, &value16, 1); // configure GPIO17 direction as output value16 = 0x0002; ret = Brom_Write16Cmd(brom_handle, hCOM, (0x80120000+0x0010+0x04)/*GPIO_DIR2_SET*/, &value16, 1); // pull down GPIO17 to disable vibrator value16 = 0x0002; ret = Brom_Write16Cmd(brom_handle, hCOM, (0x80120000+0x00a0+0x08)/*GPIO_DOUT2_CLR*/, &value16, 1); } return 0; } static int __stdcall cb_format_statistics(const FormatStatisticsReport_S *p_report, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; float bad_block_ratio; float float_size; unsigned int size_of_bits; AnsiString str_format_size; size_of_bits = (p_report->m_fmt_length<<3); float_size = size_of_bits; if( 0x40000000 <= size_of_bits ) { if( 0 == (size_of_bits%0x40000000) ) { str_format_size.printf("%dGb", size_of_bits>>30); } else { str_format_size.printf("%.2fGb", float_size/0x40000000); } } else if( 0x100000 <= size_of_bits ) { if( 0 == (size_of_bits%0x100000) ) { str_format_size.printf("%dMb", size_of_bits>>20); } else { str_format_size.printf("%.2fMb", float_size/0x100000); } } else if( 0x400 <= size_of_bits ) { if( 0 == (size_of_bits%0x400) ) { str_format_size.printf("%dKb", size_of_bits>>10); } else { str_format_size.printf("%.2fKb", float_size/0x400); } } else { str_format_size.printf("%db", size_of_bits); } bad_block_ratio = (p_report->m_bad_blocks+p_report->m_err_blocks); bad_block_ratio /= p_report->m_total_blocks; bad_block_ratio *= 100; t->asMsg.printf("Format Range: 0x%08X ~ 0x%08X\n" "Format Size: %s\n" "\n" "Bad Blocks: %lu\n" "Error Blocks: %lu\n" "Total Blocks: %lu\n" "\n" "Bad/Error Block Ratio: (%.3f%%)\n" ,p_report->m_fmt_begin_addr, p_report->m_fmt_begin_addr+p_report->m_fmt_length-1 ,str_format_size.c_str() ,p_report->m_bad_blocks ,p_report->m_err_blocks ,p_report->m_total_blocks ,bad_block_ratio); t->SyncShowMsg(); return 0; } void __fastcall tboot_1::Execute() { button_sentry s; MainForm->HWStatusBarClear(); progress_hint = ""; progress_forecolor = clBlue; progress_percentage = 0; progress_finished_bytes = 0; bUpdateFinishBytes = true; SyncInitProgress(); if(g_bDebugDA) { DebugDA(); } else { FlashTool(); } Terminate(); } class com_sentry { public: com_sentry(HANDLE &com, unsigned int com_port): m_hCOM(com) { open_com_port(m_hCOM, com_port, 115200); } ~com_sentry() { close_com_port(m_hCOM); } private: HANDLE &m_hCOM; }; void _fastcall tboot_1::ResetFakeProgress() { MainForm->CGauge1->Hint = progress_hint; MainForm->CGauge1->ForeColor = progress_forecolor; MainForm->CGauge1->Progress = 0; } void _fastcall tboot_1::StartFakeProgress() { MainForm->m_FakeProgressTimer->Enabled = true; } void _fastcall tboot_1::StopFakeProgress() { MainForm->m_FakeProgressTimer->Enabled = false; } void _fastcall tboot_1::FinishFakeProgress() { MainForm->CGauge1->Progress = 100; MainForm->m_FakeProgressTimer->Enabled = false; } void _fastcall tboot_1::SyncStartFakeProgress() { Synchronize(StartFakeProgress); } static int __stdcall cb_boot_meta_in_brom_stage(unsigned int brom_handle, HANDLE hCOM, void *usr_arg) { tboot_1 *t=(tboot_1 *)usr_arg; // start fake progress t->SyncStartFakeProgress(); return 0; } bool _fastcall tboot_1::EnterMETA(const BBCHIP_TYPE bbchip, const EXT_CLOCK ext_clock) { static META_COMM_BAUDRATE allow_baudrate[11]={ META_BAUD115200, META_BAUD230400, META_BAUD460800, META_BAUD921600, META_BAUD_END, META_BAUD_END, META_BAUD_END, META_BAUD_END, META_BAUD_END, META_BAUD_END, META_BAUD_END }; META_RESULT meta_ret; META_Connect_Req meta_req; META_Connect_Report meta_report; meta_req.com_port = COM_PORT; meta_req.bbchip = bbchip; meta_req.ext_clock = ext_clock; memcpy(meta_req.baudrate, allow_baudrate, sizeof(meta_req.baudrate)); meta_req.flowctrl = META_SW_FLOWCTRL; meta_req.ms_connect_timeout = 40000; meta_req.ms_boot_timeout = 5000; meta_req.boot_meta_arg.m_cb_in_brom_stage = cb_boot_meta_in_brom_stage; meta_req.boot_meta_arg.m_cb_in_brom_stage_arg = this; // reset fake progress progress_hint = "Reset NVRAM to factory default setting ..."; progress_forecolor = clGreen; Synchronize(ResetFakeProgress); if( META_SUCCESS != (meta_ret=META_ConnectWithTarget(&meta_req, &g_stopflag, &meta_report)) ) { // stop fake progress Synchronize(StopFakeProgress); asMsg = "META_ConnectWithTarget(): ERROR: " + AnsiString(META_GetErrorString(meta_ret)); Synchronize(ShowMsg); return false; } if( META_SUCCESS != (meta_ret=META_NVRAM_ResetToFactoryDefault(40000)) ) { META_DisconnectWithTarget(); // stop fake progress Synchronize(StopFakeProgress); asMsg = "META_NVRAM_ResetToFactoryDefault(): ERROR: " + AnsiString(META_GetErrorString(meta_ret)); Synchronize(ShowMsg); return false; } META_DisconnectWithTarget(); // finish fake progress Synchronize(FinishFakeProgress); return true; } void __fastcall tboot_1::FlashTool() { AnsiString s1, s2; int ret; memset(&arg, 0, sizeof(arg)); memset(&dl_arg, 0, sizeof(dl_arg)); memset(&rb_arg, 0, sizeof(rb_arg)); memset(&fmt_arg, 0, sizeof(fmt_arg)); // fill COM_PORT_SETTING com.com.number = COM_PORT; com.baudrate = BAUD_RATE; com.ms_read_timeout = g_COM_Read_Timeout; com.ms_write_timeout = g_COM_Write_Timeout; // fill FLASHTOOL_ARG arg.bbchip = g_BBCHIP_TYPE; arg.ext_clock = g_EXT_CLOCK; arg.p_bank0_mem_cfg = g_EMI_Config[0].m_bAuto?NULL:&(g_EMI_Config[0].m_Config); arg.p_bank1_mem_cfg = g_EMI_Config[1].m_bAuto?NULL:&(g_EMI_Config[1].m_Config); if(g_bSkipBootRom) arg.da_handle = NULL; else arg.da_handle = g_DA_HANDLE; arg.cb_download_da_init = cb_download_da_init; arg.cb_download_da_init_arg = this; arg.cb_download_da = cb_download_da; arg.cb_download_da_arg = this; arg.cb_before_process = cb_before_process; arg.cb_before_process_arg = this; arg.cb_set_high_speed_baudrate = NULL; arg.cb_set_high_speed_baudrate_arg = NULL; arg.ms_boot_timeout = BOOT_INFINITE; arg.max_start_cmd_retry_count = g_MaxBromStartCmdRetryCount; arg.cb_in_brom_stage = cb_in_brom_stage; arg.cb_in_brom_stage_arg = &(arg.bbchip); arg.m_baudrate_full_sync_count = g_Baudrate_FullSync_Count; arg.m_speedup_brom_baudrate = g_SpeedUpBootROMBaudrate?_TRUE:_FALSE; if( NOR_OPERATION == g_OperationMethod ) { arg.m_storage_type = HW_STORAGE_NOR; arg.m_storage_chip_select[0] = CS0; arg.m_storage_chip_select[1] = CS_WITH_DECODER; } else if( NFB_OPERATION==g_OperationMethod && FLASHTOOL_DOWNLOAD==g_flashtool_function ) { // NFB_OPERATION arg.m_storage_type = HW_STORAGE_NAND; // NFB download, force to CS0, because NFB BootROM only check CS0 arg.m_storage_chip_select[0] = CS0; arg.m_storage_chip_select[1] = CS_WITH_DECODER; } else { arg.m_storage_type = HW_STORAGE_NAND; arg.m_storage_chip_select[0] = g_bNFI_SelectCS1?CS1:CS0; arg.m_storage_chip_select[1] = CS_WITH_DECODER; } // NFI setting arg.m_nand_acccon = g_EMI_NFI_Setting.m_nand_acccon; arg.m_enable_dram_setting = _FALSE; // check BootLoader's DRAM setting if( NFB_OPERATION == g_OperationMethod ) { BL_INFO bl_info; if( !g_EMI_NFI_Setting.m_enable_dram_setting && (FTHND_OK == DL_BL_GetInfo(g_DL_HANDLE, &bl_info)) && (_TRUE == bl_info.m_dram_cfg.m_valid) ) { // apply DRAM Setting from BootLoader arg.m_emi_gen_a = bl_info.m_dram_cfg.m_emi_gen_a; arg.m_emi_gen_b = bl_info.m_dram_cfg.m_emi_gen_b; arg.m_emi_gen_c = bl_info.m_dram_cfg.m_emi_gen_c; arg.m_emi_dram_con_i_mode = bl_info.m_dram_cfg.m_emi_dram_con_i_mode; arg.m_emi_dram_con_i_ext_mode = bl_info.m_dram_cfg.m_emi_dram_con_i_ext_mode; arg.m_emi_dram_con_k = bl_info.m_dram_cfg.m_emi_dram_con_k; arg.m_emi_dram_con_l = bl_info.m_dram_cfg.m_emi_dram_con_l; } else { // user select argument arg.m_emi_gen_a = g_EMI_NFI_Setting.m_emi_gen_a; arg.m_emi_gen_b = g_EMI_NFI_Setting.m_emi_gen_b; arg.m_emi_gen_c = g_EMI_NFI_Setting.m_emi_gen_c; arg.m_emi_dram_con_i_mode = g_EMI_NFI_Setting.m_emi_dram_con_i_mode; arg.m_emi_dram_con_i_ext_mode = g_EMI_NFI_Setting.m_emi_dram_con_i_ext_mode; arg.m_emi_dram_con_k = g_EMI_NFI_Setting.m_emi_dram_con_k; arg.m_emi_dram_con_l = g_EMI_NFI_Setting.m_emi_dram_con_l; } } if( FLASHTOOL_DOWNLOAD == g_flashtool_function ) { // fill FLASHTOOL_DOWNLOAD_ARG if( MainForm->mi_MultiLoad->Checked){ //ray 2006.05.18 : Multi-Load dl_arg.dl_handle_list = g_DL_HANDLE_LIST; dl_arg.dl_handle = NULL; } else{ dl_arg.dl_handle = g_DL_HANDLE; dl_arg.dl_handle_list = NULL; } dl_arg.download_accuracy = ACCURACY_AUTO; dl_arg.cb_download_flash_init = cb_download_flash_init; dl_arg.cb_download_flash_init_arg = this; dl_arg.cb_download_flash = cb_download_flash; dl_arg.cb_download_flash_arg = this; if( NOR_OPERATION == g_OperationMethod ) { dl_arg.fmt_fat.fat_begin_addr = g_ulFormatStartAddr; dl_arg.fmt_fat.fat_length = g_ulFormatLength; } else { dl_arg.fmt_fat.fat_begin_addr = g_ulNandFormatStartAddr; dl_arg.fmt_fat.fat_length = g_ulNandFormatLength; } dl_arg.fmt_fat.m_validation = g_FormatValidation?_TRUE:_FALSE; switch(g_FormatAfterDownloadOption) { case RESET_TO_FACTORY: // disable format dl_arg.enable_fat_format = _FALSE; dl_arg.fmt_fat.option = FORMAT_FAT_AUTO; // enable watchdog dl_arg.enable_wdt_timeout = _TRUE; dl_arg.ms_wdt_timeout_interval = 1500; break; case AUTO_FORMAT: // enable auto format dl_arg.enable_fat_format = _TRUE; dl_arg.fmt_fat.option = FORMAT_FAT_AUTO; // disable watchdog dl_arg.enable_wdt_timeout = _FALSE; dl_arg.ms_wdt_timeout_interval = 0; break; case MANUAL_FORMAT: // enable manual format dl_arg.enable_fat_format = _TRUE; dl_arg.fmt_fat.option = FORMAT_FAT_MANUAL; // disable watchdog dl_arg.enable_wdt_timeout = _FALSE; dl_arg.ms_wdt_timeout_interval = 0; break; case DISABLE_FORMAT: default: // disable format dl_arg.enable_fat_format = _FALSE; dl_arg.fmt_fat.option = FORMAT_FAT_AUTO; // disable watchdog dl_arg.enable_wdt_timeout = _FALSE; dl_arg.ms_wdt_timeout_interval = 0; break; } dl_arg.cb_format_report_init = cb_format_report_init; dl_arg.cb_format_report_init_arg = this; dl_arg.cb_format_report = cb_format_report; dl_arg.cb_format_report_arg = this; dl_arg.enable_tgt_res_layout_check = g_bCheckTgtResourceLayout?_TRUE:_FALSE; dl_arg.enable_bbchip_eco_check = g_bCheckECOVer?_TRUE:_FALSE; dl_arg.m_cb_format_statistics = cb_format_statistics; dl_arg.m_cb_format_statistics_arg = this; if( NFB_OPERATION == g_OperationMethod ) { // for NFB bloader dl_arg.m_nfb_enable = _TRUE; dl_arg.m_cb_download_bloader_init = cb_download_bloader_init; dl_arg.m_cb_download_bloader_init_arg = this; dl_arg.m_cb_download_bloader = cb_download_bloader; dl_arg.m_cb_download_bloader_arg = this; } else { dl_arg.m_nfb_enable = _FALSE; dl_arg.m_cb_download_bloader_init = NULL; dl_arg.m_cb_download_bloader_init_arg = NULL; dl_arg.m_cb_download_bloader = NULL; dl_arg.m_cb_download_bloader_arg = NULL; } if(g_AutoDetectBBCHIP) { ret = AutoBoot_FlashDownload(&com, &arg, &dl_arg, &g_stopflag, &da_report); } else { ret = FlashDownload(&com, &arg, &dl_arg, &g_stopflag, &da_report); } if( FT_OK != ret ) { // stop timer Synchronize(StopTimer); } } else if( FLASHTOOL_READBACK == g_flashtool_function ) { // fill FLASHTOOL_READBACK_ARG rb_arg.rb_handle = g_RB_HANDLE; rb_arg.readback_accuracy = ACCURACY_AUTO; rb_arg.readback_accuracy = ACCURACY_AUTO; rb_arg.cb_readback_flash_init = cb_readback_flash_init; rb_arg.cb_readback_flash_init_arg = this; rb_arg.cb_readback_flash = cb_readback_flash; rb_arg.cb_readback_flash_arg = this; if(g_AutoDetectBBCHIP) { ret = AutoBoot_FlashReadback(&com, &arg, &rb_arg, &g_stopflag, &da_report); } else { ret = FlashReadback(&com, &arg, &rb_arg, &g_stopflag, &da_report); } if( FT_OK != ret ) { // stop timer Synchronize(StopTimer); } } else if( FLASHTOOL_FORMAT == g_flashtool_function ) { if( RESET_TO_FACTORY == g_FormatOption ) { // reset stop flag g_stopflag = 0; // go to META mode reset ret = FT_OK; } else { // fill FLASHTOOL_FORMAT_ARG if( NOR_OPERATION == g_OperationMethod ) { fmt_arg.format_addr = g_ulFormatStartAddr; fmt_arg.format_length = g_ulFormatLength; } else { fmt_arg.format_addr = g_ulNandFormatStartAddr; fmt_arg.format_length = g_ulNandFormatLength; } fmt_arg.cb_format_report_init = cb_format_report_init; fmt_arg.cb_format_report_init_arg = this; fmt_arg.cb_format_report = cb_format_report; fmt_arg.cb_format_report_arg = this; fmt_arg.m_cb_format_statistics = cb_format_statistics; fmt_arg.m_cb_format_statistics_arg = this; fmt_arg.m_erase_flag = g_EraseFlag; fmt_arg.m_validation = g_FormatValidation?_TRUE:_FALSE; if(g_AutoDetectBBCHIP) { ret = AutoBoot_FlashFormat(&com, &arg, &fmt_arg, &g_stopflag, &da_report); } else { ret = FlashFormat(&com, &arg, &fmt_arg, &g_stopflag, &da_report); } } if( FT_OK != ret ) { // stop timer Synchronize(StopTimer); } } if( BOOT_STOP == g_stopflag ) { return; } switch(FT_RET(ret)) { case FT_SKIP_AUTO_FORMAT_FAT: ROM_INFO rom_info; DL_Rom_GetInfo(g_DL_HANDLE, 0, &rom_info); asMsg.printf("[Warning] Skip FAT auto format because of one of the following reasons.\n\n" " 1. \"%s\" might not contain FAT range information! \n" " 2. Target's flash id doesn't correspond to \"%s\" 's flash id!", rom_info.name, rom_info.name); Synchronize(ShowMsg); case FT_OK: if( (FLASHTOOL_DOWNLOAD==g_flashtool_function && RESET_TO_FACTORY==g_FormatAfterDownloadOption) ) { if(!EnterMETA(arg.bbchip, arg.ext_clock)) { // stop timer Synchronize(StopTimer); return; } } else if( (FLASHTOOL_FORMAT==g_flashtool_function && RESET_TO_FACTORY==g_FormatOption) ) { if(!EnterMETA(g_AutoDetectBBCHIP?UNKNOWN_BBCHIP_TYPE:g_BBCHIP_TYPE, g_EXT_CLOCK)) { // stop timer Synchronize(StopTimer); return; } } // show ok form and stop timer Synchronize(ShowOK_Form); break; case FT_COM_PORT_OPEN_ERR: asMsg.printf("[COM] Open COM%d error!", COM_PORT); Synchronize(ShowMsg); break; case FT_COM_PORT_SET_TIMEOUT_ERR: asMsg.printf("[COM] Fail to set COM%d timeout!", COM_PORT); Synchronize(ShowMsg); break; case FT_DA_HANDLE_ERROR: switch(FTHND_RET(ret)) { case FTHND_FILE_IS_NOT_LOADED: s1 = arg.da_info.filepath; asMsg = "[DA_HANDLE] DA(\"" + s1 + "\") is not loaded yet!\n\nPlease load it before download."; Synchronize(ShowMsg); break; default: asMsg = "[DA_HANDLE] Error: ret=0x" + IntToHex(ret, 6); Synchronize(ShowMsg); break; } break; case FT_DL_HANDLE_ERROR: switch(FTHND_RET(ret)) { case FTHND_LIST_IS_EMPTY: asMsg = "[DL_HANDLE] Download list is empty or all disabled!\n\nPlease select at least one entry."; Synchronize(ShowMsg); break; case FTHND_FILE_IS_NOT_LOADED: s1 = dl_arg.rom_info.name; asMsg = "[DL_HANDLE] " + s1 + " is not loaded yet!\n\nPlease load it before download."; Synchronize(ShowMsg); break; case FTHND_RES_NO_MATCH_IN_JUMPTABLE: { char *p_filename=NULL; char path[512]; AnsiString filename; GetFullPathName(dl_arg.rom_info.filepath, sizeof(path), path, &p_filename); if( NULL!=p_filename && (strlen(dl_arg.rom_info.filepath)>(strlen(p_filename)+12)) ) { filename.printf("%.12s...\\%s", path, p_filename); } else { filename = dl_arg.rom_info.filepath; } asMsg.printf("[DL_HANDLE] %s (\"%s\") doesn't match any entry in jump table!", dl_arg.rom_info.name, filename.c_str()); Synchronize(ShowMsg); } break; case FTHND_RES_BASE_ADDR_NOT_MATCH: { char *p_filename=NULL; char path[512]; AnsiString filename; MTK_Resource res_info; GetFullPathName(dl_arg.rom_info.filepath, sizeof(path), path, &p_filename); if( NULL!=p_filename && (strlen(dl_arg.rom_info.filepath)>(strlen(p_filename)+12)) ) { filename.printf("%.12s...\\%s", path, p_filename); } else { filename = dl_arg.rom_info.filepath; } DL_Rom_GetResInfo(g_DL_HANDLE, dl_arg.rom_info.index, &res_info); asMsg.printf("[DL_HANDLE] %s (\"%s\"): The begin_addr(0x%08X) doesn't match resource base_addr(0x%08X)!", dl_arg.rom_info.name, filename.c_str(), dl_arg.rom_info.begin_addr, res_info.m_base_addr); Synchronize(ShowMsg); } break; case FTHND_SCAT_REGION_IS_OVERLAP: { ROM_INFO rom_info; DL_Rom_GetInfo(g_DL_HANDLE, dl_arg.rom_info.index+1, &rom_info); asMsg.printf("[DL_HANDLE] %s file overlap the next file %s !", dl_arg.rom_info.name, rom_info.name); Synchronize(ShowMsg); } break; case FTHND_RES_IS_NOT_DOWNLOAD_WITH_JUMPTABLE: asMsg = "[DL_HANDLE] Resources and jump table are not selected to download together!"; Synchronize(ShowMsg); break; case FTHND_RES_DOWNLOAD_SELECT_INCOMPLETE: // enable unselect files for(int i=0; i SyncRedrawDownloadList); asMsg = "[DL_HANDLE] The resources you selected to download are incomplete, please download again!"; Synchronize(ShowMsg); break; case FTHND_JUMPTABLE_INCONSISTENT_WITH_SCAT: asMsg = "[DL_HANDLE] jump table is different from scatter!"; Synchronize(ShowMsg); break; case FTHND_JUMPTABLE_INCORRECT_FORMAT: asMsg = "[DL_HANDLE] jump table is not loaded yet! \nBecause its content is not a correct jump table format."; Synchronize(ShowMsg); break; default: asMsg = "[DL_HANDLE] Error: ret=0x" + IntToHex(ret, 6); Synchronize(ShowMsg); break; } break; case FT_RB_HANDLE_ERROR: switch(FTHND_RET(ret)) { case FTHND_LIST_IS_EMPTY: asMsg = "[RB_HANDLE] Readback list is empty!\n\nPlease add at least one readback entry."; Synchronize(ShowMsg); break; default: asMsg = "[RB_HANDLE] Error: ret=0x" + IntToHex(ret, 6); Synchronize(ShowMsg); break; } break; case FT_BROM_ERROR: switch(BROM_RET(ret)) { case BROM_CMD_START_FAIL: asMsg = "[BROM] Can not pass bootrom start command! Possibly target power up too early."; Synchronize(ShowMsg); break; case BROM_DOWNLOAD_DA_FAIL: asMsg = "[BROM] Fail to download DA to baseband chip's internal SRAM!\n\nPossible reasons:\n1. There's an UART communication problem between FlashTool and BootROM.\n2. Target might be shutdown unexpectedly.\n\n[ACTION]\n1. Try again.\n2. Proceed H/W checking in download cable and target side UART path.\n3. Monitor if power-drop occured in target side."; Synchronize(ShowMsg); break; case BROM_BBCHIP_HW_VER_INCORRECT: asMsg.printf("[BROM] Target baseband chip is inconsistent with %s!\n\n[ACTION]\nPlease select the suitable bin files for the target's baseband chip.", arg.p_bbchip_name); Synchronize(ShowMsg); break; case BROM_BBCHIP_DSP_VER_INCORRECT: asMsg.printf("[BROM] Target baseband chip DSP version is inconsistent with %s !!!", arg.p_bbchip_name); Synchronize(ShowMsg); break; case BROM_FAIL_TO_GET_BBCHIP_HW_VER: asMsg = "[BROM] Fail to get target baseband chip H/W version!\n\nPossible reasons:\n1. There's an UART communication problem between FlashTool and BootROM.\n2. Target might be shutdown unexpectedly.\n\n[ACTION]\n1. Try again.\n2. Proceed H/W checking in download cable and target side UART path.\n3. Monitor if power-drop occured in target side."; Synchronize(ShowMsg); break; case BROM_UNKNOWN_TGT_BBCHIP: asMsg = "[BROM] Unsupported target baseband chip type!\n\n[ACTION]\nPlease upgrade to the latest FlashTool then try again."; Synchronize(ShowMsg); break; case BROM_UNKNOWN_BBCHIP: { char *p_filename=NULL; char path[512]; AnsiString filename; MTK_Resource res_info; ROM_INFO rom_info; DL_Rom_GetInfo(g_DL_HANDLE, 0, &rom_info); GetFullPathName(rom_info.filepath, sizeof(path), path, &p_filename); if( NULL!=p_filename && (strlen(rom_info.filepath)>(strlen(p_filename)+12)) ) { filename.printf("%.12s...\\%s", path, p_filename); } else { filename = rom_info.filepath; } asMsg.printf("[BROM] Unknown baseband chip type in file %s(\"%s\")!", rom_info.name, filename.c_str()); Synchronize(ShowMsg); } break; case BROM_CHKSUM16_MEM_RESULT_DIFF: asMsg = "[BROM] Fail to download DA to baseband chip's internal SRAM!\n\nThe internal SRAM has the problem that leads to 16 bits checksum error!"; Synchronize(ShowMsg); break; case BROM_MULTIPLE_BAUDRATE_FAIL: asMsg = "[BROM] BootROM start command passed but fail to multiple BootROM baudrate!\n\nPossible reasons:\n1. There's an UART communication problem between FlashTool and BootROM.\n2. Target might be shutdown unexpectedly.\n\n[ACTION]\n1. Try again.\n2. If the problem still exists. Disable \"Options\"->\"Transmission option\"->\"Speed-Up BootROM baudrate\"\n in advance mode (CTRL+ALT+V) then try again.\n3. Proceed H/W checking in download cable and target side UART path.\n4. Monitor if power-drop occured in target side."; Synchronize(ShowMsg); break; case BROM_CMD_START_TIMEOUT: asMsg = "[BROM] BootROM start command timeout!"; Synchronize(ShowMsg); break; default: asMsg = "[BROM] Error: ret=0x" + IntToHex(ret, 6); Synchronize(ShowMsg); break; } break; case FT_DA_NO_RESPONSE: asMsg = "DA didn't send response data which FlashTool requested."; Synchronize(ShowMsg); break; case FT_DA_HW_ERROR: SyncDisplayFlashType(); asMsg.printf(" <<< H/W Detection Failure >>>\n\n%s", m_strHWDetectionReport); Synchronize(ShowMsg); break; case FT_DA_SYNC_INCORRECT: asMsg = "DA sync fail! Possibly download an illegal DA."; Synchronize(ShowMsg); break; case FT_DA_VERSION_INCORRECT: asMsg.printf("DA version is incorrect! DA_v%d.%d was expired, expected DA_v%d.%d.", da_report.m_da_major_ver, da_report.m_da_minor_ver, da_report.m_expected_da_major_ver, da_report.m_expected_da_minor_ver); Synchronize(ShowMsg); break; case FT_DA_UNKNOWN_FLASH_DEVICE: asMsg = "Unknown flash device!"; Synchronize(ShowMsg); break; case FT_DA_SET_EXT_CLOCK_FAIL: asMsg = "DA_EXT_CLOCK_CMD command fail!"; Synchronize(ShowMsg); break; case FT_DA_SET_BBCHIP_TYPE_FAIL: asMsg = "DA_BBCHIP_TYPE_CMD command fail!"; Synchronize(ShowMsg); break; case FT_DA_CHANGE_BAUDRATE_FAIL: { unsigned int baudrate_tbl[] = { 0, 921600, 460800, 230400, 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300, 110 }; asMsg = "Fail to change baudrate to " + IntToStr(baudrate_tbl[com.baudrate]) + "."; } Synchronize(ShowMsg); break; case FT_DA_SET_DOWNLOAD_BLOCK_FAIL: asMsg = "DA_MEM_CMD command fail! Possibly the following reason.\n\n 1. Download block exceeds target flash size.\n 2. Download block start address is not WORD alignment.\n 3. Download block length is not multiple of WORD."; Synchronize(ShowMsg); break; case FT_DA_DOWNLOAD_FAIL: asMsg = "Download to flash fail! Please press CTRL+ALT+T to turn on debug log then reproduce again!\n C:\\BROM_DLL.log would be created and record more detail information."; Synchronize(ShowMsg); break; case FT_DA_READBACK_FAIL: asMsg = "Readback from flash fail! Please press CTRL+ALT+T to turn on debug log then reproduce again!\n C:\\BROM_DLL.log would be created and record more detail information."; Synchronize(ShowMsg); break; case FT_DA_FORMAT_FAIL: asMsg = "Format flash error! Possibly given a wrong format range, please check your format setting."; Synchronize(ShowMsg); break; case FT_BLOCK_UNSTABLE: asMsg = "Format flash error! After erase operation, block data is not entire 0xFF."; Synchronize(ShowMsg); break; case FT_DA_FINISH_CMD_FAIL: asMsg = "DA_FINISH_CMD command fail!"; Synchronize(ShowMsg); break; case FT_DA_SOC_CHECK_FAIL: asMsg = "SOC verification fail!"; Synchronize(ShowMsg); break; case FT_DA_BBCHIP_DSP_VER_INCORRECT: asMsg.printf("Target baseband chip DSP version is inconsistent with %s !!!", arg.p_bbchip_name); Synchronize(ShowMsg); break; case FT_DA_NAND_DOWNLOAD_BLOADER_FAIL: asMsg.printf("Fail to download BootLoader to NAND flash!"); Synchronize(ShowMsg); break; case FT_DA_NAND_DOWNLOAD_IMAGE_FAIL: asMsg.printf("Fail to download Image(s) to NAND flash!"); Synchronize(ShowMsg); break; case FT_DA_NAND_BLOADER_NOT_EXIST: asMsg.printf("BootLoader doesn't exist on NAND flash, please download BootLoader first!"); Synchronize(ShowMsg); break; case FT_BL_HANDLE_ERROR: switch(FTHND_RET(ret)) { case FTHND_FILE_IS_NOT_LOADED: { BL_INFO bl_info; DL_BL_GetInfo(g_DL_HANDLE, &bl_info); s1 = bl_info.m_filepath; asMsg = "[BL_HANDLE] BootLoader(\"" + s1 + "\") is not loaded yet!\n\nPlease load it before download."; Synchronize(ShowMsg); } break; default: asMsg = "[BL_HANDLE] Error: ret=0x" + IntToHex(ret, 6); Synchronize(ShowMsg); break; } break; case FT_DA_INIT_SYNC_ERROR: asMsg.printf("Fail to send sync data to DA in initialization stage!"); Synchronize(ShowMsg); break; case FT_NFB_NOT_SUPPORT_MBA: asMsg.printf("Multiple-bin download is currently unsupported for NAND-Flash-Booting(NFB) operation!"); Synchronize(ShowMsg); break; case FT_NFB_ONLY_SUPPORT_FOR_NAND_FLASH: asMsg.printf("NAND-Flash-Booting(NFB) can only operate on NAND flash!"); Synchronize(ShowMsg); break; case FT_NAND_RAW_DATA_DOWNLOAD_NOT_SUPPORT: asMsg.printf("Currently FlashTool doesn't support raw-data download on NAND flash!\n\nPlease select \"Options\"->\"Operation method\" to NOR or NFB for download purpose."); Synchronize(ShowMsg); break; case FT_DA_MEMCMD_INVALID_RANGE: asMsg = "DA_MEM_CMD command fail!\n\n 1. One of the download blocks has invalid range.\n 2. Possibly invalid begin address or end address exceeds target flash size."; Synchronize(ShowMsg); break; case FT_DA_MEMCMD_PGM_AT_ODD_ADDR: asMsg = "DA_MEM_CMD command fail!\n\n 1. One of the download blocks has the ODD begin address!"; Synchronize(ShowMsg); break; case FT_DA_MEMCMD_PGM_WITH_ODD_LENGTH: asMsg = "DA_MEM_CMD command fail!\n\n 1. One of the download blocks has the EVEN end address! That is download block is in ODD length."; Synchronize(ShowMsg); break; case FT_DA_MEMCMD_SIBLEY_PGM_AT_THE_SAME_REGIONS: asMsg = "DA_MEM_CMD command fail!\n\n 1. Two of the download blocks locate in the same 1KB program region on INTEL sibley flash device.\n 2. Please ensure that your scatter file leaves at least 1 KB (0x400) between consecutive bin files."; Synchronize(ShowMsg); break; default: asMsg = "Error: ret=0x" + IntToHex(ret, 6); Synchronize(ShowMsg); break; } } void __fastcall tboot_1::DebugDA() { DWORD ret; HANDLE hCOM = INVALID_HANDLE_VALUE; com_sentry s(hCOM, COM_PORT); if( INVALID_HANDLE_VALUE == hCOM ) { // stop timer Synchronize(StopTimer); asMsg = "Open COM" + IntToStr(COM_PORT) + "failed!"; Synchronize(ShowMsg); return; } BBCHIP_TYPE bbchip = g_BBCHIP_TYPE; EXT_CLOCK ext_clock = g_EXT_CLOCK; DA_INFO da_info; BOOT_FLASHTOOL_ARG boot_ft; DA_GetInfo(g_DA_HANDLE, &da_info); boot_ft.m_p_bbchip_name = NULL; boot_ft.m_p_bank0_mem_cfg = g_EMI_Config[0].m_bAuto?NULL:&(g_EMI_Config[0].m_Config); boot_ft.m_p_bank1_mem_cfg = g_EMI_Config[1].m_bAuto?NULL:&(g_EMI_Config[1].m_Config); boot_ft.m_da_start_addr = da_info.start_addr; boot_ft.m_da_buf = da_info.buf; boot_ft.m_da_len = da_info.buf_len; boot_ft.m_da_main_prog_len = da_info.main_prog_size; boot_ft.m_cb_download_da_init = cb_download_da_init; boot_ft.m_cb_download_da_init_arg = this; boot_ft.m_cb_download_da = cb_download_da; boot_ft.m_cb_download_da_arg = this; boot_ft.m_cb_in_brom_stage = cb_in_brom_stage; boot_ft.m_cb_in_brom_stage_arg = &bbchip; boot_ft.m_speedup_brom_baudrate = g_SpeedUpBootROMBaudrate?_TRUE:_FALSE; if(g_AutoDetectBBCHIP) { ret = AutoBoot_FlashTool_Ex(hCOM, &bbchip, &ext_clock, &g_stopflag, BOOT_INFINITE, g_MaxBromStartCmdRetryCount, &boot_ft); asMsg = "AutoBoot_FlashTool(): Error: ret=0x" + IntToHex((int)ret, 6); } else { ret = Boot_FlashTool_Ex(hCOM, bbchip, ext_clock, &g_stopflag, BOOT_INFINITE, g_MaxBromStartCmdRetryCount, &boot_ft); asMsg = "Boot_FlashTool(): Error: ret=0x" + IntToHex((int)ret, 6); } if( BROM_OK != ret ) { // stop timer Synchronize(StopTimer); if( BOOT_STOP != g_stopflag ) { Synchronize(ShowMsg); } return; } COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout = 0; timeouts.ReadTotalTimeoutMultiplier = 1; timeouts.ReadTotalTimeoutConstant = 1000; timeouts.WriteTotalTimeoutMultiplier = 1; timeouts.WriteTotalTimeoutConstant = 1000; if(!::SetCommTimeouts(hCOM, &timeouts)) { // stop timer Synchronize(StopTimer); ret = GetLastError(); asMsg = "SetCommTimeouts(): Error: ret=" + IntToStr(ret); Synchronize(ShowMsg); return; } bool bIsUpToDate=false; m_RecvString = ""; while( g_bDebugDA && (BOOT_STOP!=g_stopflag) ) { unsigned char ch; bool bResult; unsigned long readlen; ch = 0; readlen = 0; bResult = ReadFile( hCOM, &ch, 1, &readlen, NULL ); if( true==bResult && 1==readlen ) { AnsiString str; m_RecvChar = ch; str.printf("%c", ch); m_RecvString += str; if( 0 == (m_RecvString.Length()%1024) ) { Synchronize(UpdateDebugDAWindow); bIsUpToDate = true; } else { bIsUpToDate = false; } } else if(!bIsUpToDate) { Synchronize(UpdateDebugDAWindow); bIsUpToDate = true; } } // stop timer Synchronize(StopTimer); return; } /////////////////////////////////////////////////////////////////////////