📄 flashtool.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:
* ---------
* flashtool.h
*
* Project:
* --------
* Flash Download/Readback/Format Library.
*
* Description:
* ------------
* Exported C interface APIs for FlashTool Library.
*
* Author:
* -------
* Amos Hsu (mtk00539)
*
*==============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* $Revision: 1.21 $
* $Modtime: Jan 13 2006 20:33:38 $
* $Log: //mtkvs01/vmdata/flash_tool/archives/BootRom/flashtool.h-arc $
*
* 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. [BROM_DLL][NEW] Support 6229 Download, add m_emi_gen_c in DRAM setting
*
* Rev 1.21 Jan 14 2006 00:41:40 mtk00539
* Bug fixes:
* 1. [BROM_DLL&DA] Workaround reading DSP version failure issue in some production lines, rollback to the old method for reading DSP version.
*
* Enhancements:
* 1. [BROM_DLL&DA] Enhance DA_FINISH_CMD protocol by adding ACK and delay.
* 2. [BROM_DLL] Modify timeout mechanism for more reasonable in DA_cmd::WriteData() and DA_cmd::WriteData().
* Resolution for 159: [FlashTool v2.7.1015]
*
* Rev 1.20 Nov 19 2005 00:40:32 mtk00539
* 1. [BROM_DLL&DA][New] Add UID Secure Booting feature.
* 2. [BROM_DLL&DA][BUG FIX] Fix RTC date-time value could not be initialized problem.
* 3. [DA][New] Supports new NOR flash device.
* [INTEL] 38F1010C0ZBL0
* [INTEL] 28F1602C3BD70
* [TOSHIBA] TY0068B012APGG
* [TOSHIBA] TY0068B013APGG
* 4. [DA][New] Supports new NAND flash device.
* [HYNIX] HY27XG082G2M
* Resolution for 149: [BROM_DLL v2.7.1011][New] Add UID Secure Booting feature and Bug Fix.
*
* Rev 1.19 Oct 26 2005 09:43:42 mtk00539
* 1. [BROM_DLL][Enhance] Always fix BootROM start command read timeout to 20ms to bypass start command failure problem.
* 2. [DA][BUG FIX] Fix wrong start block address of 2nd binary for new NFB architecture.
* Resolution for 144: [BROM_DLL v2.7.1010][BUG FIX] Fix wrong start block address of 2nd binary for new NFB architecture.
*
* Rev 1.18 Oct 19 2005 14:44:44 mtk00539
* 1. [BROM_DLL&DA][New] New H/W devices detection architecture including NOR, NAND, SRAM and DRAM detection.
* 2. [BROM_DLL&DA][New] DA partial download technic, that overcomes DA size exceeds MT6205B internal SRAM (32KB).
* 3. [BROM_DLL&DA][New] Format verification option, each byte should be 0xFF after erasure.
* 4. [BROM_DLL&DA][New] DA validation to ensure invalid binary could not be loaded.
* 5. [BROM_DLL&DA][New] Support NFB download.
* 6. [BROM_DLL&DA][New] Support NAND flash format with 3 method, NORMAL, FORCEDLY ERASE and MARK AS BAD BLOCK.
* 7. [BROM_DLL&DA][New] Support NAND flash read back with 4 methods, PAGE+ECC, PAGE ONLY, SPARE ONLY and PAGE+SPARE.
* Resolution for 140: [BROM_DLL v2.7.1008][New] Support NFB download and many new features.
*
* Rev 1.17 May 24 2005 19:54:24 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.16 Nov 22 2004 14:27:56 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.15 Oct 29 2004 11:42:56 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 Sep 17 2004 17:03:34 mtk00539
* add new error code to indicate internal and external SRAM detection failure
* Resolution for 90: [BROM_DLL v2.4.1005][BUG FIX] Fix MT6217 download fail problem and some enhancement.
*
* Rev 1.13 Aug 03 2004 10:55:26 mtk00539
* 1. [BROM_DLL][BUG FIX] Use timeout waiting instead of while(1) waiting to prevent FlashTool UI hang without any error message.
* 2. [BROM_DLL][New] Add 12 new flash devices support.
* 3. [BROM_DLL][New] Add external SRAM size into DA_REPORT_T structure.
* 4. [BROM_DLL][Enhance] Skip old DA MT6205AB_DA.bin and MT6218AB_DA.bin in DA_HANDLE::AutoLoadByCustomName().
* 5. [BROM_DLL][Enhance] Remove Sleep() delay when RX_BUFFER_FULL. It's no need to delay, since when DA return RX_BUFFER_FULL, it flushed RX buffer to flash already.
* Resolution for 83: [BROM_DLL v2.4.1002] Merge all the DAs into all-in-one DA and fix many bugs and enhancement.
*
* Rev 1.12 Jul 19 2004 01:56:38 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.11 May 26 2004 21:24:00 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.10 May 14 2004 17:01:28 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 29 2004 13:59:24 mtk00539
* 1. [brom.dll][New] add baseband chip ECO revision checking flag for FlashDownload.
* 2. [brom.dll][Enhance] replace port_no with unsigned int instead of COM_PORT_NO enum.
* 3. [brom.dll][Enhance] add new member p_bbchip_name in FLASHTOOL_ARG to report target baseband chip name.
* 4. [brom.dll][Enhance] enumerate com port from registry and also check whether if its property is PST_RS232.
* 5. [brom.dll][Enhance] change com_sentry::Open() procedure to use SetCommConfig() like HyperTerminal.
* Resolution for 64: [BootRom v2.2.1013][New] add baseband chip ECO revision checking flag for FlashDownload.
*
* Rev 1.8 Mar 09 2004 21:01:00 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:06 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 Feb 11 2004 17:52:16 mtk00539
* [Enhance] support selectable download
* Resolution for 51: [BootRom v2.2.1003][Enhance] selectable download.
*
* Rev 1.5 Dec 12 2003 14:28:16 mtk00539
* add import mechanism for flash devie name list file.
* Resolution for 40: [BootRom v2.1.1007][New] support Fujitsu MB84VD22280FE flash and etc.
*
* Rev 1.4 Nov 12 2003 14:23:56 mtk00539
* 1. Add SOC feature.
* 2. Adapt new MTRACE macro.
* Resolution for 35: [BootRom v2.1.1005][New] Add SOC feature.
*
* Rev 1.3 Sep 25 2003 19:35:02 mtk00539
* add return code
* Resolution for 28: [BootRom v2.1.1001][New] See the reasons below.
*
* Rev 1.2 Sep 25 2003 13:57:54 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.1 Jul 09 2003 13:31:34 mtk00539
* reduce default timeout period and read/write incomplete retry times.
* Resolution for 14: [BootRom v2.0.1004] fine tune for high speed download card behavior.
*
* Rev 1.0 Jun 30 2003 18:13:58 admin
* Initial revision.
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*==============================================================================
*******************************************************************************/
#ifndef _FLASHTOOL_H_
#define _FLASHTOOL_H_
#include "brom.h"
#include "DOWNLOAD.H"
#include "flashtool_handle.h"
#ifdef __cplusplus
extern "C" {
#endif
//------------------------------------------------------------------------------
// return code
//------------------------------------------------------------------------------
#define FT_RET(ret) (ret&0x000000FF)
#define FT_OK 0x000000
#define FT_ERROR 0x000001
#define FT_INVALID_ARGUMENTS 0x000002
#define FT_COM_PORT_OPEN_ERR 0x000003
#define FT_DA_HANDLE_ERROR 0x000004
#define FT_DL_HANDLE_ERROR 0x000005
#define FT_RB_HANDLE_ERROR 0x000006
#define FT_BROM_ERROR 0x000007
#define FT_COM_PORT_SET_TIMEOUT_ERR 0x000008
#define FT_DA_NO_RESPONSE 0x000009
#define FT_DA_SYNC_INCORRECT 0x00000A
#define FT_DA_VERSION_INCORRECT 0x00000B
#define FT_DA_UNKNOWN_FLASH_DEVICE 0x00000C
#define FT_DA_SET_EXT_CLOCK_FAIL 0x00000D
#define FT_DA_SET_BBCHIP_TYPE_FAIL 0x00000E
#define FT_DA_CHANGE_BAUDRATE_FAIL 0x00000F
#define FT_DA_SET_DOWNLOAD_BLOCK_FAIL 0x000010
#define FT_DA_DOWNLOAD_FAIL 0x000011
#define FT_DA_READBACK_FAIL 0x000012
#define FT_DA_FORMAT_FAIL 0x000013
#define FT_DA_FINISH_CMD_FAIL 0x000014
#define FT_DA_SOC_CHECK_FAIL 0x000015
#define FT_DA_BBCHIP_DSP_VER_INCORRECT 0x000016
#define FT_SKIP_AUTO_FORMAT_FAT 0x000017
#define FT_DA_HW_ERROR 0x000018
#define FT_DA_ENABLE_WATCHDOG_FAIL 0x000019
#define FT_CALLBACK_ERROR 0x00001A
#define FT_DA_NAND_DOWNLOAD_BLOADER_FAIL 0x00001B
#define FT_DA_NAND_DOWNLOAD_IMAGE_FAIL 0x00001C
#define FT_DA_NAND_BLOADER_NOT_EXIST 0x00001D
#define FT_BL_HANDLE_ERROR 0x00001E
#define FT_DA_INIT_SYNC_ERROR 0x00001F
#define FT_NFB_NOT_SUPPORT_MBA 0x000020
#define FT_NFB_ONLY_SUPPORT_FOR_NAND_FLASH 0x000021
#define FT_NAND_RAW_DATA_DOWNLOAD_NOT_SUPPORT 0x000022
#define FT_NAND_READADDR_NOT_PAGE_ALIGNMENT 0x000023
#define FT_NAND_READLEN_NOT_PAGE_ALIGNMENT 0x000024
#define FT_BLOCK_UNSTABLE 0x000025
#define FT_DA_READ_REG16_FAIL 0x000026
#define FT_DA_WRITE_REG16_FAIL 0x000027
#define FT_DA_MEMCMD_INVALID_RANGE 0x000028
#define FT_DA_MEMCMD_PGM_AT_ODD_ADDR 0x000029
#define FT_DA_MEMCMD_PGM_WITH_ODD_LENGTH 0x00002A
#define FT_DA_MEMCMD_SIBLEY_PGM_AT_THE_SAME_REGIONS 0x00002B
//------------------------------------------------------------------------------
// accuracy enum
//------------------------------------------------------------------------------
typedef enum {
ACCURACY_AUTO = 0, // auto detect by baudrate
ACCURACY_1_3 = 3, // 33%
ACCURACY_1_4 = 4, // 25%
ACCURACY_1_10 = 10, // 10%
ACCURACY_1_100 = 100, // 1%
ACCURACY_1_1000 = 1000, // 0.1%
ACCURACY_1_10000 = 10000 // 0.01%
}ACCURACY;
//------------------------------------------------------------------------------
// utility functions
//------------------------------------------------------------------------------
extern const char * __stdcall GetNorFlashNameByTypeId(unsigned short type_id);
extern const char * __stdcall GetNandFlashNameByTypeId(unsigned short type_id);
extern const char * __stdcall DAStatusToString(STATUS_E status);
extern const char * __stdcall HWChipSelectToString(HW_ChipSelect_E cs);
extern const char * __stdcall HWStorageTypeToString(HW_StorageType_E type);
extern const char * __stdcall HWRamTypeToString(HW_RAMType_E type);
extern const char * __stdcall ReadFlagToString(NUTL_ReadFlag_E flag);
extern const char * __stdcall EraseFlagToString(NUTL_EraseFlag_E flag);
//------------------------------------------------------------------------------
// com port setting
//------------------------------------------------------------------------------
#ifndef COM_DEFAULT_TIMEOUT
#define COM_DEFAULT_TIMEOUT 0xFFFFFFF
#endif
#define COM_NO_TIMEOUT 0
typedef union {
unsigned char number;
HANDLE handle;
}COM_PORT_HANDLE;
typedef struct {
COM_PORT_HANDLE com;
UART_BAUDRATE baudrate;
unsigned int ms_read_timeout;
unsigned int ms_write_timeout;
}COM_PORT_SETTING;
//------------------------------------------------------------------------------
// DA report related function
//------------------------------------------------------------------------------
typedef struct {
// DA version
unsigned char m_expected_da_major_ver;
unsigned char m_expected_da_minor_ver;
unsigned char m_da_major_ver;
unsigned char m_da_minor_ver;
// bbchip
BBCHIP_TYPE m_bbchip;
unsigned short m_bbchip_hw_code;
unsigned short m_bbchip_hw_ver;
unsigned short m_bbchip_sw_ver;
// storagte report
STATUS_E m_storage_ret;
HW_StorageType_E m_storage_type;
HW_ChipSelect_E m_storage_chip_select[2];
unsigned short m_flash_id;
unsigned int m_flash_size;
unsigned short m_flash_dev_code_1;
unsigned short m_flash_dev_code_2;
unsigned short m_flash_dev_code_3;
unsigned short m_flash_dev_code_4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -