diff -u -U 5 -r --new-file -x *~ -X /tmp/diffexclude fxload-2002_04_11/ezusb.c fxload-2002_04_11.doj/ezusb.c --- fxload-2002_04_11/ezusb.c Fri Apr 12 06:08:01 2002 +++ fxload-2002_04_11.doj/ezusb.c Sun Sep 5 13:46:27 2004 @@ -32,10 +32,12 @@ # include # include # include "ezusb.h" +void logerror(char *format, ...); + /* * This file contains functions for downloading firmware into Cypress * EZ-USB microcontrollers. These chips use control endpoint 0 and vendor * specific commands to support writing into the on-chip SRAM. They also * support writing into the CPUCS register, which is how we reset the @@ -121,11 +123,11 @@ size_t length ) { struct usbdevfs_ctrltransfer ctrl; if (length > USHRT_MAX) { - fputs ("length too big", stderr); + logerror("length too big\n"); return -EINVAL; } /* 8 bytes SETUP */ ctrl.bRequestType = requestType; @@ -168,21 +170,20 @@ size_t len ) { int status; if (verbose) - fprintf (stderr, "%s, addr 0x%04x len %4d (0x%04x)\n", - label, addr, len, len); + logerror("%s, addr 0x%04x len %4d (0x%04x)\n", label, addr, len, len); status = ctrl_msg (device, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, opcode, addr, 0, data, len); if (status != len) { if (status < 0) - perror (label); + logerror("%s : %s\n", strerror(errno), label); else - fprintf (stderr, "%s ==> %d\n", label, status); + logerror("%s ==> %d\n", label, status); } return status; } /* @@ -197,21 +198,20 @@ size_t len ) { int status; if (verbose) - fprintf (stderr, "%s, addr 0x%04x len %4d (0x%04x)\n", - label, addr, len, len); + logerror("%s, addr 0x%04x len %4d (0x%04x)\n", label, addr, len, len); status = ctrl_msg (device, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, opcode, addr, 0, (unsigned char *) data, len); if (status != len) { if (status < 0) - perror (label); + logerror("%s : %s", strerror(errno), label); else - fprintf (stderr, "%s ==> %d\n", label, status); + logerror("%s ==> %d\n", label, status); } return status; } /* @@ -225,22 +225,21 @@ ) { int status; unsigned char data = doRun ? 0 : 1; if (verbose) - fprintf (stderr, "%s\n", data ? "stop CPU" : "reset CPU"); + logerror("%s\n", data ? "stop CPU" : "reset CPU"); status = ctrl_msg (device, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, RW_INTERNAL, addr, 0, &data, 1); if (status != 1) { - char *mesg = "can't modify CPUCS"; if (status < 0) - perror (mesg); + logerror("%s : %s", strerror(errno), device); else - fprintf (stderr, "%s\n", mesg); + logerror("can't modify CPUCS\n"); return 0; } else return 1; } @@ -303,28 +302,28 @@ size_t len; unsigned idx, off; cp = fgets(buf, sizeof buf, image); if (cp == 0) { - fprintf (stderr, "EOF without EOF record!\n"); + logerror("EOF without EOF record!\n"); break; } /* EXTENSION: "# comment-till-end-of-line", for copyrights etc */ if (buf[0] == '#') continue; if (buf[0] != ':') { - fprintf (stderr, "not an ihex record: %s", buf); + logerror("not an ihex record: %s", buf); return -2; } if (verbose >= 3) { cp = strchr (buf, '\n'); if (cp) *cp = 0; - fprintf (stderr, "** LINE: %s\n", buf); + logerror("** LINE: %s\n", buf); } /* Read the length field (up to 16 bytes) */ tmp = buf[3]; buf[3] = 0; @@ -350,21 +349,21 @@ buf[9] = tmp; /* If this is an EOF record, then make it so. */ if (type == 1) { if (verbose >= 2) - fprintf (stderr, "EOF on hexfile\n"); + logerror("EOF on hexfile\n"); break; } if (type != 0) { - fprintf (stderr, "unsupported record type: %u\n", type); + logerror("unsupported record type: %u\n", type); return -3; } if ((len * 2) + 11 >= strlen(buf)) { - fprintf (stderr, "record too short?\n"); + logerror("record too short?\n"); return -4; } // FIXME check for _physically_ contiguous not just virtually // e.g. on FX2 0x1f00-0x2100 includes both on-chip and external @@ -442,35 +441,35 @@ unsigned retry = 0; switch (ctx->mode) { case internal_only: /* CPU should be stopped */ if (external) { - fprintf (stderr, "can't write %d bytes external memory at 0x%04x\n", + logerror("can't write %d bytes external memory at 0x%04x\n", len, addr); return -EINVAL; } break; case skip_internal: /* CPU must be running */ if (!external) { if (verbose >= 2) { - fprintf (stderr, "SKIP on-chip RAM, %d bytes at 0x%04x\n", + logerror("SKIP on-chip RAM, %d bytes at 0x%04x\n", len, addr); } return 0; } break; case skip_external: /* CPU should be stopped */ if (external) { if (verbose >= 2) { - fprintf (stderr, "SKIP external RAM, %d bytes at 0x%04x\n", + logerror("SKIP external RAM, %d bytes at 0x%04x\n", len, addr); } return 0; } break; default: - fprintf (stderr, "bug\n"); + logerror("bug\n"); return -EDOM; } ctx->total += len; ctx->count++; @@ -512,14 +511,14 @@ struct ram_poke_context ctx; int status; image = fopen (path, "r"); if (image == 0) { - fprintf (stderr, "%s: unable to open for input.\n", path); + logerror("%s: unable to open for input.\n", path); return -2; } else if (verbose) - fprintf (stderr, "open RAM hexfile image %s\n", path); + logerror("open RAM hexfile image %s\n", path); /* EZ-USB original/FX and FX2 devices differ, apart from the 8051 core */ if (fx2) { cpucs_addr = 0xe600; is_external = fx2_is_external; @@ -540,19 +539,19 @@ } else { ctx.mode = skip_internal; /* let CPU run; overwrite the 2nd stage loader later */ if (verbose) - fprintf (stderr, "2nd stage: write external memory\n"); + logerror("2nd stage: write external memory\n"); } /* scan the image, first (maybe only) time */ ctx.device = fd; ctx.total = ctx.count = 0; status = parse_ihex (image, &ctx, is_external, ram_poke); if (status < 0) { - fprintf (stderr, "unable to download %s\n", path); + logerror("unable to download %s\n", path); return status; } /* second part of 2nd stage: rescan */ if (stage) { @@ -563,20 +562,20 @@ return -1; /* at least write the interrupt vectors (at 0x0000) for reset! */ rewind (image); if (verbose) - fprintf (stderr, "2nd stage: write on-chip memory\n"); + logerror("2nd stage: write on-chip memory\n"); status = parse_ihex (image, &ctx, is_external, ram_poke); if (status < 0) { - fprintf (stderr, "unable to completely download %s\n", path); + logerror("unable to completely download %s\n", path); return status; } } if (verbose) - fprintf (stderr, "... WROTE: %d bytes, %d segments, avg %d\n", + logerror("... WROTE: %d bytes, %d segments, avg %d\n", ctx.total, ctx.count, ctx.total / ctx.count); /* now reset the CPU so it runs what we just downloaded */ if (!ezusb_cpucs (fd, cpucs_addr, 1)) return -1; @@ -605,18 +604,18 @@ struct eeprom_poke_context *ctx = context; int rc; unsigned char header [4]; if (external) { - fprintf (stderr, + logerror( "EEPROM can't init %d bytes external memory at 0x%04x\n", len, addr); return -EINVAL; } if (len > 1023) { - fprintf (stderr, "not fragmenting %d bytes\n", len); + logerror("not fragmenting %d bytes\n", len); return -EDOM; } /* NOTE: No retries here. They don't seem to be needed; * could be added if that changes. @@ -668,26 +667,26 @@ return -1; } image = fopen (path, "r"); if (image == 0) { - fprintf (stderr, "%s: unable to open for input.\n", path); + logerror("%s: unable to open for input.\n", path); return -2; } else if (verbose) - fprintf (stderr, "open EEPROM hexfile image %s\n", path); + logerror("open EEPROM hexfile image %s\n", path); if (verbose) - fprintf (stderr, "2nd stage: write boot EEPROM\n"); + logerror("2nd stage: write boot EEPROM\n"); /* EZ-USB family devices differ, apart from the 8051 core */ if (strcmp ("fx2", type) == 0) { first_byte = 0xC2; cpucs_addr = 0xe600; is_external = fx2_is_external; ctx.ee_addr = 8; config &= 0x4f; - fprintf (stderr, + logerror( "FX2: config = 0x%02x, %sconnected, I2C = %d KHz\n", config, (config & 0x40) ? "dis" : "", // NOTE: old chiprevs let CPU clock speed be set // or cycle inverted here. You shouldn't use those. @@ -699,11 +698,11 @@ first_byte = 0xB6; cpucs_addr = 0x7f92; is_external = fx_is_external; ctx.ee_addr = 9; config &= 0x07; - fprintf (stderr, + logerror( "FX: config = 0x%02x, %d MHz%s, I2C = %d KHz\n", config, ((config & 0x04) ? 48 : 24), (config & 0x02) ? " inverted" : "", (config & 0x01) ? 400 : 100 @@ -713,14 +712,14 @@ first_byte = 0xB2; cpucs_addr = 0x7f92; is_external = fx_is_external; ctx.ee_addr = 7; config = 0; - fprintf (stderr, "AN21xx: no EEPROM config byte\n"); + logerror("AN21xx: no EEPROM config byte\n"); } else { - fprintf (stderr, "?? Unrecognized microcontroller type %s ??\n", type); + logerror("?? Unrecognized microcontroller type %s ??\n", type); return -1; } /* make sure the EEPROM won't be used for booting, * in case of problems writing it @@ -734,20 +733,20 @@ /* scan the image, write to EEPROM */ ctx.device = dev; ctx.last = 0; status = parse_ihex (image, &ctx, is_external, eeprom_poke); if (status < 0) { - fprintf (stderr, "unable to write EEPROM %s\n", path); + logerror("unable to write EEPROM %s\n", path); return status; } /* append a reset command */ value = 0; ctx.last = 1; status = eeprom_poke (&ctx, cpucs_addr, 0, &value, sizeof value); if (status < 0) { - fprintf (stderr, "unable to append reset to EEPROM %s\n", path); + logerror("unable to append reset to EEPROM %s\n", path); return status; } /* write the config byte for FX, FX2 */ if (strcmp ("an21", type) != 0) { diff -u -U 5 -r --new-file -x *~ -X /tmp/diffexclude fxload-2002_04_11/fxload.8 fxload-2002_04_11.doj/fxload.8 --- fxload-2002_04_11/fxload.8 Fri Apr 12 06:08:01 2002 +++ fxload-2002_04_11.doj/fxload.8 Sun Sep 5 14:49:37 2004 @@ -26,10 +26,11 @@ .SH "NAME" fxload \- Firmware download to EZ-USB devices .SH "SYNOPSIS" .B fxload .BI "[ \-v ]" +.BI "[ \-l ]" .BI "[ \-D " devpath " ]" .BI "[ \-I " hexfile " ]" .BI "[ \-t " type " ]" .BI "[ \-c " config " ]" .BI "[ \-s " loader " ]" @@ -170,10 +171,13 @@ .B "\-v" Prints some diagnostics, such as download addresses and sizes, to standard error. Repeat the flag .RB ( -vv ", " -vvv ) to get more diagnostics. +.TP +.B "\-l" +print error and verbose messages to syslog. .TP .BI "\-D " devpath Specifies the "usbfs" path name for the device in question, such as .IR /proc/bus/usb/004/080 . diff -u -U 5 -r --new-file -x *~ -X /tmp/diffexclude fxload-2002_04_11/main.c fxload-2002_04_11.doj/main.c --- fxload-2002_04_11/main.c Fri Apr 12 06:08:01 2002 +++ fxload-2002_04_11.doj/main.c Sun Sep 5 14:49:37 2004 @@ -62,10 +62,25 @@ #ifndef FXLOAD_VERSION # define FXLOAD_VERSION (__DATE__ " (development)") #endif +#include +#include +#include +static int dosyslog=0; +void logerror(char *format, ...) +{ + va_list ap; + va_start(ap, format); + if(dosyslog) + vsyslog(LOG_ERR, format, ap); + else + vfprintf(stderr, format, ap); + va_end(ap); +} + int main(int argc, char*argv[]) { const char *link_path = 0; const char *ihex_path = 0; const char *device_path = getenv("DEVICE"); @@ -73,11 +88,11 @@ const char *stage1 = 0; mode_t mode = 0; int opt; int config = -1; - while ((opt = getopt (argc, argv, "2vV?D:I:L:c:m:s:t:")) != EOF) + while ((opt = getopt (argc, argv, "2vV?D:I:L:c:lm:s:t:")) != EOF) switch (opt) { case '2': // original version of "-t fx2" type = "fx2"; break; @@ -99,17 +114,20 @@ return 0; case 'c': config = strtoul (optarg, 0, 0); if (config < 0 || config > 255) { - fputs ("illegal config byte: ", stderr); - fputs (optarg, stderr); - fputs ("\n", stderr); + logerror("illegal config byte: %s\n", optarg); goto usage; } break; + case 'l': + openlog(argv[0], LOG_CONS|LOG_NOWAIT|LOG_PERROR, LOG_USER); + dosyslog=1; + break; + case 'm': mode = strtoul(optarg,0,0); mode &= 0777; break; @@ -120,13 +138,11 @@ case 't': if (strcmp (optarg, "an21") // original AnchorChips parts && strcmp (optarg, "fx") // updated Cypress versions && strcmp (optarg, "fx2") // Cypress USB 2.0 versions ) { - fputs ("illegal microcontroller type: ", stderr); - fputs (optarg, stderr); - fputs ("\n", stderr); + logerror("illegal microcontroller type: %s\n", optarg); goto usage; } type = optarg; break; @@ -140,32 +156,29 @@ } if (config >= 0) { if (type == 0) { - fputs ("must specify microcontroller type to write EEPROM!\n", - stderr); + logerror("must specify microcontroller type to write EEPROM!\n"); goto usage; } if (!stage1 || !ihex_path) { - fputs ("need 2nd stage loader and firmware to write EEPROM!\n", - stderr); + logerror("need 2nd stage loader and firmware to write EEPROM!\n"); goto usage; } if (link_path || mode) { - fputs ("links and modes not set up when writing EEPROM\n", - stderr); + logerror("links and modes not set up when writing EEPROM\n"); goto usage; } } if (!device_path) { - fputs ("no device specified!\n", stderr); + logerror("no device specified!\n"); usage: fputs ("usage: ", stderr); fputs (argv [0], stderr); - fputs (" [-vV] [-t type] [-D devpath]\n", stderr); + fputs (" [-vV] [-l] [-t type] [-D devpath]\n", stderr); fputs ("\t\t[-I firmware_hexfile] ", stderr); fputs ("[-s loader] [-c config_byte]\n", stderr); fputs ("\t\t[-L link] [-m mode]\n", stderr); fputs ("... [-D devpath] overrides DEVICE= in env\n", stderr); fputs ("... device types: one of an21, fx, fx2\n", stderr); @@ -177,27 +190,27 @@ int fd = open(device_path, O_RDWR); int status; int fx2; if (fd == -1) { - perror(device_path); + logerror("%s : %s\n", strerror(errno), device_path); return -1; } if (type == 0) { type = "fx"; /* an21-compatible for most purposes */ fx2 = 0; } else fx2 = (strcmp (type, "fx2") == 0); if (verbose) - fprintf (stderr, "microcontroller type: %s\n", type); + logerror("microcontroller type: %s\n", type); if (stage1) { /* first stage: put loader into internal memory */ if (verbose) - fprintf (stderr, "1st stage: load 2nd stage loader\n"); + logerror("1st stage: load 2nd stage loader\n"); status = ezusb_load_ram (fd, stage1, fx2, 0); if (status != 0) return status; /* second stage ... write either EEPROM, or RAM. */ @@ -208,11 +221,11 @@ if (status != 0) return status; } else { /* single stage, put into internal memory */ if (verbose) - fprintf (stderr, "single stage: load on-chip memory\n"); + logerror("single stage: load on-chip memory\n"); status = ezusb_load_ram (fd, ihex_path, fx2, 0); if (status != 0) return status; } @@ -223,25 +236,25 @@ if (link_path) { int rc = unlink(link_path); rc = symlink(device_path, link_path); if (rc == -1) { - perror(link_path); + logerror("%s : %s\n", strerror(errno), link_path); return -1; } } if (mode != 0) { int rc = chmod(device_path, mode); if (rc == -1) { - perror(link_path); + logerror("%s : %s\n", strerror(errno), link_path); return -1; } } if (!ihex_path && !link_path && !mode) { - fputs ("missing request! (firmware, link, or mode)\n", stderr); + logerror("missing request! (firmware, link, or mode)\n"); return -1; } return 0; } @@ -274,6 +287,5 @@ * Added the fxload program. * Rework root makefile and hotplug.spec to install in prefix * location without need of spec file for install. * */ -