/* December 2003 -- patched by for SAGEM */ /* $Id: eagleflash.c,v 1.6 2003/11/22 09:11:55 damien Exp $ */ /*- * Copyright (c) 2003, Damien Bergamini * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice unmodified, this list of conditions, and the following * disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __RCSID("$Id: eagleflash.c,v 1.6 2003/11/22 09:11:55 damien Exp $"); #include #include #include #include #include #include #include #include #include #include "firmware.h" #define ANCHOR_LOAD_INTERNAL 0xa0 #define ANCHOR_CPUCS_REG 0x7f92 #define ANCHOR_RESET 0x01 static void usage(void); static void flash(int, struct ezdata *); int main(int argc, char **argv) { int fd; setprogname(argv[0]); if (argc != 2) usage(); if ((fd = open(argv[1], O_WRONLY)) == -1) err(EX_OSERR, "%s", argv[1]); flash(fd, fw_eagleII); (void)close(fd); return EX_OK; } static void usage(void) { (void)fprintf(stderr, "usage: %s device\n", getprogname()); exit(EX_USAGE); } static void flash(int fd, struct ezdata *firmware) { struct usb_ctl_request ucr; u_int8_t rst; ucr.ucr_request.bmRequestType = UT_WRITE_VENDOR_DEVICE; ucr.ucr_request.bRequest = ANCHOR_LOAD_INTERNAL; USETW(ucr.ucr_request.wIndex, 0); ucr.ucr_flags = 0; rst = ANCHOR_RESET; USETW(ucr.ucr_request.wValue, ANCHOR_CPUCS_REG); USETW(ucr.ucr_request.wLength, 1); ucr.ucr_data = &rst; if (ioctl(fd, USB_DO_REQUEST, &ucr) == -1) err(EX_OSERR, "ioctl(USB_DO_REQUEST)"); (void)usleep(250000); for (; firmware->length > 0; firmware++) { USETW(ucr.ucr_request.wValue, firmware->address); USETW(ucr.ucr_request.wLength, firmware->length); ucr.ucr_data = firmware->data; if (ioctl(fd, USB_DO_REQUEST, &ucr) == -1) err(EX_OSERR, "ioctl(USB_DO_REQUEST)"); } (void)usleep(250000); rst = 0; USETW(ucr.ucr_request.wValue, ANCHOR_CPUCS_REG); USETW(ucr.ucr_request.wLength, 1); ucr.ucr_data = &rst; if (ioctl(fd, USB_DO_REQUEST, &ucr) == -1) err(EX_OSERR, "ioctl(USB_DO_REQUEST)"); }