UpdateRootfs.c 1.9 KB

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