[tuxdroid-svn] r1237 - firmware/tuxup/trunk
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2008-06-20 11:48:25
|
Author: remi Date: 2008-06-20 13:48:28 +0200 (Fri, 20 Jun 2008) New Revision: 1237 Added: firmware/tuxup/trunk/error.h Modified: firmware/tuxup/trunk/Makefile firmware/tuxup/trunk/bootloader.c firmware/tuxup/trunk/main.c Log: * Added specific error codes on the program exiting. * Added a sleep(5) at the end on the "prog_usb" function, between fux_disconnect and fux_connect. (Windows needs more time than linux to detect the reconnection of the dongle) Modified: firmware/tuxup/trunk/Makefile =================================================================== --- firmware/tuxup/trunk/Makefile 2008-06-17 14:46:21 UTC (rev 1236) +++ firmware/tuxup/trunk/Makefile 2008-06-20 11:48:28 UTC (rev 1237) @@ -4,9 +4,9 @@ ## General Flags ifdef windir - CC = "gcc.exe" + CC = "E:\MinGWStudio\MinGW\bin\gcc.exe" DEFS = -DWIN32 - C_INCLUDE_DIRS = -I"C:\bin\MinGWStudio\MinGW\include\ddk" + C_INCLUDE_DIRS = -I"E:\MinGWStudio\MinGW\include\ddk" CFLAGS = -pipe -Wall -funsigned-char -g2 -O0 LIBS = -lwinmm -lhid -lsetupapi -lhidparse else @@ -48,12 +48,14 @@ bootloader.h \ version.h \ tux_misc.h \ +error.h \ tux_hid_win32.h $(compile_source) bootloader.o: bootloader.c \ tux_misc.h \ tux_hid_win32.h \ +error.h \ tux-api.h $(compile_source) Modified: firmware/tuxup/trunk/bootloader.c =================================================================== --- firmware/tuxup/trunk/bootloader.c 2008-06-17 14:46:21 UTC (rev 1236) +++ firmware/tuxup/trunk/bootloader.c 2008-06-20 11:48:28 UTC (rev 1237) @@ -41,6 +41,7 @@ # include "tux_hid_unix.h" #endif #include "tux-api.h" +#include "error.h" /* Whether to display verbose messages. */ extern int verbose; @@ -412,7 +413,7 @@ { fprintf(stderr, "Bootloading failed, program aborted at dongle reply.\n"); - exit(1); + exit(E_TUXUP_BOOTLOADINGFAILED); } } else @@ -431,7 +432,7 @@ { fprintf(stderr, "\nBootloading failed, program aborted at dongle reply.\n"); - exit(1); + exit(E_TUXUP_BOOTLOADINGFAILED); } } } Added: firmware/tuxup/trunk/error.h =================================================================== --- firmware/tuxup/trunk/error.h (rev 0) +++ firmware/tuxup/trunk/error.h 2008-06-20 11:48:28 UTC (rev 1237) @@ -0,0 +1,38 @@ +/* + * Tuxup - Error + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef _ERROR_H_ +#define _ERROR_H_ + +typedef enum +{ + E_TUXUP_NOERROR = 0, + E_TUXUP_BADPARAMETER = 2, + E_TUXUP_DONGLENOTFOUND = 3, + E_TUXUP_DONGLEMANUALBOOTLOAD = 4, + E_TUXUP_BADHEXFILE = 5, + E_TUXUP_BADEEPFILE = 6, + E_TUXUP_BOOTLOADINGFAILED = 7, + E_TUXUP_USBERROR = 8, + E_TUXUP_DFUPROGNOTFOUND = 9, + E_TUXUP_PROGRAMMINGFAILED = 10 +} tuxup_error_t; + +#endif /* _ERROR_ */ Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2008-06-17 14:46:21 UTC (rev 1236) +++ firmware/tuxup/trunk/main.c 2008-06-20 11:48:28 UTC (rev 1237) @@ -32,6 +32,7 @@ #include "version.h" #include "common/defines.h" #include "tux_misc.h" +#include "error.h" #ifdef WIN32 # include "tux_hid_win32.h" # include <windows.h> @@ -144,7 +145,7 @@ if (device == NULL) { fprintf(stderr, "The dongle was not found, now exiting.\n"); - exit(1); + exit(E_TUXUP_DONGLENOTFOUND); } else { @@ -154,7 +155,7 @@ } #else fprintf(stderr, "The dongle was not found, now exiting.\n"); - exit(1); + exit(E_TUXUP_DONGLENOTFOUND); #endif } else @@ -176,14 +177,14 @@ if (device->descriptor.bcdDevice < 0x030) { fprintf(stderr, msg_old_firmware); - exit(1); + exit(E_TUXUP_DONGLEMANUALBOOTLOAD); } /* open USB device */ if ((dev_h = usb_open_tux(device)) == NULL) { fprintf(stderr, "USB DEVICE INIT ERROR \n"); - exit(1); + exit(E_TUXUP_USBERROR); } } #endif @@ -238,7 +239,7 @@ if ((fs = fopen(filename, "r")) == NULL) { fprintf(stderr, "Unable to open file '%s' for reading\n", filename); - exit(1); + exit(E_TUXUP_BADHEXFILE); } while (fscanf(fs, " %s", word) != EOF) @@ -276,7 +277,7 @@ { printf("[FAIL] Programming of '%s' failed, this file is not a correct" " hex file for that CPU\n\n", filename); - return 1; + return E_TUXUP_BADHEXFILE; } printf("Programming %s in the ", filename); if (version.cpu_nbr == TUXCORE_CPU_NUM) @@ -303,13 +304,13 @@ { printf("Unrecognized CPU number, %s doesn't appear to be compiled" " for a CPU of tuxdroid.\n", filename); - return 1; + return E_TUXUP_BADHEXFILE; } printf("Version %d.%d.%d\n", version.ver_major, version.ver_minor, version.ver_update); if (pretend) - return 0; + return E_TUXUP_NOERROR; #ifdef WIN32 if (bootload(cpu_i2c_addr, FLASH, filename)) #else @@ -321,7 +322,7 @@ #else printf("\033[2C[ \033[01;32mOK\033[00m ]\n"); #endif - return 0; + return E_TUXUP_NOERROR; } else { @@ -331,7 +332,7 @@ printf("\033[2C[\033[01;31mFAIL\033[00m]\n"); #endif } - return 1; + return E_TUXUP_PROGRAMMINGFAILED; } static int prog_eeprom(uint8_t cpu_nbr, char const *filename) @@ -356,11 +357,11 @@ else { printf("Wrong CPU number specified for the eeprom.\n"); - return 0; + return E_TUXUP_BADEEPFILE; } if (pretend) - return 0; + return E_TUXUP_NOERROR; #ifdef WIN32 if (bootload(cpu_i2c_addr, EEPROM, filename)) #else @@ -372,7 +373,7 @@ #else printf("\033[2C[ \033[01;32mOK\033[00m ]\n"); #endif - return 0; + return E_TUXUP_NOERROR; } else { @@ -382,7 +383,7 @@ printf("\033[2C[\033[01;31mFAIL\033[00m]\n"); #endif } - return 1; + return E_TUXUP_PROGRAMMINGFAILED; } static int prog_usb(char const *filename) @@ -400,20 +401,20 @@ { printf("[FAIL] Programming of '%s' failed, this file is not a correct" " hex file for that CPU\n\n", filename); - return 1; + return E_TUXUP_BADHEXFILE; } if (version.cpu_nbr != FUXUSB_CPU_NUM) { printf("Unrecognized CPU number, %s doesn't appear to be compiled" " for a CPU of tuxdroid.\n", filename); - return 1; + return E_TUXUP_BADHEXFILE; } printf("Version %d.%d.%d\n", version.ver_major, version.ver_minor, version.ver_update); if (pretend) - return 0; + return E_TUXUP_NOERROR; /* Check if the dongle is already in bootloader mode */ if (verbose) @@ -436,7 +437,7 @@ if (ret == 32512) { fprintf(stdout, msg_dfu_programmer_not_installed); - exit(1); + exit(E_TUXUP_DFUPROGNOTFOUND); } if (verbose) { @@ -467,7 +468,7 @@ else { fprintf(stderr, "Switching to bootloader mode failed.\n"); - return 1; + return E_TUXUP_BOOTLOADINGFAILED; } } #endif @@ -476,28 +477,30 @@ if (ret) { fprintf(stderr, "[FAIL] Erasing the USB CPU failed.\n"); - return ret; + return E_TUXUP_PROGRAMMINGFAILED; } sprintf(tmp_string, "dfu-programmer at89c5130 flash %s", filename); ret = system(tmp_string); if (ret) { fprintf(stderr, "[FAIL] Flashing the USB CPU failed.\n"); - return ret; + return E_TUXUP_PROGRAMMINGFAILED; } ret = system("dfu-programmer at89c5130 configure HSB 0x7b"); if (ret) { fprintf(stderr, "[FAIL] Configuring the USB CPU failed.\n"); - return ret; + return E_TUXUP_PROGRAMMINGFAILED; } ret = system("dfu-programmer at89c5130 start"); fprintf(stdout, "[OK]\n"); fux_disconnect(); + /* Windows needs more time than linux to enumerate the device */ + sleep(5); fux_connect(); - return 0; + return E_TUXUP_NOERROR; } /* @@ -616,7 +619,7 @@ case 'h': /* -h or --help */ /* User has requested usage information. Print it to standard * output, and exit with exit code zero (normal termination). */ - usage(stdout, 0); + usage(stdout, E_TUXUP_NOERROR); case 'm': /* -m or --main */ if (program_mode == NONE) program_mode = MAIN; @@ -624,7 +627,7 @@ { fprintf(stderr, "'-a' and '-m' options can't be used simultaneoulsy.\n\n"); - usage(stderr, 1); + usage(stderr, E_TUXUP_BADPARAMETER); } break; case 'a': /* -a or --all */ @@ -634,7 +637,7 @@ { fprintf(stderr, "'-a' and '-m' options can't be used simultaneoulsy.\n\n"); - usage(stderr, 1); + usage(stderr, E_TUXUP_BADPARAMETER); } break; case 'p': /* -a or --all */ @@ -646,12 +649,12 @@ case 'V': /* -V or --version */ fprintf(stdout, "%s %s, an uploader program for tuxdroid.\n\n", program_name, program_version); - exit(0); /* version is already printed, so just exit. */ + exit(E_TUXUP_NOERROR); /* version is already printed, so just exit. */ break; case '?': /* The user specified an invalid option. */ /* Print usage information to standard error, and exit with exit * code one (indicating abnormal termination). */ - usage(stderr, 1); + usage(stderr, E_TUXUP_NOERROR); case -1: /* Done with options. */ break; default: /* Something else: unexpected. */ @@ -679,14 +682,14 @@ else { fprintf(stderr, "too many files or paths specified.\n\n"); - usage(stderr, 1); + usage(stderr, E_TUXUP_BADPARAMETER); } } } else { fprintf(stderr, "no file nor path specified.\n\n"); - usage(stderr, 1); + usage(stderr, E_TUXUP_BADPARAMETER); } /* Select which files to program */ @@ -742,5 +745,5 @@ if (!pretend) printf("Time elapsed: %2.0f seconds.\n", difftime(end_time, start_time)); - return 0; + return ret; } |