资源简介
linux下利用dnw烧写文件(通过fedora9,fedora14使用测试),100%可以使用
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
const char* dev = “/dev/secbulk0“;
int main(int argc char* argv[])
{
unsigned char* file_buffer = NULL;
if( 2 != argc )
{
printf(“Usage: dwn \n“);
return 1;
}
int fd = open(argv[1] O_RDONLY);
if(-1 == fd)
{
printf(“Can not open file - %s\n“ argv[1]);
return 1;
}
struct stat file_stat;
if( -1 == fstat(fd &file_stat) )
{
printf(“Get file size filed!\n“);
return 1;
}
file_buffer = (char*)malloc(file_stat.st_size+10);
if(NULL == file_buffer)
{
printf(“malloc failed!\n“);
goto error;
}
if( file_stat.st_size != read(fd file_buffer+8 file_stat.st_size))
{
printf(“Read file failed!\n“);
goto error;
}
printf(“file name : %s\n“ argv[1]);
printf(“file size : %d bytes\n“ file_stat.st_size);
int fd_dev = open(dev O_WRONLY);
if( -1 == fd_dev)
{
printf(“Can not open %s\n“ dev);
goto error;
}
*((unsigned long*)file_buffer) = 0x32000000; //load address
*((unsigned long*)file_buffer+1) = file_stat.st_size+10; //file size
unsigned short sum = 0;
int i;
for(i=8; i {
sum += file_buffer[i];
}
printf(“Writing data...\n“);
size_t remain_size = file_stat.st_size+10;
size_t block_size = remain_size / 100;
size_t writed = 0;
while(remain_size>0)
{
size_t to_write = remain_size > block_size ? block_size:remain_size;
if( to_write != write(fd_dev file_buffer+writed to_write))
{
printf(“failed!\n“);
return 1;
}
remain_size -= to_write;
writed += to_write;
printf(“\r%d%\t %d bytes “ writed*100/(file_stat.st_size+10) writed);
fflush(stdout);
}
printf(“OK\n“);
return 0;
error:
if(-1!=fd_dev) close(fd_dev);
if(fd != -1) close(fd);
if( NULL!=file_buffer )
free(file_buffer);
return -1;
}
- 上一篇:2020年中国互联网医疗年度分析
- 下一篇:ArcGIS景观分析插件
相关资源
- Micrium.RTOS.1.0.0.pack
- uboot到linux logo显示不间断 补丁
- ISE_14.7_license.lic
- stm32f103c8t6 4 oled.rar
- mpu6050+hmc5883L.rar
- UNIX/LINUX编程实践教程的源码
- 嵌入式图形界面MiniGUI的示例程序9例
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- ARM嵌入式项目实战
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- uCOS编译环境建立 BC45 TASM
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- stm32 用SPI 方式读写 SDHC
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
评论
共有 条评论