📄 out.c
字号:
OutInit();
StroeBlock = CreateOut;
TftpStart( argv[1], argv[2] ); /* 启动TFTP */
while(! NetState )
{
len = tftp_read();
if( len > 0 )
{
TftpHandler( len );
}
if( timeHandler && ( cticks - timeStart > timeDelta ))
timeHandler();
}
/* 停止tftp */
TftpStop();
if( out_stat != STAT_END )
{
channel_printf( "load fail!\r\n" );
return 1;
}
channel_printf( "zipping ...\r\n" );
/* 计数烧写到flash中的地址,并且对.text段进行压缩 */
for( i = 0; i < OutInfo.OutHead.num_sections; i ++ )
{
if( (( OutInfo.psection[i].sectionhead.virtual_addr >= CFG_FLASH_BASE )
&& OutInfo.psection[i].sectionhead.sizes ) ||
( i == DEBUG_INFO_INDEX ) ||
( i == DEBUG_ABBR_INDEX ))
{
if( OutInfo.psection[i].sectionhead.name != 0 &&
strcmp(( char *)OutInfo.psection[i].sectionhead.name, ".text" ) == 0 )
{
idx_text = i;
/* 分配text节大小数据空间 */
zip_out_ptr = ( char *)malloc( OutInfo.psection[i].raw_bytes_recved );
if( zip_out_ptr == 0 )
{
/* 如果没有足够空间分配 */
channel_printf( "no memory malloc %s: %d\r\n", __FILE__, __LINE__ );
return 1; /* 返回失败代码 */
}
/* 压缩TEXT */
OutInfo.psection[i].raw_bytes_recved = zipmem( ( char *)OutInfo.psection[i].prawdata,
OutInfo.psection[i].raw_bytes_recved, zip_out_ptr );
free( OutInfo.psection[i].prawdata ); /* 释放压缩前内存空间 */
high_addr = OutInfo.psection[i].sectionhead.virtual_addr + OutInfo.psection[i].raw_bytes_recved;
/* 申请解压后的空间 */
OutInfo.psection[i].prawdata = ( unsigned char *)malloc( OutInfo.psection[i].raw_bytes_recved );
if( OutInfo.psection[i].prawdata == 0 )
{
/* 如果没有足够空间分配 */
channel_printf( "no memory malloc %s: %d\r\n", __FILE__, __LINE__ );
return 1; /* 返回失败代码 */
}
memcpy( OutInfo.psection[i].prawdata, zip_out_ptr, OutInfo.psection[i].raw_bytes_recved );
free( zip_out_ptr ); /* 释放空间 */
}
if( i != DEBUG_ABBR_INDEX && i != DEBUG_INFO_INDEX )
if( low_addr > OutInfo.psection[i].sectionhead.virtual_addr )
low_addr = OutInfo.psection[i].sectionhead.virtual_addr;
OutInfo.psection[i].flag = 1;
}
else
{
if( OutInfo.psection[i].sectionhead.name != 0 &&
strcmp(( char *)OutInfo.psection[i].sectionhead.name, ".far" ) == 0 )
{
/* 查找far节 */
idx_far = i;
}
else if( OutInfo.psection[i].sectionhead.name != 0 &&
strcmp(( char *)OutInfo.psection[i].sectionhead.name, ".bss" ) == 0 )
{
/* 查找bss节 */
idx_bss = i;
}
if( OutInfo.psection[i].prawdata )
{
free( OutInfo.psection[i].prawdata );
OutInfo.psection[i].prawdata = 0;
}
}
}
/* 再次轮询全部节点,确定debug_info与debug_abbre节的烧写地址 */
for( i = 0; i < OutInfo.OutHead.num_sections; i ++ )
{
if( i == DEBUG_INFO_INDEX || i == DEBUG_ABBR_INDEX )
{
high_addr = ( high_addr + 3 ) & ~ 0x03; /* 确认为4字节对齐 */
zip_out_ptr = ( char *)malloc( OutInfo.psection[i].raw_bytes_recved );
if( zip_out_ptr == 0 )
{
/* 如果没有足够空间分配 */
channel_printf( "no memory malloc %s: %d\r\n", __FILE__, __LINE__ );
return 1; /* 返回失败代码 */
}
OutInfo.psection[i].raw_bytes_recved = zipmem( ( char *)OutInfo.psection[i].prawdata,
OutInfo.psection[i].raw_bytes_recved, zip_out_ptr );
#ifdef OS_WINDOWS
if( i == DEBUG_INFO_INDEX )
ptr_info = OutInfo.psection[i].prawdata;
else
ptr_abbrev = OutInfo.psection[i].prawdata;
#else
free( OutInfo.psection[i].prawdata ); /* 释放压缩前内存空间 */
#endif
/* 申请解压后的空间 */
OutInfo.psection[i].prawdata = ( unsigned char *)malloc( OutInfo.psection[i].raw_bytes_recved );
if( OutInfo.psection[i].prawdata == 0 )
{
/* 如果没有足够空间分配 */
channel_printf( "no memory malloc %s: %d\r\n", __FILE__, __LINE__ );
return 1; /* 返回失败代码 */
}
memcpy( OutInfo.psection[i].prawdata, zip_out_ptr, OutInfo.psection[i].raw_bytes_recved );
free( zip_out_ptr );
/* 烧写flash的高地址 */
OutInfo.psection[i].sectionhead.virtual_addr = high_addr;
high_addr = OutInfo.psection[i].sectionhead.virtual_addr + OutInfo.psection[i].raw_bytes_recved;
}
}
adjust_addr(& low_addr,& high_addr ); /* 调整扇区烧写范围 */
channel_printf( "low addr = 0x%08x, high addr = 0x%08x\r\n", low_addr, high_addr );
#ifndef OS_WINDOWS
channel_printf( "eraseing ...\r\n" );
flash_sect_erase( low_addr, high_addr );
channel_printf( "flashing ...\r\n" );
for( i = 0; i < OutInfo.OutHead.num_sections; i ++ )
{
if( OutInfo.psection[i].flag )
{
unsigned int size;
if( OutInfo.psection[i].sectionhead.virtual_addr == CFG_FLASH_BASE )
{
/* 找到启动扇区 */
*( unsigned int *)& OutInfo.psection[i].prawdata[DEBUG_INFO_ADDR] =
OutInfo.psection[DEBUG_INFO_INDEX].sectionhead.virtual_addr;
*( unsigned int *)& OutInfo.psection[i].prawdata[DEBUG_INFO_LEN] =
OutInfo.psection[DEBUG_INFO_INDEX].raw_bytes_recved;
*( unsigned int *)& OutInfo.psection[i].prawdata[DEBUG_ABBR_ADDR] =
OutInfo.psection[DEBUG_ABBR_INDEX].sectionhead.virtual_addr;;
*( unsigned int *)& OutInfo.psection[i].prawdata[DEBUG_ABBR_LEN] =
OutInfo.psection[DEBUG_ABBR_INDEX].raw_bytes_recved;
*( unsigned int *)& OutInfo.psection[i].prawdata[TEXT_LOAD_ADDR] =
OutInfo.psection[idx_text].sectionhead.virtual_addr;;
*( unsigned int *)& OutInfo.psection[i].prawdata[TEXT_LOAD_LEN] =
OutInfo.psection[idx_text].raw_bytes_recved;
*( unsigned int *)& OutInfo.psection[i].prawdata[TEXT_RUN_ADDR] =
OutInfo.psection[idx_text].sectionhead.physcial_addr;
*( unsigned int *)& OutInfo.psection[i].prawdata[TEXT_RUN_LEN] =
OutInfo.psection[idx_text].sectionhead.sizes;
*( unsigned int *)& OutInfo.psection[i].prawdata[FAR_RUN_ADDR] =
OutInfo.psection[idx_far].sectionhead.physcial_addr;
*( unsigned int *)& OutInfo.psection[i].prawdata[FAR_RUN_LEN] =
OutInfo.psection[idx_far].sectionhead.sizes;
*( unsigned int *)& OutInfo.psection[i].prawdata[BSS_RUN_ADDR] =
OutInfo.psection[idx_bss].sectionhead.physcial_addr;
*( unsigned int *)& OutInfo.psection[i].prawdata[BSS_RUN_LEN] =
OutInfo.psection[idx_bss].sectionhead.sizes;
/* 保存压缩前DEBUG_INFO 长度 */
*( unsigned int *)& OutInfo.psection[i].prawdata[DEBUG_INFO_UNZIPLEN] =
OutInfo.psection[DEBUG_INFO_INDEX].sectionhead.sizes;
/* 保存压缩前DEBUG_ABBRV长度 */
*( unsigned int *)& OutInfo.psection[i].prawdata[DEBUG_ABBR_UNZIPLEN] =
OutInfo.psection[DEBUG_ABBR_INDEX].sectionhead.sizes;
size = BOOTRAM_LEN; /* 烧写启动长度 */
}
else
size = OutInfo.psection[i].raw_bytes_recved;
flash_write(( unsigned char * )OutInfo.psection[i].prawdata,
OutInfo.psection[i].sectionhead.virtual_addr, size );
}
}
channel_printf( ".done\r\n" );
#else
/* 解压到原来的位置 */
old_info_len = unzipmem( OutInfo.psection[DEBUG_INFO_INDEX].prawdata,
OutInfo.psection[DEBUG_INFO_INDEX].raw_bytes_recved, ptr_info );
/* 解压到原来的位置 */
old_abbrev_len = unzipmem( OutInfo.psection[DEBUG_ABBR_INDEX].prawdata,
OutInfo.psection[DEBUG_ABBR_INDEX].raw_bytes_recved, ptr_abbrev );
dwarf2_init( ptr_info, old_info_len, ptr_abbrev, old_abbrev_len );
dwarf2_build_symtabs();
free( ptr_info );
free( ptr_abbrev );
#endif
FreeOut();
return 0;
}
int do_reset( struct cmd_tbl_s * cmdtp, int flag, int argc, char * argv[] )
{
go exe;
char * src,* dst;
disable_interrupt( );
dst = ( char *)0; /* 目的地址 */
src = ( char *)CFG_FLASH_BASE; /* 源地址 */
/* 手动拷贝到0地址 */
memcpy( dst, src, BOOTRAM_LEN );
exe = ( go )0;
exe();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -