]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/slutils/slutils-0.1.0/sltime/sltime.c
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / slutils / slutils-0.1.0 / sltime / sltime.c
1 /*
2    sltime utility replacement for Sharp Zaurus SL-C7x0/860
3    version 1.0
4    Copyright 2004 Alexander Chukov <sash@cacko.biz>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <time.h>
25 #include <string.h>
26
27 #define CONFIG_MTD_NAND_LOGICAL_ADDRESS_ACCESS
28 #include "mtduser.h"
29
30 #define APM_IOC_SETRTC 0x4146
31 #define APM_IOC_GETRTC 0x4147
32
33 static int open_mtd(void)
34 {
35         int fd;
36         mtd_info_t meminfo;
37
38         /* Open the device */
39         if((fd = open("/dev/mtd1", O_RDWR)) == -1) {
40                 perror("open flash");
41                 exit(1);
42         }
43
44         /* Fill in MTD device capability structure */  
45         if(ioctl(fd, MEMGETINFO, &meminfo) != 0) {
46                 perror("MEMGETINFO");
47                 close(fd);
48                 exit(1);
49         }
50
51         /* Make sure device page sizes are valid */
52         if( !(meminfo.oobsize == 16 && meminfo.oobblock == 512) &&
53                 !(meminfo.oobsize == 8 && meminfo.oobblock == 256) ) {
54                 printf("Unknown flash (not normal NAND)\n");
55                 close(fd);
56                 exit(1);
57         }
58
59         return fd;
60 }
61
62 int main(int argc, char *argv[])
63 {
64         int fd, mfd;
65         struct timeval tv;
66         unsigned int setime;
67         struct read_laddr_info_user rinfo = {0x4C004, 4, (unsigned char *) &setime};
68         
69         if (argc < 2) {
70             mfd = open_mtd();
71             if (ioctl(mfd, MEMREADLADDR, &rinfo) != 0) {
72                 perror("ioctl(MEMREADLADDR)");
73                 close(mfd);
74                 exit(1);
75             }
76             close(mfd);
77             fd = open("/dev/apm_bios", O_RDWR);
78             //setime += ioctl(fd, APM_IOC_GETRTC, 0);
79             ioctl(fd, APM_IOC_SETRTC, &setime);
80             tv.tv_usec = 0;
81             tv.tv_sec = setime;
82             settimeofday(&tv, 0);
83             close(fd);
84         } else if (strcmp(argv[1], "-clear") == 0) {
85             fd = open("/dev/apm_bios", O_RDWR);
86             tv.tv_usec = 0;
87             tv.tv_sec  = 1075658510;
88             settimeofday(&tv, 0);
89             setime = tv.tv_sec;
90             ioctl(fd, APM_IOC_SETRTC, (void*)&setime);
91             close(fd);
92         } else if (strcmp(argv[1], "-set") == 0) {
93             gettimeofday(&tv, 0);
94             setime = tv.tv_sec;
95             mfd = open_mtd();
96             if (ioctl(mfd, MEMWRITELADDR, &rinfo) != 0) {
97                 perror("ioctl(MEMWRITELADDR)");
98                 close(mfd);
99                 exit(1);
100             }
101             close(mfd);
102         } else {
103             fprintf(stderr, "Usage:\n%s [-set|-clear]\n", argv[0]);
104             exit(1);
105         }
106         return 0;
107 }
108