📄 flashdownload.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) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* FlashDownload.cpp
*
* Project:
* --------
* Multiport download
*
* Description:
* ------------
* Flash download/format thread source file
*
* Author:
* -------
* Andy Ueng (mtk00490)
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* $Revision$
* $Modtime$
* $Log$
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
//---------------------------------------------------------------------------
#include "meta.h"
#pragma hdrstop
#include "Multiport_Common.h"
#ifndef _MD_MSG_
#include "MD_msg.h"
#endif
#include "FlashDownLoad.h"
#include "MultiPortFlashDownloadTool.h"
#ifndef _FACTORY_COMMON_H_
#include "factory_common.h"
#endif
#pragma package(smart_init)
bool isShowNoFormatInfo = false;
bool isShowFileNotLoaded = false;
BBCHIP_TYPE gbb_chip_type;
int boot_stop = 0;
HANDLE Flash_Download_Event[MAX_SUPPORT_PORT_NUM];
int stopflag[MAX_SUPPORT_PORT_NUM];
extern bool isStopTrigger[MAX_SUPPORT_PORT_NUM];
// access
extern HANDLE hSemaphore;
//=============================================================================
//////////////////////// call back ////////////////////////////////////////
//=============================================================================
static int __stdcall cb_download_da_init(void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
int i;
i = t->m_com_port.number - m_TheFirstComNo;
MainForm->DownLoadTimeSec[i]=0;
// access
if( MainForm->Get_EnableFactoryDatabaseLog() )
{
TDateTime datetime;
TDateTime date = datetime.CurrentDate();
TDateTime time = datetime.CurrentTime();
sTime stime;
time.DecodeTime( &stime.hour, &stime.min, &stime.sec, &stime.msec);
MainForm->SetDnDate( i, date );
MainForm->SetDnStartTime( i, time );
MainForm->SetDnStartsTime( i, stime );
}
//MainForm->TimerCOMArray[i]->Enabled = false;
//MainForm->TimerCOMArray[i]->Interval = 1000;
//MainForm->TimerCOMArray[i]->Enabled = true;
// MainForm->pbCOMArray[i]->ForeColor = clRed;
MainForm->SetPbComProgress( i, 0 );
MainForm->SetPbComForeColor( i, clRed );
t->progress_percentage = 0;
t->prefix = "DA ";
t->SyncInitProgress();
return 0;
}
//---------------------------------------------------------------------------
static int __stdcall cb_download_da(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
t->progress_percentage = percent;
t->prefix = "DA ";
t->SyncUpdateProgress();
return 0;
}
//---------------------------------------------------------------------------
static int __stdcall cb_download_flash_init(void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
int i;
t->progress_percentage = 0;
t->prefix = "DL ";
t->SyncInitProgress();
return 0;
}
//---------------------------------------------------------------------------
static int __stdcall cb_download_flash(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
t->progress_percentage = percent;
t->prefix = "DL ";
t->SyncUpdateProgress();
// if (percent <= 5)
{
int i = t->m_com_port.number - m_TheFirstComNo;
MainForm->pbCOMArray[i]->ForeColor = clBlue; // VCL
}
return 0;
}
//-----------------------------------------------------------------------------
static int __stdcall cb_download_bloader_init(void *usr_arg)
{
#if 0
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();
#endif
return 0;
}
//-----------------------------------------------------------------------------
static int __stdcall cb_download_bloader(unsigned char percent, unsigned int sent_bytes, unsigned int total_bytes, void *usr_arg)
{
#if 0
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();
#endif
return 0;
}
//==============================================================================
static int __stdcall cb_format_report_init(void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
int i;
t->progress_percentage = 0;
t->prefix = "FR ";
t->SyncInitProgress();
return 0;
}
//------------------------------------------------------------------------------
static int __stdcall cb_format_report(unsigned char percent, void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
t->progress_percentage = percent;
t->prefix = "FR ";
t->SyncUpdateProgress();
// if (percent <= 50)
{
int i = t->m_com_port.number - m_TheFirstComNo;
MainForm->pbCOMArray[i]->ForeColor = clGreen; // VCL
}
return 0;
}
//-----------------------------------------------------------------------------------
static int __stdcall cb_before_process(const DA_REPORT_T *p_da_report, void *usr_arg)
{
#if 0
TBOOT1 *t=(TBOOT1 *)usr_arg;
int i;
i = t->m_com_port.number - m_TheFirstComNo;
//-----------------------------------------------------------------------
// to do: set stopflag[i]=BOOT_STOP when flash type does not match
// check flash type here
if( p_da_report->/* flash type match */ )
{
....
}
else
{
/* not match */
stopflag[i] = BOOT_STOP;
}
#endif
return 0;
}
//------------------------------------------------------------------------------
static int __stdcall cb_in_brom_stage(unsigned int brom_handle, HANDLE hCOM, void *usr_arg) {
int ret;
unsigned short value16;
TBOOT1 *t=(TBOOT1 *)usr_arg;
if( MainForm->isPullDownGPIO17 && gbb_chip_type == MT6218B )
{
// 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)
{
#if 0
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();
#endif
return 0;
}
//---------------------------------------------------------------------------
static int __stdcall cb_boot_meta_in_brom_stage(unsigned int brom_handle, HANDLE hCOM, void *usr_arg)
{
TBOOT1 *t=(TBOOT1 *)usr_arg;
t->progress_percentage = 0;
t->prefix = "FR ";
t->SyncStartFactoryDefaultProgress();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -