UpdateRootfs.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <linux/termios.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <time.h>
  8. #include <stdlib.h>
  9. #include <sys/ipc.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/sockios.h>
  13. #include <linux/socket.h>
  14. #include <sys/socket.h>
  15. #include <netinet/in.h>
  16. #include <sys/time.h>
  17. #include <sys/timeb.h>
  18. #include <math.h>//for pow
  19. #include "../../define.h"
  20. int main(int argc,char *argv[])
  21. {
  22. unsigned int MaxLen=25*1024*1024, ImageLen=0;
  23. unsigned char *ptr;
  24. int fd,wrd;
  25. ptr=malloc(MaxLen);
  26. if(ptr==NULL)
  27. {
  28. printf("UpdateRootfs NG - can not malloc\n");
  29. return 0;
  30. }
  31. memset(ptr,0xFF,MaxLen);
  32. fd = open(argv[1], O_RDONLY);
  33. if(fd < 0)
  34. {
  35. printf("UpdateRootfs NG - can not open rootfs\n");
  36. free(ptr);
  37. return 0;
  38. }
  39. ImageLen=read(fd,ptr,MaxLen);
  40. close(fd);
  41. printf("ImageLen=0x%x\n",ImageLen);
  42. if(ImageLen<(24*1024*1024))
  43. {
  44. printf("ImageLen size mismatch\n");
  45. free(ptr);
  46. return 0;
  47. }
  48. fd = open("/dev/mtdblock8", O_RDWR);
  49. if (fd < 0)
  50. {
  51. printf("UpdateRootfs NG - can not open mtdblock8\n");
  52. free(ptr);
  53. return 0;
  54. }
  55. wrd=write(fd, ptr, ImageLen);
  56. close(fd);
  57. if(wrd!=ImageLen)
  58. {
  59. printf("UpdateRootfs NG - wrd(0x%x) != ImageLen(0x%x)\n",wrd,ImageLen);
  60. free(ptr);
  61. return 0;
  62. }
  63. free(ptr);
  64. printf("UpdateRootfs OK\n");
  65. }