summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2010-01-21 11:57:01 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2010-01-21 11:57:01 +0000
commit3e89296d6a3ecbcd430d3569fdc28a355ac36a0d (patch)
tree46eab846c10d0a5121e7ff5d834a9a9d01e67f42
parent0061234579833576f6d00a7fc8f0b94d3f0f64ed (diff)
downloadrockbox-3e89296d6a3ecbcd430d3569fdc28a355ac36a0d.tar.gz
rockbox-3e89296d6a3ecbcd430d3569fdc28a355ac36a0d.zip
Import ipod-time-sync from libgpod
This copies ipod-time-sync from libgpod and strips it of unneccesary code + Makefile and README are added. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24306 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/time-sync/Makefile17
-rw-r--r--utils/time-sync/README20
-rw-r--r--utils/time-sync/ipod-scsi.c100
-rw-r--r--utils/time-sync/time-sync.c41
4 files changed, 178 insertions, 0 deletions
diff --git a/utils/time-sync/Makefile b/utils/time-sync/Makefile
new file mode 100644
index 0000000000..d58ad3b357
--- /dev/null
+++ b/utils/time-sync/Makefile
@@ -0,0 +1,17 @@
1CFLAGS = -Wall
2SRCS = ipod-scsi.c time-sync.c
3OBJS = $(patsubst %.c,%.o,$(SRCS))
4
5all: time-sync
6
7clean:
8 rm -f ${OBJS} ipod-time-sync
9
10%.o: %.c
11 gcc ${CFLAGS} -c -o $@ $^
12
13time-sync: ${OBJS}
14 gcc ${CFLAGS} -lsgutils2 -o $@ $^
15
16install: time-sync
17 cp time-sync /usr/local/bin/ \ No newline at end of file
diff --git a/utils/time-sync/README b/utils/time-sync/README
new file mode 100644
index 0000000000..31a876f428
--- /dev/null
+++ b/utils/time-sync/README
@@ -0,0 +1,20 @@
1time-sync is a utility to sync the time with any Rockbox target that runs the
2software USB stack.
3
4It was originally take from libgpod and stripped of unnecessary code.
5
6http://gtkpod.git.sourceforge.net/git/gitweb.cgi?p=gtkpod/libgpod
7
8To compile and install, just run:
9 make
10 make install
11
12Example run:
13 mcuelenaere@wim2160:~/rockbox/utils/time-sync$ sudo time-sync /dev/sdb1
14 Data Payload: 07 da 00 14 04 0c 30 2b 00 00 00 00
15 Write buffer cmd: 3b 01 00 0c 00 00 00 00 0c 00
16 Time was synced!
17
18Example udev rule (for Onda VX747):
19 # automatically adjust my Rockboxed DAP RTC
20 ACTION=="add", ATTRS{idVendor}=="07c4", ATTRS{idProduct}=="a4a5", KERNEL=="sd?", NAME="%k", RUN+="/usr/local/bin/time-sync /dev/%k"
diff --git a/utils/time-sync/ipod-scsi.c b/utils/time-sync/ipod-scsi.c
new file mode 100644
index 0000000000..163cfbca8f
--- /dev/null
+++ b/utils/time-sync/ipod-scsi.c
@@ -0,0 +1,100 @@
1/* Copyright (c) 2007, Christophe Fergeau <teuf@gnome.org>
2 * Part of the libgpod project.
3 *
4 * URL: http://www.gtkpod.org/
5 * URL: http://gtkpod.sourceforge.net/
6 *
7 * The code contained in this file is free software; you can redistribute
8 * it and/or modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either version
10 * 2.1 of the License, or (at your option) any later version.
11 *
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this code; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * iTunes and iPod are trademarks of Apple
22 *
23 * This product is not supported/written/published by Apple!
24 *
25 */
26
27#include <fcntl.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <stdint.h>
31#include <string.h>
32#include <unistd.h>
33#include <scsi/sg_cmds.h>
34#include <endian.h>
35#include <time.h>
36
37static int do_sg_write_buffer (const char *device, void *buffer, size_t len)
38{
39 int fd;
40 size_t i;
41
42 fd = open (device, O_RDWR);
43 if (fd < 0) {
44 printf ("Couldn't open device %s\n", device);
45 return -1;
46 }
47
48 printf (" Data Payload: ");
49 for (i = 0; i < len; i++) {
50 printf ("%02x ", *((uint8_t *)buffer+i));
51 }
52 printf ("\n");
53
54 if (sg_ll_write_buffer (fd, 1, 0, 0x0c0000, buffer, len, 1, 1) != 0) {
55 close(fd);
56 return -2;
57 }
58 close(fd);
59
60 return 0;
61}
62
63int sync_time (const char *device, struct tm *tm)
64{
65 struct iPodTime {
66 uint16_t year;
67 uint16_t days;
68 uint8_t timezone;
69 uint8_t hour;
70 uint8_t minute;
71 uint8_t second;
72 uint8_t dst;
73 uint8_t padding[3];
74 } __attribute__((__packed__));
75 struct iPodTime ipod_time;
76
77 if (tm == NULL) {
78 time_t current_time;
79 current_time = time (NULL);
80 tm = localtime (&current_time);
81 }
82
83 ipod_time.year = htobe16 (1900+tm->tm_year);
84 ipod_time.days = htobe16 (tm->tm_yday);
85 /* the timezone value is the shift east of UTC in 15 min chunks
86 * so eg. UTC+2 is 2*4 = 8
87 */
88 ipod_time.timezone = tm->tm_gmtoff / 900;
89 ipod_time.hour = tm->tm_hour;
90 ipod_time.minute = tm->tm_min;
91 ipod_time.second = tm->tm_sec;
92 if (tm->tm_isdst) {
93 ipod_time.dst = 1;
94 } else {
95 ipod_time.dst = 0;
96 }
97 memset (ipod_time.padding, 0, sizeof (ipod_time.padding));
98
99 return do_sg_write_buffer (device, &ipod_time, sizeof (ipod_time));
100}
diff --git a/utils/time-sync/time-sync.c b/utils/time-sync/time-sync.c
new file mode 100644
index 0000000000..ebb46ed2fc
--- /dev/null
+++ b/utils/time-sync/time-sync.c
@@ -0,0 +1,41 @@
1/* Copyright (c) 2009, Christophe Fergeau <teuf@gnome.org>
2 *
3 * The code contained in this file is free software; you can redistribute
4 * it and/or modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either version
6 * 2.1 of the License, or (at your option) any later version.
7 *
8 * This file is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this code; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19#include <stdlib.h>
20#include <stdio.h>
21#include <time.h>
22
23extern int sync_time (const char *dev, struct tm *tm);
24extern char *basename (char *__filename);
25
26int
27main (int argc, char **argv)
28{
29 if (argc < 2) {
30 printf ("usage: %s <device>\n", basename(argv[0]));
31 return 1;
32 }
33
34 if (sync_time (argv[1], NULL)) {
35 printf ("Error occured while syncing time.\n");
36 } else {
37 printf ("Time was synced!\n");
38 }
39
40 return 0;
41}