ARM-Linux驱动移植--Linux下烧写工具DNW和USB驱动安装

主机平台:Gentoo Linux 11.2 with linux kernel 3.0.6

硬件平台:FL2440(S3C2440)with linux kernel 2.6.35

原创作品,转载请标明出处http://blog.csdn.net/yming0221/article/details/7211396

1、首先下载DNW for linuxhttp://download.csdn.net/source/1011140

2、解压文件


3、编译主机的USB驱动

make -C /lib/modules/`uname -r`/build M=`pwd` modules
然后insmod安装驱动并dmesg查看如下


4、修改dnw.c文件并编译

由于FL2440烧写内核需要设置初始地址为0x30800000,修改后文件如下

#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> const char* dev = "/dev/secbulk0"; int main(int argc, char* argv[]) { unsigned char* file_buffer = NULL; if( 2 != argc ) { printf("Usage: dwn <filename>\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) = 0x30800000; //load address *((unsigned long*)file_buffer+1) = file_stat.st_size+10; //file size unsigned short sum = 0; int i; for(i=8; i<file_stat.st_size+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 block_size = 512; 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; }
最后烧写内核





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值