[tuxdroid-svn] r211 - firmware/tuxup/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-03-28 08:06:58
|
Author: jaguarondi Date: 2007-03-27 13:04:28 +0200 (mar, 27 mar 2007) New Revision: 211 Modified: firmware/tuxup/trunk/main.c firmware/tuxup/trunk/version.h Log: - ADD: check if dfu-programmer is installed - ADD: check if the old firmware is used and tell to replug with the button pressed - UPD: messages have been improved and cleaned - UPD: moved to version 0.1.1 unreleased Modififirmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2007-03-26 06:08:50 UTC (rev 210) +++ firmware/tuxup/trunk/main.c 2007-03-27 11:04:28 UTC (rev 211) @@ -31,11 +31,30 @@ #include "version.h" #include "common/commands.h" +/* Messages. */ +const char * msg_old_firmware = \ +"\nERROR: Your dongle firmware is too old to support switching to bootloader"\ +"\nmode automatically.\n"\ +"\n To enter bootloading mode manually, you need to unplug the dongle, press"\ +"\n with a small pin on the button located inside the hole on the belly and,"\ +"\n while keeping it pressed, plug the dongle."\ +"\n The eyes should not turn blue at this time, otherwise try again."\ +"\n Now, reprogram the dongle alone with the command:"\ +"\n 'tuxup /opt/tuxdroid/hex/fusxusb.hex'"\ +"\n (You may use another path depending on the hex files"\ +" you want to use).\n"\ +"\nCheck http://www.tuxisalive.com/documentation/how-to/updating-the-firmware"\ +"\nfor more details.\n"; + +const char* msg_dfu_programmer_not_installed = \ +"\nERROR: dfu-programmer is not installed or is not in your path, tuxup uses"\ +"\nit to reprogram the USB cpu so installing dfu-programmer is mandatory.\n"; + /* Programming modes. */ enum program_modes_t {NONE, ALL, MAIN, INPUTFILES}; /* The name of this program. */ -const char* program_name; +const char* program_name = "tuxup"; /* The version defined in version.h */ const char * program_version = VERSION; @@ -60,6 +79,7 @@ */ void usage (FILE* stream, int exit_code) { + fprintf(stream, "%s %s\n",program_name, program_version ); fprintf(stream, "Usage: %s options [path|file ...]\n", program_name); fprintf (stream, " -m --main Reprogram tuxcore and tuxaudio (flash and eeprom) with hex files located in path.\n" @@ -97,15 +117,24 @@ if (device == NULL) { if (!wait) { - fprintf(stderr, "Tux not found on USB\n"); + fprintf(stderr, "The dongle was not found, now exiting.\n"); exit(1); } } else { - if (verbose) printf("Tux found \n"); + if (verbose) printf("The dongle was found.\n"); + /* Check if we have the old firmware that requires entering + * bootloader mode manually, exits with a message that exlains what + * to do in such a case. */ + if (device->descriptor.bcdDevice < 0x100) + { + fprintf(stderr, msg_old_firmware); + exit(1); + } break; } + sleep(1); wait--; } @@ -187,7 +216,7 @@ printf("[FAIL] Programming of '%s' failed, this file is not a correct hex file for that CPU\n\n", filename); return 1; } - printf("Programming %s in ", filename); + printf("Programming %s in the ", filename); if (version.cpu_nbr == TUXCORE_CPU_NUM) { printf("core CPU\n"); @@ -208,11 +237,6 @@ printf("fux (dongle) RF CPU\n"); cpu_i2c_addr = FUXRF_BL_ADDR; } - else if (version.cpu_nbr == FUXUSB_CPU_NUM) - { - printf("fux (dongle) USB CPU: not implemented yet\n"); - return 1; - } else { printf("Unrecognized CPU number, %s doesn't appear to be compiled for a CPU of tuxdroid.\n", filename); @@ -273,20 +297,34 @@ uint8_t send_data[5] = {0x01, 0x01, 0x00, 0x00, 0xFF}; /* XXX include those as defines in commands.h */ char tmp_string[90]; int ret; - printf("Programming %s in USB CPU\n", filename); + printf("Programming %s in the USB CPU\n", filename); if (pretend) return 0; /* Check if the dongle is already in bootloader mode */ if (verbose) { - fprintf(stdout,"Testing if the dongle is already in bootloader mode. If it is not, 'no device present' will be reported, don't worry about it\n"); + fprintf(stdout,"Testing if the dongle is already in bootloader mode.\n"\ + "If it is not, 'no device present' will be reported.\n"); ret = system("dfu-programmer at89c5130 get bootloader-version"); } else ret = system("dfu-programmer at89c5130 get bootloader-version 2> /dev/null"); + + /* If dfu-programmer didn't detect the dongle, we try to set it in bootloader mode with the specific command */ if (ret) { + /* Check if dfu-programmer is installed */ + if (ret == 32512) /* XXX a better way to code that error, a define? */ + { + fprintf(stdout, msg_dfu_programmer_not_installed); + exit(1); + } + if (verbose) + { + fprintf(stdout,"The dongle was not detected in bootloader mode, "\ + "now \ntrying to set it with a command.\n"); + } fux_connect(); /* Enter bootloader mode. */ ret = usb_send_commands(dev_h, send_data, 5); @@ -296,7 +334,10 @@ sleep(2); } else + { fprintf (stderr, "Switching to bootloader mode failed.\n"); + return 1; + } } @@ -340,7 +381,7 @@ /* Checking path */ len = strlen(path); if (path[len-1] != '/') - strcat(path, "/"); /* Append '/' at the end of not specified. */ + strcat(path, "/"); /* Append '/' at the end if not specified. */ strcpy (filenamepath, path); strcat(filenamepath, filename); filename = filenamepath; @@ -417,7 +458,7 @@ /* Remember the name of the program, to incorporate in messages. The name is stored in argv[0]. */ - program_name = argv[0]; + /*program_name = argv[0];*/ /* Save the start time to measure the programming time */ start_time = time((time_t *)0); @@ -456,7 +497,7 @@ verbose = 1; break; case 'V': /* -V or --version */ - fprintf(stdout, "%s v%s, an uploader program for tuxdroid\n\n",program_name, program_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. */ break; case '?': /* The user specified an invalid option. */ @@ -470,12 +511,10 @@ } } while (next_option != -1); - /* Done with options. OPTIND points to first nonoption argument. - For demonstration purposes, print them if the verbose option was - specified. */ + /* Done with options. OPTIND points to first nonoption argument. */ /* Print program name and version at program launch */ - if (verbose) fprintf(stdout, "%s v%s, an uploader program for tuxdroid\n\n",program_name, program_version ); + if (verbose) fprintf(stdout, "%s %s, an uploader program for tuxdroid.\n\n",program_name, program_version ); /* If no program mode has been selected, choose INPUTFILES. */ if (program_mode == NONE) Modififirmware/tuxup/trunk/version.h =================================================================== --- firmware/tuxup/trunk/version.h 2007-03-26 06:08:50 UTC (rev 210) +++ firmware/tuxup/trunk/version.h 2007-03-27 11:04:28 UTC (rev 211) @@ -22,6 +22,6 @@ #ifndef version_h #define version_h -#define VERSION "0.1.0" +#define VERSION "0.1.1 (SVN/UNRELEASED)" #endif |