summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-22 18:07:40 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-11-22 18:07:40 +0000
commit3e2c51d82ce50b0074681c44e81f08de25f34fab (patch)
treec9a9fcd6aeef6fe2cd2d87aa0cb390c747f24f6b
parentf7e2ecee15e2ed24261dd8ab0f7da89636546134 (diff)
downloadrockbox-3e2c51d82ce50b0074681c44e81f08de25f34fab.tar.gz
rockbox-3e2c51d82ce50b0074681c44e81f08de25f34fab.zip
Firmware update utility for the Gigabeat S and probably other MTP devices. Based on libmtp's sendfile.c example, tweaked by Maurus Cuelenaere and me to send firmware files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15755 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--docs/CREDITS1
-rw-r--r--utils/MTP/Makefile11
-rw-r--r--utils/MTP/sendfirm.c136
3 files changed, 148 insertions, 0 deletions
diff --git a/docs/CREDITS b/docs/CREDITS
index ffff55c90d..dca54732e0 100644
--- a/docs/CREDITS
+++ b/docs/CREDITS
@@ -347,6 +347,7 @@ Karim Boucher
347James Espinoza 347James Espinoza
348Franz Rühmland 348Franz Rühmland
349Jordan Anderson 349Jordan Anderson
350Maurus Cuelenaere
350 351
351The libmad team 352The libmad team
352The wavpack team 353The wavpack team
diff --git a/utils/MTP/Makefile b/utils/MTP/Makefile
new file mode 100644
index 0000000000..4678546b02
--- /dev/null
+++ b/utils/MTP/Makefile
@@ -0,0 +1,11 @@
1CFLAGS = -Wall
2LIBS = -lmtp
3OUTPUT = sendfirm
4
5all: $(OUTPUT)
6
7$(OUTPUT): sendfirm.c
8 gcc $(CFLAGS) $(LIBS) -o $(OUTPUT) sendfirm.c
9
10clean:
11 rm -f $(OUTPUT)
diff --git a/utils/MTP/sendfirm.c b/utils/MTP/sendfirm.c
new file mode 100644
index 0000000000..e216037efc
--- /dev/null
+++ b/utils/MTP/sendfirm.c
@@ -0,0 +1,136 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Based on sendfile.c from libmtp: http://libmtp.sourceforge.net
11 * Modified by Maurus Cuelenaere and Nicolas Pennequin.
12 *
13 * Copyright (C) 2005-2007 Linus Walleij
14 * Copyright (C) 2006 Chris A. Debenham
15 *
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#define _LARGEFILE_SOURCE
25#define _LARGEFILE64_SOURCE
26
27#include <string.h>
28#include <libgen.h>
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <fcntl.h>
32#include "libmtp.h"
33
34LIBMTP_mtpdevice_t *device;
35
36static int progress(u_int64_t const sent, u_int64_t const total,
37 void const *const data)
38{
39 int percent = (sent * 100) / total;
40#ifdef __WIN32__
41 printf("Progress: %I64u of %I64u (%d%%)\r", sent, total, percent);
42#else
43 printf("Progress: %llu of %llu (%d%%)\r", sent, total, percent);
44#endif
45 fflush(stdout);
46 return 0;
47}
48
49void usage(void)
50{
51 fprintf(stderr, "usage: sendfirm <local filename>\n");
52}
53
54int sendfile_function(char *from_path)
55{
56 printf("Sending %s\n", from_path);
57 char *filename;
58 uint64_t filesize;
59#ifdef __USE_LARGEFILE64
60 struct stat64 sb;
61#else
62 struct stat sb;
63#endif
64 LIBMTP_file_t *genfile;
65 int ret;
66 uint32_t parent_id = 0;
67
68#ifdef __USE_LARGEFILE64
69 if (stat64(from_path, &sb) == -1)
70 {
71#else
72 if (stat(from_path, &sb) == -1)
73 {
74#endif
75 fprintf(stderr, "%s: ", from_path);
76 perror("stat");
77 exit(1);
78 }
79
80#ifdef __USE_LARGEFILE64
81 filesize = sb.st_size;
82#else
83 filesize = (uint64_t) sb.st_size;
84#endif
85 filename = basename(from_path);
86
87 genfile = LIBMTP_new_file_t();
88 genfile->filesize = filesize;
89 genfile->filename = strdup("nk.bin");
90 genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
91
92 printf("Sending file...\n");
93 ret = LIBMTP_Send_File_From_File(device, from_path, genfile, progress,
94 NULL, parent_id);
95 printf("\n");
96 if (ret != 0)
97 {
98 printf("Error sending file.\n");
99 LIBMTP_Dump_Errorstack(device);
100 LIBMTP_Clear_Errorstack(device);
101 }
102 else
103 {
104 printf("New file ID: %d\n", genfile->item_id);
105 }
106
107 LIBMTP_destroy_file_t(genfile);
108
109 return 0;
110}
111
112int main(int argc, char **argv)
113{
114 if (argc < 2)
115 {
116 usage();
117 return 1;
118 }
119
120 LIBMTP_Init();
121
122 fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
123
124 device = LIBMTP_Get_First_Device();
125 if (device == NULL)
126 {
127 printf("No devices.\n");
128 return 0;
129 }
130
131 sendfile_function(argv[1]);
132
133 LIBMTP_Release_Device(device);
134
135 exit(0);
136}