www.pudn.com > FlashTool_src_v2.9.1006.zip > brom.h
/******************************************************************************* * 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) 2003 * ******************************************************************************/ /******************************************************************************* * Filename: * --------- * brom.h * * Project: * -------- * BootRom Library * * Description: * ------------ * Exported C interface APIs for BootRom library. * * Author: * ------- * Amos Hsu (mtk00539) * *============================================================================== * HISTORY * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! *------------------------------------------------------------------------------ * $Revision: 1.21 $ * $Modtime: Dec 06 2005 15:05:36 $ * $Log: //mtkvs01/vmdata/flash_tool/archives/BootRom/brom.h-arc $ * * Jul 21 2006 mtk01413 * [STP100001021] FlashTool v2.9.1002 release * 1. [BROM_DLL] Fix DA download error on MT6205/MT6205B. * * Rev 1.21 Dec 29 2005 10:42:02 mtk00539 * 1. [BROM_DLL] Support new baseband chip MT6226M. * Resolution for 156: [FlashTool v2.7.1013][BUG FIX] Fix BootROM start command failure while manually selecting NMT6226 or MT6227 baseband chip. * * Rev 1.20 Sep 13 2005 13:21:58 mtk00539 * 1. [BROM_DLL][Enhance] Workaround the 1st time power up failure issue when RTC is empty. * 2. [BROM_DLL][Enhance] Padding download bin file length to EVEN number. * 3. [BROM_DLL][New] New baseband chip support, MT6226, MT6227(0x8A01), MT6228(0x8A01). * Resolution for 130: [BROM_DLL v2.4.1016][Enhance] Workaround the 1st time power up failure issue when RTC is empty. * * Rev 1.19 Jul 24 2005 21:37:50 mtk00539 * 1. Support MT6228 NFB META mode. * Resolution for 121: [BROM_DLL v2.4.1014][New] Support MT6227 and MT6228 NFB META mode. * * Rev 1.18 May 24 2005 19:54:20 mtk00539 * 1. [BROM_DLL][New] Add DA_cmd::CMD_EnableWatchDog() to enable watchdog after download process. * 2. [BROM_DLL][New] Add DL_ResourceProjectIdComparisonSetting() API to enable/disable resource project id comparison. * 3. [BROM_DLL][New] Add callback function in Boot_META() series API to do extra process after BootROM start command passed. * 4. [BROM_DLL][BUG FIX] Fix com port error after using HyperTerminal. * 5. [BROM_DLL][BUG FIX] Fix m_boot_timeout takes no effect in BRom_AutoBoot::BRom_StartCmd(). * 6. [BROM_DLL][Change Behavior] Stop download process while CALLBACK_BEFORE_PROCESS return non-zero value. * 7. [BROM_DLL][Change Behavior] Skip resource table size and content size checking for CustPack project. * Resolution for 115: [BROM_DLL v2.4.1012][New] Support new flash devices and bug fix. * * Rev 1.17 Nov 22 2004 14:27:54 mtk00539 * 1. [BROM_DLL][BUG FIX] Add baudrate sync procedure for BootROM stage baudrate change for Prolific convertor. * 2. [BROM_DLL][BUG FIX] Fix ReadData() delay time too long problem in DA_cmd::CMD_ChangeUartSpeed() while target is running at 13MHz. * 3. [BROM_DLL][BUG FIX] DO NOT use while loop in reading BootROM ack in BRom_AutoBoot::BRom_StartCmd(), it will cause BootROM timeout. * 4. [BROM_DLL][Enhance] Extend the read timeout waiting time in DA_cmd::CMD_WriteData, because SHARP flash program time is slow. * 5. [BROM_DLL][Enhance] Add m_speedup_brom_baudrate flag to enable/disable speed-up baudrate in BootROM stage. * Resolution for 99: [BROM_DLL v2.4.1008][New] Support INTEL family flash Buffered-Program method. * * Rev 1.16 Nov 05 2004 10:35:08 mtk00539 * 1. [BROM_DLL][New] Implement S/W compatible mechanism for MT6218B_FN and MT6218B_GN. * 2. [BROM_DLL][Enhance] Read property to check if it was RS232 or Modem from COM1 to COM3. * 3. [BROM_DLL][Change Behavior] Unknown bbchip won't allow to download once check ECO version flag is enabled. * Resolution for 96: [BROM_DLL v2.4.1007][New] Implement S/W compatible mechanism for MT6218B_FN and MT6218B_GN. * * Rev 1.15 Oct 29 2004 11:42:58 mtk00539 * 1. [BROM_DLL][New] Implement auto bbchip and ext_clock detection mechanism. * 2. [BROM_DLL][New] Increase BootROM baudrate as twice times by setup UART_HIGHSPEED_RATE_STEP register. * 3. [BROM_DLL][New] Add new bbchip MT6205_EN and MT6218B_GN. * 4. [BROM_DLL][Enhance] Increase MT6217 and MT6219 EMI driving strength. * Resolution for 92: [BROM_DLL v2.4.1006][BUG FIX] Fix AM49DL3208GT & S71PL032J download fail problem and some enhancement. * * Rev 1.14 Jul 19 2004 01:56:36 mtk00539 * 1. [BROM_DLL][BUG FIX] When bbchip_type is inconsistent with rom bbchip info, do not use rom bbchip info to compare with target bbchip id. * 2. [BROM_DLL][BUG FIX] Fix baudrate 921600 download fail under 13MHz external clock. * 1. Add Sleep(0) to force context switch to flush UART TX data in BRom_Base::WriteData() and DA_cmd::WriteData(). * 2. After target side baudrate changed command was issued, add Sleep() to delay sending SYNC_CHAR. * This will prevent the interference of target side UART state machine during target side baudrate changed. * 3. Purge PC side and target side UART TX & RX FIFO after baudrate changed. * 4. Use while(1) loop to avoid flash readback checksum timeout. * 5. Add baudrate full char sync mechanism to test if baudrate is stable. * 3. [BROM_DLL][CHANGE] Change GetJumpTableInfoFromBuf() to fit JumpTable definition changed in Maui.SW system. * 4. [BROM_DLL][Enhance] Remove unnecessary functions MT6205_MEM_config and MT6205B_MEM_config. * 5. [BROM_DLL][Enhance] Add MT6218B and MT6219 EMI general control register setting in BootROM stage. * 6. [BROM_DLL][Enhance] Change EMI setting to 32 bits. * Resolution for 81: [BROM_DLL v2.4.1001] Support Intel flash and fix many bugs. * * Rev 1.13 May 26 2004 21:23:58 mtk00539 * [New] Add callback function in BootROM stage. So that users could have chance to issue other BootROM command after start cmd is passed, or do whatever they want otherwise. * Resolution for 73: [BROM_DLL v2.3.1005][New] Add callback function in BootROM stage. * * Rev 1.12 May 21 2004 15:44:38 mtk00539 * 1. [brom.dll][New] add J2ME_ROM resource for w04.21 load. * 2. [brom.dll][New] add MT6217 BootROM. * 3. [brom.dll][New] add Brom_DownloadData API. * 4. [brom.dll][New] remove Brom_Verify relative APIs. * 5. [brom.dll][Enhance] move region overlap checking from Rom_Load() to IsReady() for more convenience. * Resolution for 70: [BROM_DLL v2.3.1003][New] add J2ME_ROM resource for w04.21 load. * * Rev 1.11 May 17 2004 12:55:20 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.10 May 14 2004 17:01:26 mtk00539 * 1. [brom.dll][BUG FIX] fix DA_cmd::CMD_WriteData() buffer overrun problem. * 2. [brom.dll][BUG FIX] remove DA_HANDLE & DL_HANDLE rwlock_writer_sentry for multi-thread download. * 3. [brom.dll][BUG FIX] fix download address remap problem for Multi-Bin download on MT6218B series projects. * 4. [brom.dll][Enhance] for the unknown bbchip_name just bypass ECO checking, don't stop process. * 5. [brom.dll][New] add FAT auto format mechanism, parse the embedded FAT range info from the end of the ROM file. * 6. [brom.dll][New] add DA auto selection mechanism, parse the embedded custom_bane info from the end of the DA file. * 7. [brom.dll][New] add _ByhCOM interface to let users to control com port handle. * 8. [brom.dll][New] add BootROM start command retry mechanism to prevent cable TX/RX cross over. * 9. [brom.dll][New] add MT6219_AV, MT6219_BV and MT6218B_FN support. * 10. [DA][New] add DA auto selection mechanism, append custom_name at the end of DA. * 11. [DA][New] add FAT auto format mechanism, report flash manufacture id and device code to PC side. * Resolution for 67: [BootRom v2.3.1001][New] add FAT auto format, DA auto selection mechanism and bug fix. * * Rev 1.9 Mar 18 2004 23:06:40 mtk00539 * 1. [brom.dll][Enhance] only bbchip after MT6218B has to check firmware version. * 2. [brom.dll][BUG FIX] change func() to func(void) to fix header file compatibility for LabView. * 3. [brom.dll][BUG FIX] CompareTargetBBChipHWID() should return error and skip comparison when target doesn't respond. * Resolution for 61: [BootRom v2.2.1012][BUG FIX] fix CompareTargetBBChipHWID() error. * * Rev 1.8 Mar 09 2004 21:00:50 mtk00539 * [Enhance] check BBChip H/W version in Boot_META and Boot_FlashTool. * Resolution for 57: [BootRom v2.2.1010][Enhance] check BBChip H/W version in Boot_META and Boot_FlashTool. * * Rev 1.7 Mar 02 2004 00:19:04 mtk00539 * 1. [brom.dll][Enhance] add resource and jump table consistency detection. * 2. [brom.dll][Enhance] read back target's jump table layout and compare before download. * 3. [brom.dll][Enhance] automatically load all the resource files. * 4. [brom.dll][Enhance] add target bbchip id detection. * 5. [brom.dll][Enhance] add ini module. * 6. [brom.dll][Enhance] add MT6219 support. * Resolution for 53: [BootRom v2.2.1007][Enhance] resource layout error detection. * * Rev 1.6 Sep 25 2003 13:57:52 mtk00539 * brom.dll v2.1.1001, please see SCR(28) for more details. * Resolution for 28: [BootRom v2.1.1001][New] See the reasons below. * * Rev 1.5 Jul 25 2003 15:50:28 mtk00539 * Reason: * 1. SA reports read(10sec)/write(3sec) timeouts are too long. Because DA_cmd::WriteData() and DA_cmd::ReadData() will re-try one time, so the actual timeouts are read(10x2sec)/write(3x2sec). So I decide to reduce timeouts to read(5sec)/write(1.5sec). * * 2. Add specific debug log at the end of FlashDownload(), FlashReadback() and FlashFormat(). In this way SA can query whether if the function successfully executed by this signature. * * 3. Export debug log clear function, let users clear debug log whenever they want. * Resolution for 17: [BootRom v2.0.1006][Add Features] shorten read/write timeout and export debug log clear function. * * Rev 1.4 Jun 30 2003 19:24:50 mtk00539 * 1. [brom.dll][Add Features] Split flashtool function into brom.dll * 2. [brom.dll][Add Features] Add a fake MT6208 bootrom for FlashTool for Pluto version. * 3. [DA][Add Features] Check format range. * 4. [DA][Add Features] Report format percentage. * 5. [DA][Add Features] Support 6208 EVB/CEVB for double flash devices access. * 6. [DA][BUG FIXED] Fix DA pre-format sector bug, it shouldn't format beyond the max size of flash. * 7. [DA][BUG FIXED] Fix DA FlashTool MEM_CMD end_addr bug, FlashTool should use (begin_addr+length-1) as end_addr. * 8. [DA][BUG FIXED] Fix DA AM29DL640D, MB84VD23280FA and TC58FVB64 flash table error. * Resolution for 12: [BootRom v2.2.1001][New Version] Split flashtool function into brom.dll * * Rev 1.2 May 22 2003 17:27:48 mtk00539 * add bootstop flag * Resolution for 6: [FlashTool v2.2][AddFeature] Support 6205/6205B at 13MHz, 26MHz and 52MHz. * * Rev 1.1 May 20 2003 18:05:46 mtk00539 * add copyright * Resolution for 6: [FlashTool v2.2][AddFeature] Support 6205/6205B at 13MHz, 26MHz and 52MHz. * *------------------------------------------------------------------------------ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! *============================================================================== *******************************************************************************/ #ifndef _BROM_H_ #define _BROM_H_ #include#include "mtk_mcu.h" #ifdef __cplusplus extern "C" { #endif // The magic value to stop boot process #define BOOT_STOP 9876 // boot infinitely #define BOOT_INFINITE 0xFFFFFFF // default start cmd retry count #define DEFAULT_BROM_START_CMD_RETRY_COUNT 1 //------------------------------------------------------------------------------ // Boolean //------------------------------------------------------------------------------ typedef enum { _FALSE = 0, _TRUE = 1 } _BOOL; //------------------------------------------------------------------------------ // return code //------------------------------------------------------------------------------ #define BROM_RET(ret) (ret&0x00FF0000) #define BROM_OK 0x000000 #define BROM_ERROR 0x010000 #define BROM_NO_MEMORY 0x020000 #define BROM_INVALID_ARGUMENTS 0x030000 #define BROM_SET_COM_STATE_FAIL 0x040000 #define BROM_PURGE_COM_FAIL 0x050000 #define BROM_SET_META_REG_FAIL 0x060000 #define BROM_SET_FLASHTOOL_REG_FAIL 0x070000 #define BROM_SET_REMAP_REG_FAIL 0x080000 #define BROM_SET_MEM_WAIT_STATE_FAIL 0x090000 #define BROM_DOWNLOAD_DA_FAIL 0x0A0000 #define BROM_CMD_START_FAIL 0x0B0000 #define BROM_CMD_JUMP_FAIL 0x0C0000 #define BROM_CMD_WRITE16_MEM_FAIL 0x0D0000 #define BROM_CMD_READ16_MEM_FAIL 0x0E0000 #define BROM_CMD_WRITE16_REG_FAIL 0x0F0000 #define BROM_CMD_READ16_REG_FAIL 0x100000 #define BROM_CMD_CHKSUM16_MEM_FAIL 0x110000 #define BROM_CMD_WRITE32_MEM_FAIL 0x120000 #define BROM_CMD_READ32_MEM_FAIL 0x130000 #define BROM_CMD_WRITE32_REG_FAIL 0x140000 #define BROM_CMD_READ32_REG_FAIL 0x150000 #define BROM_CMD_CHKSUM32_MEM_FAIL 0x160000 #define BROM_WR16_RD16_MEM_RESULT_DIFF 0x170000 #define BROM_WR16_RD16_REG_RESULT_DIFF 0x180000 #define BROM_WR32_RD32_MEM_RESULT_DIFF 0x190000 #define BROM_WR32_RD32_REG_RESULT_DIFF 0x1A0000 #define BROM_CHKSUM16_MEM_RESULT_DIFF 0x1B0000 #define BROM_CHKSUM32_MEM_RESULT_DIFF 0x1C0000 #define BROM_BBCHIP_HW_VER_INCORRECT 0x1D0000 #define BROM_FAIL_TO_GET_BBCHIP_HW_VER 0x1E0000 #define BROM_SKIP_BBCHIP_HW_VER_CHECK 0x1F0000 #define BROM_UNKNOWN_BBCHIP 0x200000 #define BROM_UNKNOWN_TGT_BBCHIP 0x210000 #define BROM_BBCHIP_DSP_VER_INCORRECT 0x220000 #define BROM_MULTIPLE_BAUDRATE_FAIL 0x230000 #define BROM_JUMP_TO_NFB_DETECTION_FAIL 0x240000 #define BROM_SET_LOCK_POWER_FAIL 0x250000 #define BROM_CMD_START_TIMEOUT 0x260000 //------------------------------------------------------------------------------ // prototype of percentage callback function in BootROM stage //------------------------------------------------------------------------------ typedef int (__stdcall *CALLBACK_IN_BROM_STAGE)(unsigned int brom_handle, HANDLE hCOM, void *usr_arg); //------------------------------------------------------------------------------ // prototype of percentage callback function for download a buffer into target //------------------------------------------------------------------------------ typedef int (__stdcall *CALLBACK_BROM_WRITE_BUF_INIT)(void *usr_arg); typedef int (__stdcall *CALLBACK_BROM_WRITE_BUF)(unsigned char finished_percentage, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg); //------------------------------------------------------------------------------ // runtime debug trace //------------------------------------------------------------------------------ int __stdcall Brom_DebugOn(void); int __stdcall Brom_DebugOff(void); int __stdcall Brom_DebugClear(void); //------------------------------------------------------------------------------ // translate enum to string //------------------------------------------------------------------------------ const char * __stdcall BBChipTypeToName(const BBCHIP_TYPE bbchip); const char * __stdcall ExtClockToName(const EXT_CLOCK ext_clock); //------------------------------------------------------------------------------ // boot META mode //------------------------------------------------------------------------------ typedef struct { // This callback function will be invoke after BootROM start cmd is passed. // You can issue other BootROM command by brom_handle and hCOM which provides callback arguments, // or do whatever you want otherwise. CALLBACK_IN_BROM_STAGE m_cb_in_brom_stage; void *m_cb_in_brom_stage_arg; } BOOT_META_ARG; int __stdcall Boot_META( HANDLE hCOM, BBCHIP_TYPE bbchip, EXT_CLOCK ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, const BOOT_META_ARG *p_arg); int __stdcall Boot_META_Ex( HANDLE hCOM, BBCHIP_TYPE bbchip, EXT_CLOCK ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, unsigned int max_start_cmd_retry_count, const BOOT_META_ARG *p_arg); int __stdcall AutoBoot_META( HANDLE hCOM, BBCHIP_TYPE *p_bbchip, EXT_CLOCK *p_ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, const BOOT_META_ARG *p_arg); int __stdcall AutoBoot_META_Ex( HANDLE hCOM, BBCHIP_TYPE *p_bbchip, EXT_CLOCK *p_ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, unsigned int max_start_cmd_retry_count, const BOOT_META_ARG *p_arg); //------------------------------------------------------------------------------ // boot FlashTool download mode //------------------------------------------------------------------------------ typedef struct { // [IN] the PC side bbchip revsion name that is used to compare with target bbchip // eg: "MT6218B_EN", if this field is NULL it will skip comparison with target bbchip const char *m_p_bbchip_name; // EMI Control for Bank0 and Bank1 unsigned int *m_p_bank0_mem_cfg; // bank0 memory config unsigned int *m_p_bank1_mem_cfg; // bank0 memory config // Download Agent unsigned int m_da_start_addr; // DA start address const unsigned char *m_da_buf; // buffer stored DA code unsigned int m_da_len; // length of DA buffer unsigned int m_da_main_prog_len; // length of DA main subroutine // Callback function for initialization before downloading DA code into target CALLBACK_BROM_WRITE_BUF_INIT m_cb_download_da_init; // The user input argument for callback function void *m_cb_download_da_init_arg; // Callback function while downloading DA code into target CALLBACK_BROM_WRITE_BUF m_cb_download_da; // The user input argument for callback function void *m_cb_download_da_arg; // This callback function will be invoke after BootROM start cmd is passed. // You can issue other BootROM command by brom_handle and hCOM which provides callback arguments, // or do whatever you want otherwise. CALLBACK_IN_BROM_STAGE m_cb_in_brom_stage; void *m_cb_in_brom_stage_arg; // speed-up BootROM stage baudrate _BOOL m_speedup_brom_baudrate; } BOOT_FLASHTOOL_ARG; int __stdcall Boot_FlashTool( HANDLE hCOM, BBCHIP_TYPE bbchip, EXT_CLOCK ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, const BOOT_FLASHTOOL_ARG *p_arg); int __stdcall Boot_FlashTool_Ex( HANDLE hCOM, BBCHIP_TYPE bbchip, EXT_CLOCK ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, unsigned int max_start_cmd_retry_count, const BOOT_FLASHTOOL_ARG *p_arg); int __stdcall AutoBoot_FlashTool( HANDLE hCOM, BBCHIP_TYPE *p_bbchip, EXT_CLOCK *p_ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, const BOOT_FLASHTOOL_ARG *p_arg); int __stdcall AutoBoot_FlashTool_Ex( HANDLE hCOM, BBCHIP_TYPE *p_bbchip, EXT_CLOCK *p_ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, unsigned int max_start_cmd_retry_count, const BOOT_FLASHTOOL_ARG *p_arg); //------------------------------------------------------------------------------ // get brom.dll version //------------------------------------------------------------------------------ int __stdcall GetBromDLLVersion( unsigned int *major_ver, unsigned int *minor_ver, unsigned int *build_num ); //------------------------------------------------------------------------------ // BootROM Command //------------------------------------------------------------------------------ int __stdcall Brom_Create(unsigned int *p_brom_handle, BBCHIP_TYPE bbchip, EXT_CLOCK ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, unsigned int max_start_cmd_retry_count); int __stdcall Brom_CreateAutoBoot(unsigned int *p_brom_handle, BBCHIP_TYPE *p_bbchip, EXT_CLOCK *p_ext_clock, int *p_bootstop, unsigned int ms_boot_timeout, unsigned int max_start_cmd_retry_count); int __stdcall Brom_Destroy(unsigned int *p_brom_handle); int __stdcall Brom_StartCmd(unsigned int brom_handle, HANDLE hCOM); int __stdcall Brom_Write16Cmd(unsigned int brom_handle, HANDLE hCOM, unsigned int write_addr, unsigned short *data, unsigned int num_of_word); int __stdcall Brom_Read16Cmd(unsigned int brom_handle, HANDLE hCOM, unsigned int read_addr, unsigned short *data, unsigned int num_of_word); int __stdcall Brom_Write32Cmd(unsigned int brom_handle, HANDLE hCOM, unsigned int write_addr, unsigned int *data, unsigned int num_of_dword); int __stdcall Brom_Read32Cmd(unsigned int brom_handle, HANDLE hCOM, unsigned int read_addr, unsigned int *data, unsigned int num_of_dword); int __stdcall Brom_Checksum16Cmd(unsigned int brom_handle, HANDLE hCOM, unsigned int chksum_addr, unsigned int num_of_word, unsigned short *chksum); int __stdcall Brom_JumpCmd(unsigned int brom_handle, HANDLE hCOM, unsigned int jump_addr, unsigned char bWaitForAck); int __stdcall Brom_DownloadData(unsigned int brom_handle, HANDLE hCOM, unsigned int base_addr, const unsigned char *buf_in, unsigned int num_of_byte, CALLBACK_BROM_WRITE_BUF_INIT cb_init, void *cb_init_arg, CALLBACK_BROM_WRITE_BUF cb, void *cb_arg); #ifdef __cplusplus } #endif #endif