⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tboot_1.cpp

📁 MTK bin下载工具全部源代码(c++)
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					char path[512];
					AnsiString  filename;
					MTK_Resource	res_info;
					GetFullPathName(dl_arg.rom_info.filepath, sizeof(path), path, &p_filename);
					if( NULL!=p_filename && (strlen(dl_arg.rom_info.filepath)>(strlen(p_filename)+12)) ) {
						filename.printf("%.12s...\\%s", path, p_filename);
					}
					else {
						filename = dl_arg.rom_info.filepath;
					}
					DL_Rom_GetResInfo(g_DL_HANDLE, dl_arg.rom_info.index, &res_info);
					asMsg.printf("[DL_HANDLE]  %s (\"%s\"): The begin_addr(0x%08X) doesn't match resource base_addr(0x%08X)!", dl_arg.rom_info.name, filename.c_str(), dl_arg.rom_info.begin_addr, res_info.m_base_addr);
					Synchronize(ShowMsg);
	            }
				break;
			case FTHND_SCAT_REGION_IS_OVERLAP:
	            {
					ROM_INFO	rom_info;
					DL_Rom_GetInfo(g_DL_HANDLE, dl_arg.rom_info.index+1, &rom_info);
					asMsg.printf("[DL_HANDLE]  %s file overlap the next file %s !", dl_arg.rom_info.name, rom_info.name);
					Synchronize(ShowMsg);
	            }
				break;
			case FTHND_RES_IS_NOT_DOWNLOAD_WITH_JUMPTABLE:
				asMsg = "[DL_HANDLE] Resources and jump table are not selected to download together!";
				Synchronize(ShowMsg);
				break;
			case FTHND_RES_DOWNLOAD_SELECT_INCOMPLETE:
                // enable unselect files
                for(int i=0; i<dl_arg.required_resource_count; i++) {
                	DL_Rom_SetEnableAttr(g_DL_HANDLE, dl_arg.required_resource[i], _TRUE);
                }
				Synchronize(MainForm->SyncRedrawDownloadList);
				asMsg = "[DL_HANDLE] The resources you selected to download are incomplete, please download again!";
				Synchronize(ShowMsg);
				break;
			case FTHND_JUMPTABLE_INCONSISTENT_WITH_SCAT:
				asMsg = "[DL_HANDLE] jump table is different from scatter!";
				Synchronize(ShowMsg);
				break;
			case FTHND_JUMPTABLE_INCORRECT_FORMAT:
				asMsg = "[DL_HANDLE] jump table is not loaded yet! \nBecause its content is not a correct jump table format.";
				Synchronize(ShowMsg);
				break;
			default:
				asMsg = "[DL_HANDLE] Error: ret=0x" + IntToHex(ret, 6);
				Synchronize(ShowMsg);
				break;
			}
			break;
		case FT_RB_HANDLE_ERROR:
			switch(FTHND_RET(ret)) {
			case FTHND_LIST_IS_EMPTY:
				asMsg = "[RB_HANDLE] Readback list is empty!\n\nPlease add at least one readback entry.";
				Synchronize(ShowMsg);
				break;
			default:
				asMsg = "[RB_HANDLE] Error: ret=0x" + IntToHex(ret, 6);
				Synchronize(ShowMsg);
				break;
			}
			break;
		case FT_BROM_ERROR:
			switch(BROM_RET(ret)) {
			case BROM_CMD_START_FAIL:
				asMsg = "[BROM] Can not pass bootrom start command! Possibly target power up too early.";
				Synchronize(ShowMsg);
				break;
			case BROM_DOWNLOAD_DA_FAIL:
				asMsg = "[BROM] Fail to download DA to baseband chip's internal SRAM!\n\nPossible reasons:\n1. There's an UART communication problem between FlashTool and BootROM.\n2. Target might be shutdown unexpectedly.\n\n[ACTION]\n1. Try again.\n2. Proceed H/W checking in download cable and target side UART path.\n3. Monitor if power-drop occured in target side.";
				Synchronize(ShowMsg);
				break;
			case BROM_BBCHIP_HW_VER_INCORRECT:
				asMsg.printf("[BROM] Target baseband chip is inconsistent with %s!\n\n[ACTION]\nPlease select the suitable bin files for the target's baseband chip.", arg.p_bbchip_name);
				Synchronize(ShowMsg);
				break;
			case BROM_BBCHIP_DSP_VER_INCORRECT:
				asMsg.printf("[BROM] Target baseband chip DSP version is inconsistent with %s !!!", arg.p_bbchip_name);
				Synchronize(ShowMsg);
				break;
			case BROM_FAIL_TO_GET_BBCHIP_HW_VER:
				asMsg = "[BROM] Fail to get target baseband chip H/W version!\n\nPossible reasons:\n1. There's an UART communication problem between FlashTool and BootROM.\n2. Target might be shutdown unexpectedly.\n\n[ACTION]\n1. Try again.\n2. Proceed H/W checking in download cable and target side UART path.\n3. Monitor if power-drop occured in target side.";
				Synchronize(ShowMsg);
				break;
			case BROM_UNKNOWN_TGT_BBCHIP:
				asMsg = "[BROM] Unsupported target baseband chip type!\n\n[ACTION]\nPlease upgrade to the latest FlashTool then try again.";
				Synchronize(ShowMsg);
				break;
			case BROM_UNKNOWN_BBCHIP:
	            {
					char *p_filename=NULL;
					char path[512];
					AnsiString  filename;
					MTK_Resource	res_info;
					ROM_INFO	rom_info;
					DL_Rom_GetInfo(g_DL_HANDLE, 0, &rom_info);
					GetFullPathName(rom_info.filepath, sizeof(path), path, &p_filename);
					if( NULL!=p_filename && (strlen(rom_info.filepath)>(strlen(p_filename)+12)) ) {
						filename.printf("%.12s...\\%s", path, p_filename);
					}
					else {
						filename = rom_info.filepath;
					}
					asMsg.printf("[BROM] Unknown baseband chip type in file %s(\"%s\")!", rom_info.name, filename.c_str());
					Synchronize(ShowMsg);
	            }
				break;
			case BROM_CHKSUM16_MEM_RESULT_DIFF:
				asMsg = "[BROM] Fail to download DA to baseband chip's internal SRAM!\n\nThe internal SRAM has the problem that leads to 16 bits checksum error!";
				Synchronize(ShowMsg);
				break;
			case BROM_MULTIPLE_BAUDRATE_FAIL:
				asMsg = "[BROM] BootROM start command passed but fail to multiple BootROM baudrate!\n\nPossible reasons:\n1. There's an UART communication problem between FlashTool and BootROM.\n2. Target might be shutdown unexpectedly.\n\n[ACTION]\n1. Try again.\n2. If the problem still exists. Disable \"Options\"->\"Transmission option\"->\"Speed-Up BootROM baudrate\"\n    in advance mode (CTRL+ALT+V) then try again.\n3. Proceed H/W checking in download cable and target side UART path.\n4. Monitor if power-drop occured in target side.";
				Synchronize(ShowMsg);
				break;
			case BROM_CMD_START_TIMEOUT:
				asMsg = "[BROM] BootROM start command timeout!";
				Synchronize(ShowMsg);
				break;
			default:
				asMsg = "[BROM] Error: ret=0x" + IntToHex(ret, 6);
				Synchronize(ShowMsg);
				break;
			}
			break;
		case FT_DA_NO_RESPONSE:
			asMsg = "DA didn't send response data which FlashTool requested.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_HW_ERROR:
			SyncDisplayFlashType();
			asMsg.printf("                      <<<  H/W Detection Failure  >>>\n\n%s", m_strHWDetectionReport);
			Synchronize(ShowMsg);
			break;
		case FT_DA_SYNC_INCORRECT:
			asMsg = "DA sync fail! Possibly download an illegal DA.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_VERSION_INCORRECT:
			asMsg.printf("DA version is incorrect! DA_v%d.%d was expired, expected DA_v%d.%d.", da_report.m_da_major_ver, da_report.m_da_minor_ver, da_report.m_expected_da_major_ver, da_report.m_expected_da_minor_ver);
			Synchronize(ShowMsg);
			break;
		case FT_DA_UNKNOWN_FLASH_DEVICE:
			asMsg = "Unknown flash device!";
			Synchronize(ShowMsg);
			break;
		case FT_DA_SET_EXT_CLOCK_FAIL:
			asMsg = "DA_EXT_CLOCK_CMD command fail!";
			Synchronize(ShowMsg);
			break;
		case FT_DA_SET_BBCHIP_TYPE_FAIL:
			asMsg = "DA_BBCHIP_TYPE_CMD command fail!";
			Synchronize(ShowMsg);
			break;
		case FT_DA_CHANGE_BAUDRATE_FAIL:
        	{
				unsigned int baudrate_tbl[] = {	0, 921600, 460800, 230400, 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300, 110 };
				asMsg = "Fail to change baudrate to " + IntToStr(baudrate_tbl[com.baudrate]) + ".";
    	    }
			Synchronize(ShowMsg);
    		break;
		case FT_DA_SET_DOWNLOAD_BLOCK_FAIL:
			asMsg = "DA_MEM_CMD command fail! Possibly the following reason.\n\n 1. Download block exceeds target flash size.\n 2. Download block start address is not WORD alignment.\n 3. Download block length is not multiple of WORD.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_DOWNLOAD_FAIL:
			asMsg = "Download to flash fail! Please press CTRL+ALT+T to turn on debug log then reproduce again!\n C:\\BROM_DLL.log would be created and record more detail information.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_READBACK_FAIL:
			asMsg = "Readback from flash fail! Please press CTRL+ALT+T to turn on debug log then reproduce again!\n C:\\BROM_DLL.log would be created and record more detail information.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_FORMAT_FAIL:
			asMsg = "Format flash error! Possibly given a wrong format range, please check your format setting.";
			Synchronize(ShowMsg);
			break;
		case FT_BLOCK_UNSTABLE:
			asMsg = "Format flash error! After erase operation, block data is not entire 0xFF.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_FINISH_CMD_FAIL:
			asMsg = "DA_FINISH_CMD command fail!";
			Synchronize(ShowMsg);
			break;
		case FT_DA_SOC_CHECK_FAIL:
			asMsg = "SOC verification fail!";
			Synchronize(ShowMsg);
			break;
		case FT_DA_BBCHIP_DSP_VER_INCORRECT:
			asMsg.printf("Target baseband chip DSP version is inconsistent with %s !!!", arg.p_bbchip_name);
			Synchronize(ShowMsg);
			break;
		case FT_DA_NAND_DOWNLOAD_BLOADER_FAIL:
			asMsg.printf("Fail to download BootLoader to NAND flash!");
			Synchronize(ShowMsg);
			break;
		case FT_DA_NAND_DOWNLOAD_IMAGE_FAIL:
			asMsg.printf("Fail to download Image(s) to NAND flash!");
			Synchronize(ShowMsg);
			break;
		case FT_DA_NAND_BLOADER_NOT_EXIST:
			asMsg.printf("BootLoader doesn't exist on NAND flash, please download BootLoader first!");
			Synchronize(ShowMsg);
			break;
		case FT_BL_HANDLE_ERROR:
			switch(FTHND_RET(ret)) {
			case FTHND_FILE_IS_NOT_LOADED:
	            {
					BL_INFO		bl_info;
					DL_BL_GetInfo(g_DL_HANDLE, &bl_info);
					s1 = bl_info.m_filepath;
					asMsg = "[BL_HANDLE] BootLoader(\"" + s1 + "\") is not loaded yet!\n\nPlease load it before download.";
					Synchronize(ShowMsg);
	            }
				break;
			default:
				asMsg = "[BL_HANDLE] Error: ret=0x" + IntToHex(ret, 6);
				Synchronize(ShowMsg);
				break;
			}
			break;
		case FT_DA_INIT_SYNC_ERROR:
			asMsg.printf("Fail to send sync data to DA in initialization stage!");
			Synchronize(ShowMsg);
			break;
		case FT_NFB_NOT_SUPPORT_MBA:
			asMsg.printf("Multiple-bin download is currently unsupported for NAND-Flash-Booting(NFB) operation!");
			Synchronize(ShowMsg);
			break;
		case FT_NFB_ONLY_SUPPORT_FOR_NAND_FLASH:
			asMsg.printf("NAND-Flash-Booting(NFB) can only operate on NAND flash!");
			Synchronize(ShowMsg);
			break;
		case FT_NAND_RAW_DATA_DOWNLOAD_NOT_SUPPORT:
			asMsg.printf("Currently FlashTool doesn't support raw-data download on NAND flash!\n\nPlease select \"Options\"->\"Operation method\" to NOR or NFB for download purpose.");
			Synchronize(ShowMsg);
			break;
		case FT_DA_MEMCMD_INVALID_RANGE:
			asMsg = "DA_MEM_CMD command fail!\n\n 1. One of the download blocks has invalid range.\n 2. Possibly invalid begin address or end address exceeds target flash size.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_MEMCMD_PGM_AT_ODD_ADDR:
			asMsg = "DA_MEM_CMD command fail!\n\n 1. One of the download blocks has the ODD begin address!";
			Synchronize(ShowMsg);
			break;
		case FT_DA_MEMCMD_PGM_WITH_ODD_LENGTH:
			asMsg = "DA_MEM_CMD command fail!\n\n 1. One of the download blocks has the EVEN end address! That is download block is in ODD length.";
			Synchronize(ShowMsg);
			break;
		case FT_DA_MEMCMD_SIBLEY_PGM_AT_THE_SAME_REGIONS:
			asMsg = "DA_MEM_CMD command fail!\n\n 1. Two of the download blocks locate in the same 1KB program region on INTEL sibley flash device.\n 2. Please ensure that your scatter file leaves at least 1 KB (0x400) between consecutive bin files.";
			Synchronize(ShowMsg);
			break;
		default:
			asMsg = "Error: ret=0x" + IntToHex(ret, 6);
			Synchronize(ShowMsg);
			break;
	}
}

void __fastcall tboot_1::DebugDA()
{
	DWORD	ret;
	HANDLE  hCOM = INVALID_HANDLE_VALUE;
    com_sentry	s(hCOM, COM_PORT);

    if( INVALID_HANDLE_VALUE == hCOM ) {
		// stop timer
		Synchronize(StopTimer);
		asMsg = "Open COM" + IntToStr(COM_PORT) + "failed!";
		Synchronize(ShowMsg);
    	return;
	}

    BBCHIP_TYPE		bbchip = g_BBCHIP_TYPE;
    EXT_CLOCK		ext_clock = g_EXT_CLOCK;
    DA_INFO	da_info;
    BOOT_FLASHTOOL_ARG	boot_ft;
    DA_GetInfo(g_DA_HANDLE, &da_info);
    boot_ft.m_p_bbchip_name = NULL;
    boot_ft.m_p_bank0_mem_cfg = g_EMI_Config[0].m_bAuto?NULL:&(g_EMI_Config[0].m_Config);
    boot_ft.m_p_bank1_mem_cfg = g_EMI_Config[1].m_bAuto?NULL:&(g_EMI_Config[1].m_Config);
    boot_ft.m_da_start_addr = da_info.start_addr;
    boot_ft.m_da_buf = da_info.buf;
    boot_ft.m_da_len = da_info.buf_len;
    boot_ft.m_da_main_prog_len = da_info.main_prog_size;
    boot_ft.m_cb_download_da_init = cb_download_da_init;
    boot_ft.m_cb_download_da_init_arg = this;
    boot_ft.m_cb_download_da = cb_download_da;
    boot_ft.m_cb_download_da_arg = this;
	boot_ft.m_cb_in_brom_stage = cb_in_brom_stage;
	boot_ft.m_cb_in_brom_stage_arg = &bbchip;
    boot_ft.m_speedup_brom_baudrate = g_SpeedUpBootROMBaudrate?_TRUE:_FALSE;

    if(g_AutoDetectBBCHIP) {
    	ret = AutoBoot_FlashTool_Ex(hCOM, &bbchip, &ext_clock, &g_stopflag, BOOT_INFINITE, g_MaxBromStartCmdRetryCount, &boot_ft);
		asMsg = "AutoBoot_FlashTool(): Error: ret=0x"  + IntToHex((int)ret, 6);
    }
    else {
    	ret = Boot_FlashTool_Ex(hCOM, bbchip, ext_clock, &g_stopflag, BOOT_INFINITE, g_MaxBromStartCmdRetryCount, &boot_ft);
		asMsg = "Boot_FlashTool(): Error: ret=0x"  + IntToHex((int)ret, 6);
	}

	if( BROM_OK != ret ) {
		// stop timer
		Synchronize(StopTimer);
		if( BOOT_STOP != g_stopflag ) {
			Synchronize(ShowMsg);
		}
		return;
	}

	COMMTIMEOUTS	timeouts;

	timeouts.ReadIntervalTimeout         = 0;
	timeouts.ReadTotalTimeoutMultiplier  = 1;
	timeouts.ReadTotalTimeoutConstant    = 1000;
	timeouts.WriteTotalTimeoutMultiplier = 1;
	timeouts.WriteTotalTimeoutConstant   = 1000;

	if(!::SetCommTimeouts(hCOM, &timeouts)) {
		// stop timer
		Synchronize(StopTimer);
		ret = GetLastError();
		asMsg = "SetCommTimeouts(): Error: ret=" + IntToStr(ret);
		Synchronize(ShowMsg);
		return;
	}

	bool bIsUpToDate=false;
	m_RecvString = "";
	while( g_bDebugDA && (BOOT_STOP!=g_stopflag) ) {
		unsigned char ch;
		bool bResult;
		unsigned long readlen;

		ch = 0;
		readlen = 0;
		bResult = ReadFile( hCOM, &ch, 1, &readlen, NULL );
		if( true==bResult && 1==readlen ) {
			AnsiString  str;
			m_RecvChar = ch;
			str.printf("%c", ch);
			m_RecvString += str;
			if( 0 == (m_RecvString.Length()%1024) ) {
				Synchronize(UpdateDebugDAWindow);
				bIsUpToDate = true;
			}
			else {
				bIsUpToDate = false;
			}
    	}
    	else if(!bIsUpToDate) {
			Synchronize(UpdateDebugDAWindow);
			bIsUpToDate = true;
    	}
	}

	// stop timer
	Synchronize(StopTimer);
	return;
}
/////////////////////////////////////////////////////////////////////////


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -