1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /*===========================================================================
- Combined Charging System (CCS): SECC
- UpdateRootfs.c
- initiated by Vern, Joseph
- (since 2019/07/19)
- =============================================================================*/
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <linux/termios.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <stdlib.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/sockios.h>
- #include <linux/socket.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <math.h>//for pow
- #include "define.h"
- #include "UpdateRootfs.h"
- int main(int argc, char *argv[])
- {
- unsigned int MaxLen = 25 * 1024 * 1024, ImageLen = 0;
- unsigned char *ptr;
- int fd, wrd;
- ptr = malloc(MaxLen);
- if(ptr == NULL)
- {
- printf("UpdateRootfs NG - can not malloc\n");
- return 0;
- }
- memset(ptr, 0xFF, MaxLen);
- fd = open(argv[1], O_RDONLY);
- if(fd < 0)
- {
- printf("UpdateRootfs NG - can not open rootfs\n");
- free(ptr);
- return 0;
- }
- ImageLen = read(fd, ptr, MaxLen);
- close(fd);
- printf("ImageLen=0x%x\n", ImageLen);
- if(ImageLen < (24 * 1024 * 1024))
- {
- printf("ImageLen size mismatch\n");
- free(ptr);
- return 0;
- }
- fd = open("/dev/mtdblock8", O_RDWR);
- if(fd < 0)
- {
- printf("UpdateRootfs NG - can not open mtdblock8\n");
- free(ptr);
- return 0;
- }
- wrd = write(fd, ptr, ImageLen);
- close(fd);
- if(wrd != ImageLen)
- {
- printf("UpdateRootfs NG - wrd(0x%x) != ImageLen(0x%x)\n", wrd, ImageLen);
- free(ptr);
- return 0;
- }
- free(ptr);
- printf("UpdateRootfs OK\n");
- }
|