📄 tboot_1.cpp
字号:
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -