123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <string.h>
- #include <net/if.h> /*struct ifreq*/
- #include <linux/sockios.h> /*SIOCGIFINDEX*/
- #include <linux/socket.h>
- #include <errno.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <fcntl.h>
- #include <sys/mman.h>
- //./FWMaker 172.16.24.126
- int main(int argc,char *argv[])
- {
- unsigned char *MemBuf,*MemBuf2,buf[64];
- int fd,rd=0,wrd=0,tmp=0,rd2=0;
- unsigned int CheckSum=0;
- memset(buf,0,64);
- sprintf(buf,"tftp -gr uImage -l /mnt/uImage %s",argv[1]);
- system(buf);
- memset(buf,0,64);
- sprintf(buf,"tftp -gr rootfs_nor.img -l /mnt/rootfs_nor.img %s",argv[1]);
- system(buf);
- if((MemBuf=malloc(0x100000D))==NULL)
- {
- printf("Allocate MemBuf memory error\n");
- return 0;
- }
- memset(MemBuf, 0xff, 0x100000D);
- fd = open("/mnt/uImage", O_RDWR);
- if (fd > 0)
- {
- if((rd=read(fd,MemBuf,0x100000D))<=0)
- {
- printf("/mnt/uImage read Error\n");
- free(MemBuf);
- close(fd);
- return 0;
- }
- close(fd);
- for(tmp=0;tmp<rd;tmp++)
- CheckSum+=MemBuf[tmp];
- strncpy(MemBuf+rd,"DELTADCOK",9);
- *(MemBuf+rd+9)=CheckSum>>24;
- *(MemBuf+rd+10)=CheckSum>>16;
- *(MemBuf+rd+11)=CheckSum>>8;
- *(MemBuf+rd+12)=CheckSum;
- // memcpy(MemBuf+rd+9,&CheckSum,4);
- fd = open("/mnt/DcoKImage", O_CREAT|O_RDWR);
- wrd=write(fd, MemBuf, rd+13);
- if(wrd!=(rd+13))
- printf("write error wrd=0x%x, rd=0x%x\n",wrd,rd+13);
- else
- printf("/mnt/DcoKImage OK\n");
-
- }
- else
- {
- free(MemBuf);
- printf("/mnt/uImage open Error\n");
- return 0;
- }
-
-
- memset(MemBuf, 0xff, 0x100000D);
- CheckSum=rd=0;
- fd = open("/mnt/rootfs_nor.img", O_RDWR);
- if (fd > 0)
- {
- if((rd=read(fd,MemBuf,0x100000D))<=0)
- {
- printf("/mnt/rootfs_nor.img read Error\n");
- free(MemBuf);
- close(fd);
- return 0;
- }
- close(fd);
- for(tmp=0;tmp<rd;tmp++)
- CheckSum+=MemBuf[tmp];
- strncpy(MemBuf+rd,"DELTADCOF",9);
- *(MemBuf+rd+9)=CheckSum>>24;
- *(MemBuf+rd+10)=CheckSum>>16;
- *(MemBuf+rd+11)=CheckSum>>8;
- *(MemBuf+rd+12)=CheckSum;
- //memcpy(MemBuf+rd+9,&CheckSum,4);
- fd = open("/mnt/DcoFImage", O_CREAT|O_RDWR);
- wrd=write(fd, MemBuf, rd+13);
- if(wrd!=(rd+13))
- printf("write error wrd=0x%x, rd=0x%x\n",wrd,rd+13);
- else
- printf("/mnt/DcoFImage OK\n");
-
- }
- else
- {
- free(MemBuf);
- printf("/mnt/rootfs_nor.img open Error\n");
- return 0;
- }
-
- }
|