diff options
Diffstat (limited to 'utils/tcctool/tcctool.c')
-rw-r--r-- | utils/tcctool/tcctool.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/utils/tcctool/tcctool.c b/utils/tcctool/tcctool.c index c1d7a46553..1beaa049ff 100644 --- a/utils/tcctool/tcctool.c +++ b/utils/tcctool/tcctool.c | |||
@@ -154,7 +154,7 @@ int upload_app(usb_dev_handle* dh, int device, char* p, int len) | |||
154 | 154 | ||
155 | /* The main function */ | 155 | /* The main function */ |
156 | 156 | ||
157 | void do_patching(int device, char* buf, int len) | 157 | int do_patching(int device, char* buf, int len) |
158 | { | 158 | { |
159 | struct usb_bus *busses; | 159 | struct usb_bus *busses; |
160 | struct usb_bus *bus; | 160 | struct usb_bus *bus; |
@@ -168,12 +168,12 @@ void do_patching(int device, char* buf, int len) | |||
168 | usb_init(); | 168 | usb_init(); |
169 | if(usb_find_busses() < 0) { | 169 | if(usb_find_busses() < 0) { |
170 | fprintf(stderr, "[ERR] Could not find any USB busses.\n"); | 170 | fprintf(stderr, "[ERR] Could not find any USB busses.\n"); |
171 | return; | 171 | return -1; |
172 | } | 172 | } |
173 | 173 | ||
174 | if (usb_find_devices() < 0) { | 174 | if (usb_find_devices() < 0) { |
175 | fprintf(stderr, "[ERR] USB devices not found(nor hubs!).\n"); | 175 | fprintf(stderr, "[ERR] USB devices not found(nor hubs!).\n"); |
176 | return; | 176 | return -1; |
177 | } | 177 | } |
178 | 178 | ||
179 | /* C calling convention, it's not nice to use global stuff */ | 179 | /* C calling convention, it's not nice to use global stuff */ |
@@ -195,13 +195,13 @@ void do_patching(int device, char* buf, int len) | |||
195 | if (dev == NULL) { | 195 | if (dev == NULL) { |
196 | fprintf(stderr, "[ERR] TCC device not found.\n"); | 196 | fprintf(stderr, "[ERR] TCC device not found.\n"); |
197 | fprintf(stderr, "[ERR] Ensure your TCC device is in USB boot mode and run tcctool again.\n"); | 197 | fprintf(stderr, "[ERR] Ensure your TCC device is in USB boot mode and run tcctool again.\n"); |
198 | return; | 198 | return -1; |
199 | } | 199 | } |
200 | 200 | ||
201 | found: | 201 | found: |
202 | if ( (dh = usb_open(dev)) == NULL) { | 202 | if ( (dh = usb_open(dev)) == NULL) { |
203 | fprintf(stderr,"[ERR] Unable to open TCC device.\n"); | 203 | fprintf(stderr,"[ERR] Unable to open TCC device.\n"); |
204 | return; | 204 | return -1; |
205 | } | 205 | } |
206 | 206 | ||
207 | err = usb_set_configuration(dh, 1); | 207 | err = usb_set_configuration(dh, 1); |
@@ -209,7 +209,7 @@ found: | |||
209 | if (err < 0) { | 209 | if (err < 0) { |
210 | fprintf(stderr, "[ERR] usb_set_configuration failed (%d)\n", err); | 210 | fprintf(stderr, "[ERR] usb_set_configuration failed (%d)\n", err); |
211 | usb_close(dh); | 211 | usb_close(dh); |
212 | return; | 212 | return -1; |
213 | } | 213 | } |
214 | 214 | ||
215 | /* "must be called" written in the libusb documentation */ | 215 | /* "must be called" written in the libusb documentation */ |
@@ -217,14 +217,14 @@ found: | |||
217 | if (err < 0) { | 217 | if (err < 0) { |
218 | fprintf(stderr, "[ERR] Unable to claim interface (%d)\n", err); | 218 | fprintf(stderr, "[ERR] Unable to claim interface (%d)\n", err); |
219 | usb_close(dh); | 219 | usb_close(dh); |
220 | return; | 220 | return -1; |
221 | } | 221 | } |
222 | 222 | ||
223 | fprintf(stderr,"[INFO] Found TCC device, uploading application.\n"); | 223 | fprintf(stderr,"[INFO] Found TCC device, uploading application.\n"); |
224 | 224 | ||
225 | /* Now we can transfer the application to the device. */ | 225 | /* Now we can transfer the application to the device. */ |
226 | 226 | ||
227 | if (upload_app(dh, device, buf, len) < 0) | 227 | if ( (err = upload_app(dh, device, buf, len)) < 0) |
228 | { | 228 | { |
229 | fprintf(stderr,"[ERR] Upload of application failed.\n"); | 229 | fprintf(stderr,"[ERR] Upload of application failed.\n"); |
230 | } | 230 | } |
@@ -235,8 +235,9 @@ found: | |||
235 | 235 | ||
236 | /* release claimed interface */ | 236 | /* release claimed interface */ |
237 | usb_release_interface(dh, dev->config->interface->altsetting->bInterfaceNumber); | 237 | usb_release_interface(dh, dev->config->interface->altsetting->bInterfaceNumber); |
238 | |||
239 | usb_close(dh); | 238 | usb_close(dh); |
239 | |||
240 | return err < 0 ? -1: 0; | ||
240 | } | 241 | } |
241 | 242 | ||
242 | off_t filesize(int fd) { | 243 | off_t filesize(int fd) { |
@@ -326,7 +327,10 @@ int main(int argc, char* argv[]) | |||
326 | } | 327 | } |
327 | close(fd); | 328 | close(fd); |
328 | 329 | ||
329 | do_patching(device, buf, padded_len); | 330 | if (do_patching(device, buf, padded_len)) |
331 | { | ||
332 | return 8; | ||
333 | } | ||
330 | 334 | ||
331 | return 0; | 335 | return 0; |
332 | } | 336 | } |