FWMaker.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <arpa/inet.h>
  6. #include <string.h>
  7. #include <net/if.h> /*struct ifreq*/
  8. #include <linux/sockios.h> /*SIOCGIFINDEX*/
  9. #include <linux/socket.h>
  10. #include <errno.h>
  11. #include <sys/time.h>
  12. #include <sys/timeb.h>
  13. #include <fcntl.h>
  14. #include <sys/mman.h>
  15. //./FWMaker 172.16.24.126
  16. int main(int argc,char *argv[])
  17. {
  18. unsigned char *MemBuf,*MemBuf2,buf[64];
  19. int fd,rd=0,wrd=0,tmp=0,rd2=0;
  20. unsigned int CheckSum=0;
  21. memset(buf,0,64);
  22. sprintf(buf,"tftp -gr uImage -l /mnt/uImage %s",argv[1]);
  23. system(buf);
  24. memset(buf,0,64);
  25. sprintf(buf,"tftp -gr rootfs_nor.img -l /mnt/rootfs_nor.img %s",argv[1]);
  26. system(buf);
  27. if((MemBuf=malloc(0x100000D))==NULL)
  28. {
  29. printf("Allocate MemBuf memory error\n");
  30. return 0;
  31. }
  32. memset(MemBuf, 0xff, 0x100000D);
  33. fd = open("/mnt/uImage", O_RDWR);
  34. if (fd > 0)
  35. {
  36. if((rd=read(fd,MemBuf,0x100000D))<=0)
  37. {
  38. printf("/mnt/uImage read Error\n");
  39. free(MemBuf);
  40. close(fd);
  41. return 0;
  42. }
  43. close(fd);
  44. for(tmp=0;tmp<rd;tmp++)
  45. CheckSum+=MemBuf[tmp];
  46. strncpy(MemBuf+rd,"DELTADCOK",9);
  47. *(MemBuf+rd+9)=CheckSum>>24;
  48. *(MemBuf+rd+10)=CheckSum>>16;
  49. *(MemBuf+rd+11)=CheckSum>>8;
  50. *(MemBuf+rd+12)=CheckSum;
  51. // memcpy(MemBuf+rd+9,&CheckSum,4);
  52. fd = open("/mnt/DcoKImage", O_CREAT|O_RDWR);
  53. wrd=write(fd, MemBuf, rd+13);
  54. if(wrd!=(rd+13))
  55. printf("write error wrd=0x%x, rd=0x%x\n",wrd,rd+13);
  56. else
  57. printf("/mnt/DcoKImage OK\n");
  58. }
  59. else
  60. {
  61. free(MemBuf);
  62. printf("/mnt/uImage open Error\n");
  63. return 0;
  64. }
  65. memset(MemBuf, 0xff, 0x100000D);
  66. CheckSum=rd=0;
  67. fd = open("/mnt/rootfs_nor.img", O_RDWR);
  68. if (fd > 0)
  69. {
  70. if((rd=read(fd,MemBuf,0x100000D))<=0)
  71. {
  72. printf("/mnt/rootfs_nor.img read Error\n");
  73. free(MemBuf);
  74. close(fd);
  75. return 0;
  76. }
  77. close(fd);
  78. for(tmp=0;tmp<rd;tmp++)
  79. CheckSum+=MemBuf[tmp];
  80. strncpy(MemBuf+rd,"DELTADCOF",9);
  81. *(MemBuf+rd+9)=CheckSum>>24;
  82. *(MemBuf+rd+10)=CheckSum>>16;
  83. *(MemBuf+rd+11)=CheckSum>>8;
  84. *(MemBuf+rd+12)=CheckSum;
  85. //memcpy(MemBuf+rd+9,&CheckSum,4);
  86. fd = open("/mnt/DcoFImage", O_CREAT|O_RDWR);
  87. wrd=write(fd, MemBuf, rd+13);
  88. if(wrd!=(rd+13))
  89. printf("write error wrd=0x%x, rd=0x%x\n",wrd,rd+13);
  90. else
  91. printf("/mnt/DcoFImage OK\n");
  92. }
  93. else
  94. {
  95. free(MemBuf);
  96. printf("/mnt/rootfs_nor.img open Error\n");
  97. return 0;
  98. }
  99. }