[tuxdroid-svn] r686 - firmware/tuxup/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-12 11:47:37
|
Author: jaguarondi Date: 2007-11-12 12:47:35 +0100 (Mon, 12 Nov 2007) New Revision: 686 Modified: firmware/tuxup/trunk/main.c Log: * main() now returns an error when programming fails for any reason. Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2007-11-12 10:13:49 UTC (rev 685) +++ firmware/tuxup/trunk/main.c 2007-11-12 11:47:35 UTC (rev 686) @@ -31,6 +31,8 @@ #include "version.h" #include "common/defines.h" +#define countof(X) ( (size_t) ( sizeof(X)/sizeof*(X) ) ) + /* Messages. */ static const char *msg_old_firmware = "\nERROR: Your dongle firmware is too old to support switching to bootloader" @@ -393,20 +395,20 @@ * programming will be selected. In case of eeprom, the correct CPU * will be choosen from the filename. */ -static int program(char *filename, char *path) +static int program(char const *filename, char const *path) { int ret = -1; size_t len; - char *extension, filenamepath[90]; + char *extension, filenamepath[255]; if (path) { /* Checking path */ len = strlen(path); + strcpy(filenamepath, path); /* Append '/' at the end if not specified. */ if (path[len - 1] != '/') - strcat(path, "/"); - strcpy(filenamepath, path); + strcat(filenamepath, "/"); strcat(filenamepath, filename); filename = filenamepath; } @@ -470,6 +472,7 @@ char path[90]; enum program_modes_t program_mode = NONE; time_t start_time, end_time; + int ret = 0; int next_option; @@ -582,24 +585,25 @@ case INPUTFILES: { int i; - for (i = optind; i < argc; ++i) - program(argv[i], NULL); /* XXX returned values are not used yet */ + for (i = optind; i < argc && !ret ; ++i) + ret = program(argv[i], NULL); /* XXX returned values are not used yet */ } break; case MAIN: - program("tuxcore.hex", path); - program("tuxcore.eep", path); - program("tuxaudio.hex", path); - program("tuxaudio.eep", path); + { + const char *s[]={"tuxcore.hex","tuxcore.eep","tuxaudio.hex","tuxaudio.eep"}; + const char **p; + for (p = s; p < &s[countof(s)] && !ret ; p++) + ret = program(*p, path); + } break; case ALL: - program("fuxusb.hex", path); - program("tuxcore.hex", path); - program("tuxcore.eep", path); - program("tuxaudio.hex", path); - program("tuxaudio.eep", path); - program("tuxrf.hex", path); - program("fuxrf.hex", path); + { + const char *s[]={"fuxusb.hex", "tuxcore.hex","tuxcore.eep","tuxaudio.hex","tuxaudio.eep", "fuxrf.hex", "tuxrf.hex"}; + const char **p; + for (p = s; p < &s[countof(s)] && !ret ; p++) + ret = program(*p, path); + } break; default: abort(); @@ -608,6 +612,10 @@ if (!pretend) fux_disconnect(); + /* In case of error of some sort, we return it. */ + if (ret) + return ret; + /* Print time elapsed for programming. */ end_time = time(NULL); if (!pretend) |