📄 burn.cpp.svn-base
字号:
return true;
}
bool BurnFlash::format_transc()
{
BYTE data[512];
bool ret = construct_zone_detail();
if(!ret)
return ret;
information.TotalLen = config.res_blocks;
int byte_index = 0;
//use total_len to pass reserve block number, as it is not used yet
memcpy(data + byte_index, &information.TotalLen, sizeof(information.TotalLen));
byte_index += sizeof(information.TotalLen);
memcpy(data + byte_index, &information.BootBlock, sizeof(information.BootBlock));
byte_index += sizeof(information.BootBlock);
memcpy(data + byte_index, &information.Zone_Cnt, sizeof(information.Zone_Cnt));
byte_index += sizeof(information.Zone_Cnt);
memcpy(data + byte_index , information.Zone_Group, sizeof(T_ZONE_DATAIL) * information.Zone_Cnt);
byte_index += sizeof(T_ZONE_DATAIL) * information.Zone_Cnt;
/*
memcpy(data, &information, sizeof(T_INFOMATION));
memcpy(data + sizeof(T_INFOMATION), information.Zone_Group,
information.Zone_Cnt * sizeof(T_ZONE_DATAIL));
*/
if( !write_transc_packet(FORMAT_TRANSC, 512, data) )
return false;
Sleep(2000);
ret = read_transc_ack();
if(ret != ACK_SUCCESS)
return false;
return true;
}
bool BurnFlash::fat_transc()
{
T_FAT_DATA fat_data;
HANDLE hFile = NULL;
DWORD dwSize = 0, read_len = 0;
BYTE file_data[MAX_PACKET_LENGTH];
UINT usb_write_len = 0;
for(int i = 0; i< config.download_fat_image_count; i++)
{
fat_data.Disk_Name = config.images[i].Disk_Name;
hFile = CreateFile(ConverPathToAbsolute(config.images[i].file_pc_path) , GENERIC_READ , FILE_SHARE_READ , NULL ,
OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return false;
}
dwSize = GetFileSize (hFile, NULL) ;
if (dwSize == 0xFFFFFFFF)
{
CloseHandle(hFile);
return false;
}
fat_data.image_file_size = dwSize;
if(!write_transc_packet(FAT_TRANS, sizeof(T_FAT_DATA), (BYTE *)&fat_data))
{
CloseHandle(hFile);
return false;
}
if( read_transc_ack() != ACK_SUCCESS)
return false;
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_DOWNLOADING_FAT_IMAGE) );
UINT length = 0;
while(1)
{
BOOL bResult = ReadFile(hFile , file_data , MAX_PACKET_LENGTH , &read_len , NULL);
if(!bResult)
{
CloseHandle(hFile);
return false;
}
int write_len = read_len;
if(write_len % MIN_PACKET_LENGTH != 0)
write_len = read_len + (MIN_PACKET_LENGTH - read_len % MIN_PACKET_LENGTH);
if( read_len > 0 && !m_usb.M3USB_DOWNLOAD(file_data, write_len, &usb_write_len))
{
CloseHandle(hFile);
return false;
}
download_file_len += read_len;
length += read_len;
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_DOWNLOAD_FILE_LEN) );
if(length > (config.images[i].File_Size + FAT_IMAGE_SAFE_SIZE))//last packet
{
CloseHandle(hFile);
if( !m_usb.M3USB_DOWNLOAD(end_pad, MIN_PACKET_LENGTH, &usb_write_len))
return false;
Sleep(200);
if( read_transc_ack() != ACK_SUCCESS)
return false;
break;
}
}
}
return true;
}
bool BurnFlash::download_config_data(T_WRITE_DATA_DATA *write_data, BYTE *data, int data_len)
{
UINT usb_write_len = 0;
if(data == NULL || data_len == 0)
return FALSE;
if(!write_transc_packet(WRITE_DATA_TRANSC, sizeof(T_WRITE_DATA_DATA), (BYTE *)write_data))
{
return false;
}
if( read_transc_ack() != ACK_SUCCESS)
return false;
if(!m_usb.M3USB_DOWNLOAD(data, MIN_PACKET_LENGTH, &usb_write_len))
{
return false;
}
if(!m_usb.M3USB_DOWNLOAD(end_pad, MIN_PACKET_LENGTH, &usb_write_len))
return false;
Sleep(2000);
if( read_transc_ack() != ACK_SUCCESS)
return false;
return true;
}
bool BurnFlash::download_BIOS_config(int bios_size)
{
T_NAND_CONFIG nand_config;
T_WRITE_DATA_DATA write_data;
write_data.Start_Address = CONFIG_ADDR;
write_data.End_Address = CONFIG_ADDR + sizeof(T_NAND_CONFIG);
write_data.Backup_Start_Address = 0;
write_data.Backup_End_Address = 0;
write_data.Data_Length = sizeof(T_NAND_CONFIG);
write_data.Backup_Map_Address = 0;
write_data.Download_Type = DOWNLOAD_TO_NANDFLASH;
nand_config.MainVer = config.bios_main_version;
nand_config.SubVer = config.bios_sub_version;
nand_config.Sub1Ver = config.bios_sub1_version;
nand_config.Length = sizeof(T_NAND_CONFIG);
if(config.bios_backup_start_address != 0 &&
config.bios_backup_end_address != 0)
nand_config.MapStart = CONFIG_ADDR + 0x0200;
else
nand_config.MapStart = 0;
nand_config.FileStart = config.bios_start_address;
nand_config.FileLen = bios_size;
nand_config.FileLdStart = (UINT32*)config.bios_run_address;
nand_config.FileEnd = config.bios_end_address;
nand_config.CheckBIOSSum = 0;
nand_config.CheckStructSum = (UCHAR)checksum((UCHAR *)&nand_config, sizeof(T_NAND_CONFIG) - 1);
return download_config_data(&write_data, (BYTE *)&nand_config, sizeof(T_NAND_CONFIG));
}
bool BurnFlash::download_data(char *file_path)
{
DWORD read_len = 0;
UINT usb_write_len = 0;
HANDLE hFile = NULL;
bool bDownloadNandBoot = false;
bool bfirst = true;
BYTE file_data[MAX_PACKET_LENGTH];
char buf[256];
if(file_path == NULL)
return false;
if(strcmp(file_path, config.nandboot_path) == 0)
bDownloadNandBoot = true;
hFile = CreateFile(ConverPathToAbsolute(file_path) , GENERIC_READ , FILE_SHARE_READ , NULL ,
OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return false;
}
sprintf(buf, "[PC PRINT]: %s\r\n", file_path);
record_write(buf, strlen(buf), get_id()+config.base_com);
while(1)
{
BOOL bResult = ReadFile(hFile , file_data , MAX_PACKET_LENGTH , &read_len , NULL);
if(!bResult)
{
CloseHandle(hFile);
sprintf(buf, "[PC PRINT]: ReadFile Error\r\n");
record_write(buf, strlen(buf), get_id()+config.base_com);
return false;
}
if(bDownloadNandBoot && bfirst)
{
config_nandboot_parameter(file_data, config, chip_para.nandflash_parameter);
bfirst = false;
}
int write_len = read_len;
if(write_len % MIN_PACKET_LENGTH != 0)
write_len = read_len + (MIN_PACKET_LENGTH - read_len % MIN_PACKET_LENGTH);
if( read_len > 0 && !m_usb.M3USB_DOWNLOAD(file_data, write_len, &usb_write_len))
{
CloseHandle(hFile);
sprintf(buf, "[PC PRINT]: Download Data Error\r\n");
record_write(buf, strlen(buf), get_id()+config.base_com);
return false;
}
download_file_len += read_len;
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_DOWNLOAD_FILE_LEN) );
if(read_len < MAX_PACKET_LENGTH)//last packet
{
CloseHandle(hFile);
if( !m_usb.M3USB_DOWNLOAD(end_pad, MIN_PACKET_LENGTH, &usb_write_len))
{
sprintf(buf, "[PC PRINT]: Download Last Data Error\r\n");
record_write(buf, strlen(buf), get_id()+config.base_com);
return false;
}
Sleep(200);
if( read_transc_ack() != ACK_SUCCESS)
{
sprintf(buf, "[PC PRINT]: Download Error\r\n");
record_write(buf, strlen(buf), get_id()+config.base_com);
return false;
}
break;
}
}
return true;
}
bool BurnFlash::download_data_transc(download_file *download_files, int count )
{
T_WRITE_DATA_DATA write_data;
DWORD dwSize = 0, read_len = 0;
UINT usb_write_len = 0;
HANDLE hFile = NULL;
for(int i = 0; i< count; i++)
{
hFile = CreateFile(ConverPathToAbsolute(download_files[i].file_pc_path) , GENERIC_READ , FILE_SHARE_READ , NULL ,
OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return false;
}
dwSize = GetFileSize (hFile, NULL) ;
if (dwSize == 0xFFFFFFFF)
{
CloseHandle(hFile);
return false;
}
CloseHandle(hFile);
if(download_files[i].download_type == DOWNLOAD_TO_NANDFLASH)
{
T_DATA_CONFIG data_config;
if(map_index == 0)
map_index++;
data_config.FileStart = download_files[i].start_destination_address;
data_config.FileEnd = download_files[i].end_destination_address;
data_config.FileLen = dwSize;
data_config.FileLdStart = download_files[i].file_run_address;
if(download_files[i].backup_end_destination_address != 0 &&
download_files[i].backup_start_destination_address != 0)
{
data_config.MapStart = CONFIG_ADDR + 0x0200 + map_len * 512;
map_len += ((download_files[i].end_destination_address -
download_files[i].start_destination_address)
/ (chip_para.nandflash_parameter.page_per_blk
* chip_para.nandflash_parameter.page_size)
* sizeof(T_U16) + 511) / 512;
}
else
data_config.MapStart = 0;
if(config.bNandBoot)
{
write_data.Start_Address = CONFIG_ADDR +
sizeof(T_NAND_CONFIG) + (map_index - 2) * sizeof(T_DATA_CONFIG);
write_data.End_Address = CONFIG_ADDR +
sizeof(T_NAND_CONFIG) + (map_index - 1) * sizeof(T_DATA_CONFIG);
}
else
{
write_data.Start_Address = CONFIG_ADDR +
(map_index) * sizeof(T_DATA_CONFIG);
write_data.End_Address = CONFIG_ADDR +
(map_index + 1) * sizeof(T_DATA_CONFIG);
}
write_data.Backup_Start_Address = 0;
write_data.Backup_End_Address = 0;
write_data.Data_Length = sizeof(T_DATA_CONFIG);
write_data.Backup_Map_Address = 0;
write_data.Download_Type = DOWNLOAD_TO_NANDFLASH;
if( !download_config_data(&write_data, (BYTE *)&data_config, sizeof(T_DATA_CONFIG)))
return FALSE;
write_data.map_index = map_index++;
write_data.Backup_Map_Address = data_config.MapStart;
}
write_data.Download_Type = download_files[i].download_type;
write_data.Start_Address = download_files[i].start_destination_address;
write_data.End_Address = download_files[i].end_destination_address;
write_data.Backup_Start_Address = download_files[i].backup_start_destination_address;
write_data.Backup_End_Address = download_files[i].backup_end_destination_address;
write_data.Data_Length = dwSize;
if(!write_transc_packet(WRITE_DATA_TRANSC, sizeof(T_WRITE_DATA_DATA), (BYTE *)&write_data))
{
CloseHandle(hFile);
return false;
}
if( read_transc_ack() != ACK_SUCCESS)
return false;
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_DOWNLOADING_FILE) );
if(download_data(download_files[i].file_pc_path))
{
if(download_files[i].compare)
{
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_COMPARE_FILE) );
if(!compare_transc(download_files[i].file_pc_path))
{
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_COMPARE_FILE_FAIL) );
return false;
}
PostMessage(get_wnd(), ON_BURNFLASH_MESSAGE, WPARAM(get_id()+100), LPARAM(MESSAGE_COMPARE_FILE_SUCCESS) );
}
}
else
return false;
}
return true;
}
bool BurnFlash::download_file_use_usb(char *pc_path, int loadfile_destination_address)
{
HANDLE hFile;
BYTE file_data[MAX_PACKET_LENGTH];
DWORD read_len = 0;
UINT usb_write_len = 0;
if(pc_path == NULL)
return false;
if(!command_download_usb(pc_path, loadfile_destination_address, m_usb))
{
return false;
}
hFile = CreateFile(ConverPathToAbsolute(pc_path), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
return false;
}
while(1)
{
BOOL bResult = ReadFile(hFile , file_data , MAX_PACKET_LENGTH , &read_len , NULL);
if(!bResult)
{
CloseHandle(hFile);
return false;
}
int write_len = read_len;
if(write_len % MIN_PACKET_LENGTH != 0)
write_len = read_len + (MIN_PACKET_LENGTH - read_len % MIN_PACKET_LENGTH);
if( read_len > 0 && !m_usb.M3USB_DOWNLOAD(file_data, write_len, &usb_write_len))
{
CloseHandle(hFile);
return false;
}
download_file_len += read_len;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -