[tuxdroid-svn] r386 - firmware/tuxup/trunk
Status: Beta
Brought to you by:
ks156
From: neimad <c2m...@c2...> - 2007-06-17 10:44:48
|
Author: neimad Date: 2007-06-17 12:44:45 +0200 (Sun, 17 Jun 2007) New Revision: 386 Modified: firmware/tuxup/trunk/main.c Log: * Made all functions static and several global variables and parameters const. * Fixed several lines longer than 80 columns, yet again... Modified: firmware/tuxup/trunk/main.c =================================================================== --- firmware/tuxup/trunk/main.c 2007-06-17 10:31:07 UTC (rev 385) +++ firmware/tuxup/trunk/main.c 2007-06-17 10:44:45 UTC (rev 386) @@ -32,7 +32,7 @@ #include "common/commands.h" /* Messages. */ -const char *msg_old_firmware = +static 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" @@ -46,39 +46,35 @@ "\nCheck http://www.tuxisalive.com/documentation/how-to/updating-the-firmware" "\nfor more details.\n"; -const char *msg_dfu_programmer_not_installed = +static 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 }; +enum program_modes_t { NONE, ALL, MAIN, INPUTFILES }; /* The name of this program. */ -const char *program_name = "tuxup"; +static const char *program_name = "tuxup"; /* The version defined in version.h */ -const char *program_version = VERSION; +static const char *program_version = VERSION; -/* Pointer o the input hex file */ -FILE *hex_file; - /* Whether to display verbose messages. */ int verbose = 0; /* Pretend option. */ -int pretend = 0; +static int pretend = 0; /* USB handle */ -struct usb_device *device; -struct usb_dev_handle *dev_h; -int usb_connected = 0; /* Flag for usb connection status */ +static struct usb_device *device; +static struct usb_dev_handle *dev_h; +static int usb_connected = 0; /* Flag for usb connection status */ /* * Prints usage information for this program to STREAM (typically * stdout or stderr), and exit the program with EXIT_CODE. Does not return. */ -void usage(FILE * stream, int exit_code) +static 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); @@ -102,7 +98,7 @@ exit(exit_code); } -void fux_connect(void) +static void fux_connect(void) { int wait = 5; @@ -151,7 +147,7 @@ usb_connected = 1; } -void fux_disconnect(void) +static void fux_disconnect(void) { if (!usb_connected) return; @@ -164,7 +160,7 @@ usb_connected = 0; } -int hex_to_i(char *hex_nr) +static int hex_to_i(char *hex_nr) { int nr; @@ -178,7 +174,7 @@ * from the hex file and returns 0 if the hex file has a cpu and version * numbers, 1 otherwise. */ -int check_hex_file(char *filename, version_bf_t * version) +static int check_hex_file(const char *filename, version_bf_t * version) { FILE *fs = NULL; char word[80]; @@ -211,7 +207,7 @@ return 1; } -int prog_flash(char *filename) +static int prog_flash(const char *filename) { version_bf_t version; uint8_t cpu_i2c_addr; @@ -222,9 +218,8 @@ if (check_hex_file(filename, &version)) { - printf - ("[FAIL] Programming of '%s' failed, this file is not a correct hex file for that CPU\n\n", - filename); + 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 the ", filename); @@ -250,9 +245,8 @@ } else { - printf - ("Unrecognized CPU number, %s doesn't appear to be compiled for a CPU of tuxdroid.\n", - filename); + printf("Unrecognized CPU number, %s doesn't appear to be compiled" + " for a CPU of tuxdroid.\n", filename); return 1; } printf("Version %d.%d.%d\n", version.ver_major, version.ver_minor, @@ -271,7 +265,7 @@ return 1; } -int prog_eeprom(uint8_t cpu_nbr, char *filename) +static int prog_eeprom(uint8_t cpu_nbr, const char *filename) { uint8_t cpu_i2c_addr; @@ -309,9 +303,10 @@ return 1; } -int prog_usb(char *filename) +static int prog_usb(const char *filename) { - uint8_t send_data[5] = { 0x01, 0x01, 0x00, 0x00, 0xFF }; /* XXX include those as defines in commands.h */ + /* XXX include those as defines in commands.h */ + uint8_t send_data[5] = { 0x01, 0x01, 0x00, 0x00, 0xFF }; char tmp_string[90]; int ret; @@ -333,11 +328,13 @@ 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 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? */ + /* XXX a better way to code that error, a define? */ + if (ret == 32512) { fprintf(stdout, msg_dfu_programmer_not_installed); exit(1); @@ -392,8 +389,12 @@ return 0; } -/* Programming function. Depending on the name, the flash or eeprom programming will be selected. In case of eeprom, the correct CPU will be choosen from the filename. */ -int program(char *filename, char *path) +/* + * Programming function. Depending on the name, the flash or eeprom + * programming will be selected. In case of eeprom, the correct CPU + * will be choosen from the filename. + */ +static int program(char *filename, char *path) { int ret = -1; size_t len; @@ -403,8 +404,9 @@ { /* Checking path */ len = strlen(path); + /* Append '/' at the end if not specified. */ if (path[len - 1] != '/') - strcat(path, "/"); /* Append '/' at the end if not specified. */ + strcat(path, "/"); strcpy(filenamepath, path); strcat(filenamepath, filename); filename = filenamepath; @@ -413,7 +415,8 @@ printf("Processing: %s\n", filename); extension = strrchr(filename, '.'); - if (extension) /* check that an extension has been given */ + /* check that an extension has been given */ + if (extension) { /* Check which program function to start. */ if (!strcmp(extension, ".hex")) |