📄 tboot_1.cpp
字号:
void _fastcall tboot_1::StopTimer() {
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(HW_StorageType_E storage_type, unsigned int begin_addr, unsigned int length, void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
t->progress_hint.printf("Format %s flash: begin_addr(0x%08X), length(0x%08X). ", (HW_STORAGE_NOR==storage_type)?"NOR":"NAND", begin_addr, length);
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(HW_StorageType_E storage_type, unsigned int rb_addr, unsigned int rb_length, const char *rb_filepath, void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
AnsiString s;
if( NULL != rb_filepath ) {
s.printf("Readback %s flash to \"%s\", ADDR(0x%08X), LEN(0x%08X). ", (HW_STORAGE_NOR==storage_type)?"NOR":"NAND", rb_filepath, rb_addr, rb_length);
}
else {
s.printf("Readback %s flash to buffer, ADDR(0x%08X), LEN(0x%08X). ", (HW_STORAGE_NOR==storage_type)?"NOR":"NAND", rb_filepath, rb_addr, rb_length);
}
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_da_report(const DA_REPORT_T *p_da_report, void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
if( MainForm->mi_MultiLoad->Checked ){
for( int index = 0; index < g_DL_HANDLE_LIST_nodes.size(); index++){
if( g_DL_HANDLE_LIST_nodes[index].m_dl_handle == p_da_report->m_dl_handle ){
t->dl_arg.m_otp_enable = g_DL_HANDLE_LIST_nodes[index].m_param.m_otp_enable;
t->dl_arg.m_otp_op = g_DL_HANDLE_LIST_nodes[index].m_param.m_otp_op;
t->dl_arg.m_otp.m_addr = g_DL_HANDLE_LIST_nodes[index].m_param.m_otp.m_addr;
t->dl_arg.m_otp.m_data = g_DL_HANDLE_LIST_nodes[index].m_param.m_otp.m_data;
t->dl_arg.m_otp.m_len = g_DL_HANDLE_LIST_nodes[index].m_param.m_otp.m_len;
t->dl_arg.m_ft_cfg_enable = g_DL_HANDLE_LIST_nodes[index].m_param.m_ft_cfg_enable;
t->dl_arg.m_ft_cfg.m_security_cfg.m_uint32 = g_DL_HANDLE_LIST_nodes[index].m_param.m_ft_cfg.m_security_cfg.m_uint32;
t->dl_arg.m_sec_ro_enable = g_DL_HANDLE_LIST_nodes[index].m_param.m_sec_ro_enable;
t->dl_arg.m_sec_ro.m_data = g_DL_HANDLE_LIST_nodes[index].m_param.m_sec_ro.m_data;
t->dl_arg.m_sec_ro.m_len = g_DL_HANDLE_LIST_nodes[index].m_param.m_sec_ro.m_len;
t->dl_arg.m_cust_para_enable = g_DL_HANDLE_LIST_nodes[index].m_param.m_cust_para_enable;
t->dl_arg.m_cust_para.m_data = g_DL_HANDLE_LIST_nodes[index].m_param.m_cust_para.m_data;
t->dl_arg.m_cust_para.m_len = g_DL_HANDLE_LIST_nodes[index].m_param.m_cust_para.m_len;
break;
}
}
}
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_T *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;
}
static int __stdcall cb_post_process_init(void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
AnsiString s;
s.printf("Proceed post-process now...");
t->progress_hint = s;
t->progress_forecolor = 0x00990000;
t->progress_percentage = 0;
t->bUpdateFinishBytes = false;
t->SyncInitProgress();
return 0;
}
static int __stdcall cb_post_process(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_update_param_init(void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
AnsiString s;
s.printf("Update parameters now...");
t->progress_hint = s;
t->progress_forecolor = 0x008A28E5;
t->progress_percentage = 0;
t->bUpdateFinishBytes = false;
t->SyncInitProgress();
return 0;
}
static int __stdcall cb_update_param(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_security_pre_process_notify(void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
if( !g_bAutomation ){
t->asMsg.printf("Proceed 1st time download pre-process ... (it takes about 10~15 seconds)\n\nPlease press OK to continue!");
t->SyncShowMsg();
}
return 0;
}
static int __stdcall cb_progress_init(void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
MainForm->Timer_Download->Enabled = true;
t->progress_hint = "Extract NFB image now...";
t->progress_forecolor = 0x0088A050;
t->progress_percentage = 0;
t->progress_finished_bytes = 0;
t->bUpdateFinishBytes = true;
t->SyncInitProgress();
return 0;
}
static int __stdcall cb_progress(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_security_post_process_notify(void *usr_arg) {
tboot_1 *t=(tboot_1 *)usr_arg;
t->asMsg.printf("Proceed 1st time download post-process ... (it takes about 10~15 seconds)\n\nPlease press OK to continue!");
t->SyncShowMsg();
return 0;
}
void __fastcall tboot_1::Execute()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -