⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 MTK平台的下载程序源代码,极具参考价值,可修改支持其它芯片的FLASH
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************
*  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:
* ---------
*  main.cpp
*
* Project:
* --------
*  Flash tool set
*
* Description:
* ------------
*  Flash tool set main window
*
* Author:
* -------
*  FZ Hsu (mtk00303)
*
*==============================================================================
*           HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* $Revision:   1.44  $
* $Modtime:   Jan 13 2006 23:50:24  $
* $Log:   //mtkvs01/vmdata/flash_tool/archives/main.cpp-arc  $
 *
 * 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
 *
 * Feb 23 2006 mtk00539
 * [STP100000625] FlashTool v2.7.1016
 * 
 * 
 *    Rev 1.44   Jan 14 2006 00:49:52   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.43   Dec 29 2005 15:57:52   mtk00539
 * [BUG FIX] Fix the 10th download history could not be loaded problem.
 * Resolution for 156: [FlashTool v2.7.1013][BUG FIX] Fix BootROM start command failure while manually selecting NMT6226 or MT6227 baseband chip.
 *
 *    Rev 1.42   Dec 29 2005 10:57:24   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.41   Oct 19 2005 14:47:24   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.40   Sep 13 2005 13:38:14   mtk00539
 *  1. [FlashTool][New] Adapt new BROM_DLL&DA v2.4.1016. 
 * Resolution for 131: [FlashTool v2.6.1016][Enhance] Workaround the 1st time power up failure issue when RTC is empty.
 * 
 *    Rev 1.39   Jul 25 2005 14:56:46   mtk00539
 *  1. [FlashTool][New] Support MT6229.
 * Resolution for 125: [FlashTool v2.6.1015][New] Support MT6229.
 * 
 *    Rev 1.38   Jul 22 2005 20:48:28   mtk00539
 *  1. [FlashTool][New] Support MT6227.
 * Resolution for 122: [FlashTool v2.6.1014][New] Support MT6227.
 * 
 *    Rev 1.37   May 26 2005 14:31:10   mtk00539
 * call META_CancelAllBlockingCall() when press stop button.
 * Resolution for 116: [FlashTool v2.6.1012][New] Reset FAT to factory default setting.
 * 
 *    Rev 1.36   May 24 2005 20:03:38   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.35   Apr 12 2005 22:13:58   mtk00539
 *  1. [FlashTool][New] Support MT6228 baseband chip.
 * Resolution for 110: [FlashTool v2.6.1011][New] Support MT6228 baseband chip.
 * 
 *    Rev 1.34   Feb 16 2005 17:27:42   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.33   Nov 22 2004 14:30:10   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.32   Oct 29 2004 11:49:20   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.31   Sep 14 2004 16:42:02   mtk00539
 * [New] Adapt new BROM_DLL&DA v2.4.1005 to fix MT6217 download fail problem.
 * Resolution for 91: [FlashTool v2.6.1005][New] Adapt new BROM_DLL&DA v2.4.1005 to fix MT6217 download fail problem.
 * 
 *    Rev 1.30   Sep 03 2004 19:54:46   mtk00539
 * [FlashTool][New] Adapt new BROM_DLL&DA v2.4.1004 for MT6217 support.
 * Resolution for 89: [FlashTool v2.6.1004][New] Adapt new BROM_DLL&DA v2.4.1004 for MT6217 support.
 * 
 *    Rev 1.29   Aug 09 2004 09:58:10   mtk00539
 * change default baudrate_full_sync_count to 1.
 * 
 *    Rev 1.28   Aug 03 2004 22:42:28   mtk00539
 * remove unnecessar include files
 * 
 *    Rev 1.27   Aug 03 2004 15:07:10   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.26   Jul 19 2004 11:13:28   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.25   Jul 19 2004 02:10:54   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.24   Jun 16 2004 16:38:32   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.23   Jun 03 2004 11:55:32   mtk00539
 * when users select new scatter file, set dialog initial dir to scatter file base dir.
 * Resolution for 76: [FlashTool v2.5.1012][BUG FIX] Fix bug in FAT range info import.
 * 
 *    Rev 1.22   May 26 2004 21:54:56   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.21   May 21 2004 17:26:00   mtk00539
 * fix ROM hint
 * Resolution for 71: [FlashTool v2.5.1010][BUF FIX] fix incorrect error message of resource detection.
 * 
 *    Rev 1.20   May 21 2004 15:54:52   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.19   May 14 2004 17:04:20   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.18   Apr 20 2004 15:58:28   mtk00539
 * [Enhance] hide seldom used option, it an be turn on again by Advance Mode hot-key CTRL+ALT+O.
 * Resolution for 65: [FlashTool v2.5.1008][New] add baseband chip ECO revision checking flag for FlashDownload.
 * 
 *    Rev 1.17   Mar 29 2004 14:20:10   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.16   Mar 02 2004 00:28:16   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.15   Feb 11 2004 17:54:56   mtk00539
 * [Enhance] support selectable download
 * Resolution for 52: [FlashTool v2.5.1002][Enhance] selectable download.
 * 
 *    Rev 1.14   Feb 05 2004 13:40:34   mtk00539
 * adapt to BROM DLL v2.2.1001
 * Resolution for 47: [FlashTool v2.5.1001][New] support multiple concatanated bin files download.
 * 
 *    Rev 1.13   Oct 29 2003 17:39:12   mtk00539
 * modify packet length
 * 
 *    Rev 1.12   Oct 06 2003 14:25:54   mtk00539
 * Do not check DA handle when users select MT6208
 * Resolution for 29: [FlashTool v2.4.1001][New] See the reasons below.
 * 
 *    Rev 1.11   Oct 01 2003 23:38:16   mtk00539
 * Add packet length in DA_WRITE_CMD and DA_READ_CMD.
 * Resolution for 28: [BootRom v2.1.1001][New] See the reasons below.
 *
 *    Rev 1.10   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.9   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.8   Jun 11 2003 17:53:34   mtk00539
 * 1. Modify BootRom library to support MT6218
 * 2. Modify FlashTool and DA to support AM29PDL128G flash
 * Resolution for 9: [FlashTool v2.2.1005][Add Feature] Support MT6218 and new flash AM29PDL128G
 * 
 *    Rev 1.7   Jun 03 2003 22:24:54   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.6   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.5   Jan 09 2003 17:45:34   mtk00303
 * update for version 2
 * add flash erase, program timeout
 * add last 1~3 context switch ID, frame tick time
 * 
 *    Rev 1.4   Dec 10 2002 23:24:30   mtk00303
 * remove redundant comment
 * 
 *    Rev 1.3   Nov 20 2002 19:52:58   mtk00303
 * update for reference phone
 * 
 *    Rev 1.2   Jul 30 2002 10:45:24   admin
 * 2002_0730
 * 
 *    Rev 1.1   Jul 26 2002 11:52:18   admin
 * ver 0726
 * 
 *    Rev 1.0   Jul 20 2002 19:26:14   admin
 * Initial revision.
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*==============================================================================
*******************************************************************************/

//---------------------------------------------------------------------------


#include <vcl.h>
#include <inifiles.hpp>

#include <fcntl.h>
#include <io.h>
#include <string.h>

#include <vector>

#pragma hdrstop

#include "meta.h"
#include "main.h"
#include "ext_mem1.h"

#include "tboot_1.h"
#include "about.h"

#include "DA_option.h"
#include "RB_option.h"
#include "frm_FormatOption.h"

#include "DL_Go.h"
#include "RB_Go.h"
#include "com_util.h"
#include "com_enum.h"
#include "frm_BootROMStartCmdRetry.h"
#include "frm_COM_Option.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Trayicon"
#pragma link "CGAUGES"
#pragma link "CGAUGES"
#pragma resource "*.dfm"

#define LAB 1

TMainForm *MainForm;

DownloadHistoryList	g_DownloadHistory;

HANDLE UART_Com;

DCB dcbCommPort;
COMMTIMEOUTS ctmoNew;

UART_BAUDRATE	BAUD_RATE;
unsigned int	COM_PORT = 1;   // default com port 1
bool bInitComPort = false;

//int prior_menu_item;

bool DEBUG = true;

//#ifndef LAB
   bool PHASE2 = false; // old 2002.01.25
//#else
//   bool PHASE2 = true;    // for lab PHASE2== true, 2002.3.12
//#endif

FLASHTOOL_FUNCTION	g_flashtool_function = FLASHTOOL_DOWNLOAD;

bool bDownloadNot258Byte = false;

int iFlashItemIndex = 0;

FormatOption_E	g_FormatAfterDownloadOption;
FormatOption_E	g_FormatOption;
unsigned int g_ulFormatStartAddr;
unsigned int g_ulFormatLength;
unsigned int g_ulNandFormatStartAddr;
unsigned int g_ulNandFormatLength;
unsigned int g_COM_Read_Timeout = COM_DEFAULT_TIMEOUT;
unsigned int g_COM_Write_Timeout = COM_DEFAULT_TIMEOUT;
unsigned char g_Baudrate_FullSync_Count=1;
EXT_CLOCK	g_EXT_CLOCK=EXT_26M;
BBCHIP_TYPE	g_BBCHIP_TYPE=MT6218B;
bool	g_AutoDetectBBCHIP=true;
bool	g_bDebugDA = false;
bool	g_bTrace = false;
bool	g_bSkipBootRom = false;
bool	g_bCheckECOVer = true;
bool	g_bAutoSelectBBChipType = true;
bool	g_bCheckTgtResourceLayout = true;
bool	g_bAutoLoadResByScat = true;
bool	g_bEnableAdvanceOption = false;
bool	g_bPullDownGPIO17 = true;
bool	g_SpeedUpBootROMBaudrate = true;
bool	g_CompareResProjectId = true;
bool	g_FormatValidation = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -