diff options
-rw-r--r-- | share/man/man4/uyap.4 | 9 | ||||
-rw-r--r-- | sys/dev/microcode/uyap/Makefile | 27 | ||||
-rw-r--r-- | sys/dev/microcode/uyap/build.c | 40 | ||||
-rw-r--r-- | sys/dev/microcode/uyap/uyap-license | 34 | ||||
-rw-r--r-- | sys/dev/microcode/uyap/uyap_firmware.h | 4 | ||||
-rw-r--r-- | sys/dev/usb/ezload.c | 23 | ||||
-rw-r--r-- | sys/dev/usb/ezload.h | 9 | ||||
-rw-r--r-- | sys/dev/usb/files.usb | 4 | ||||
-rw-r--r-- | sys/dev/usb/uyap.c | 45 |
9 files changed, 164 insertions, 31 deletions
diff --git a/share/man/man4/uyap.4 b/share/man/man4/uyap.4 index a8121576f89..9f5f339f5be 100644 --- a/share/man/man4/uyap.4 +++ b/share/man/man4/uyap.4 @@ -1,4 +1,4 @@ -.\" $OpenBSD: uyap.4,v 1.4 2004/09/30 19:59:26 mickey Exp $ +.\" $OpenBSD: uyap.4,v 1.5 2004/12/19 15:20:11 deraadt Exp $ .\" $NetBSD: $ .\" .\" Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -52,6 +52,13 @@ two audio pipes (handled by .Xr uaudio 4 ) and an HID device (handled by .Xr uhid 4 ) . +.Sh FILES +The driver need a firmware file, +which is loaded on demand when the device is attached: +.Pp +.Bl -tag -width Ds -offset indent -compact +.It Pa /etc/firmware/uyap +.El .Sh SEE ALSO .Xr intro 4 , .Xr uaudio 4 , diff --git a/sys/dev/microcode/uyap/Makefile b/sys/dev/microcode/uyap/Makefile new file mode 100644 index 00000000000..8aa599e274b --- /dev/null +++ b/sys/dev/microcode/uyap/Makefile @@ -0,0 +1,27 @@ +# $OpenBSD: Makefile,v 1.1 2004/12/19 15:20:13 deraadt Exp $ + +NOPROG= +NOMAN= + +# USB capable systems only +.if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \ + (${MACHINE} == "alpha") || (${MACHINE} == "sparc64") || \ + (${MACHINE_ARCH} == "powerpc") || (${MACHINE} == "cats") || \ + (${MACHINE} == "hppa") || (${MACHINE} == "sgi") + +FIRM= uyap + +CLEANFILES+= ${FIRM} build + +all: build + ${.OBJDIR}/build + +afterinstall: + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \ + ${FIRM} ${DESTDIR}/etc/firmware + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \ + ${.CURDIR}/uyap-license ${DESTDIR}/etc/firmware +.endif + +.include <bsd.prog.mk> + diff --git a/sys/dev/microcode/uyap/build.c b/sys/dev/microcode/uyap/build.c new file mode 100644 index 00000000000..30fc01ba80f --- /dev/null +++ b/sys/dev/microcode/uyap/build.c @@ -0,0 +1,40 @@ +/* $OpenBSD: build.c,v 1.1 2004/12/19 15:20:13 deraadt Exp $ */ + +/* + * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <sys/types.h> +#include <fcntl.h> +#include <sys/param.h> + +#include <dev/usb/ezload.h> +#include "uyap_firmware.h" +#define FILENAME "uyap" + +int +main(int argc, char *argv[]) +{ + int i; + int fd; + + printf("creating %s length %d\n", FILENAME, sizeof uyap_firmware); + fd = open(FILENAME, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) + err(1, "%s", FILENAME); + + write(fd, uyap_firmware, sizeof uyap_firmware); + close(fd); + return 0; +} diff --git a/sys/dev/microcode/uyap/uyap-license b/sys/dev/microcode/uyap/uyap-license new file mode 100644 index 00000000000..38aaf9363e1 --- /dev/null +++ b/sys/dev/microcode/uyap/uyap-license @@ -0,0 +1,34 @@ + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Silicon Portals. + * + * 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, 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + diff --git a/sys/dev/microcode/uyap/uyap_firmware.h b/sys/dev/microcode/uyap/uyap_firmware.h index a42a54250fb..064b3101c03 100644 --- a/sys/dev/microcode/uyap/uyap_firmware.h +++ b/sys/dev/microcode/uyap/uyap_firmware.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uyap_firmware.h,v 1.1 2001/12/17 01:39:08 deraadt Exp $ */ +/* $OpenBSD: uyap_firmware.h,v 1.2 2004/12/19 15:20:13 deraadt Exp $ */ /* $NetBSD: uyap_firmware.h,v 1.2 2001/01/16 03:10:09 augustss Exp $ */ /* @@ -37,6 +37,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +const struct ezdata uyap_firmware[] = { {0x10,0x146C, "\xC2\x00\x90\x7F\xA5\xE0\x54\x18\xFF\x13\x13\x13\x54\x1F\x44\x50"}, {0x10,0x147C, @@ -1234,3 +1235,4 @@ {0x01,0x02F1, "\x00"}, {0x00,0x0000,""} +}; diff --git a/sys/dev/usb/ezload.c b/sys/dev/usb/ezload.c index 859ae4a4a92..0640d344a1d 100644 --- a/sys/dev/usb/ezload.c +++ b/sys/dev/usb/ezload.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ezload.c,v 1.6 2002/07/25 04:07:32 nate Exp $ */ +/* $OpenBSD: ezload.c,v 1.7 2004/12/19 15:20:13 deraadt Exp $ */ /* $NetBSD: ezload.c,v 1.5 2002/07/11 21:14:25 augustss Exp $ */ /* @@ -41,6 +41,7 @@ #include <sys/systm.h> #include <sys/kernel.h> #include <sys/device.h> +#include <sys/malloc.h> #include <sys/conf.h> #include <dev/usb/usb.h> @@ -106,12 +107,14 @@ ezload_reset(usbd_device_handle dev, int reset) } usbd_status -ezload_download(usbd_device_handle dev, const struct ezdata *rec) +ezload_download(usbd_device_handle dev, const char *name, const u_char *buf, + size_t buflen) { usb_device_request_t req; const struct ezdata *ptr; usbd_status err; u_int len, offs; + const struct ezdata *rec = (struct ezdata *)buf; DPRINTF(("ezload_down record=%p\n", rec)); @@ -145,19 +148,29 @@ ezload_download(usbd_device_handle dev, const struct ezdata *rec) } usbd_status -ezload_downloads_and_reset(usbd_device_handle dev, const struct ezdata **recs) +ezload_downloads_and_reset(usbd_device_handle dev, char **names) { usbd_status err; + size_t buflen; + u_char *buf; + int error; /*(void)ezload_reset(dev, 1);*/ err = ezload_reset(dev, 1); if (err) return (err); usbd_delay_ms(dev, 250); - while (*recs != NULL) { - err = ezload_download(dev, *recs++); + + while (*names != NULL) { + error = loadfirmware(*names, &buf, &buflen); + if (error) + return (error); + + err = ezload_download(dev, *names, buf, buflen); + free(buf, M_DEVBUF); if (err) return (err); + names++; } if (err) return (err); diff --git a/sys/dev/usb/ezload.h b/sys/dev/usb/ezload.h index e62e4cb6569..de2797181be 100644 --- a/sys/dev/usb/ezload.h +++ b/sys/dev/usb/ezload.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ezload.h,v 1.2 2001/05/03 02:20:32 aaron Exp $ */ +/* $OpenBSD: ezload.h,v 1.3 2004/12/19 15:20:13 deraadt Exp $ */ /* $NetBSD: ezload.h,v 1.2 2001/01/18 20:28:23 jdolecek Exp $ */ /* @@ -43,6 +43,9 @@ struct ezdata { u_int8_t *data; }; +#ifdef _KERNEL usbd_status ezload_reset(usbd_device_handle, int); -usbd_status ezload_download(usbd_device_handle, const struct ezdata *); -usbd_status ezload_downloads_and_reset(usbd_device_handle, const struct ezdata **); +usbd_status ezload_download(usbd_device_handle, const char *name, + const u_char *buf, size_t buflen); +usbd_status ezload_downloads_and_reset(usbd_device_handle, char **); +#endif diff --git a/sys/dev/usb/files.usb b/sys/dev/usb/files.usb index 30f43564f22..19c0340b729 100644 --- a/sys/dev/usb/files.usb +++ b/sys/dev/usb/files.usb @@ -1,4 +1,4 @@ -# $OpenBSD: files.usb,v 1.41 2004/11/22 18:49:05 deraadt Exp $ +# $OpenBSD: files.usb,v 1.42 2004/12/19 15:20:13 deraadt Exp $ # $NetBSD: files.usb,v 1.16 2000/02/14 20:29:54 augustss Exp $ # # Config file and device description for machine-independent USB code. @@ -108,7 +108,7 @@ attach uvisor at uhub file dev/usb/uvisor.c uvisor # YAP phone firmware loader -device uyap: ezload +device uyap: ezload, firmload attach uyap at uhub file dev/usb/uyap.c uyap diff --git a/sys/dev/usb/uyap.c b/sys/dev/usb/uyap.c index 846c519e421..a03903edf25 100644 --- a/sys/dev/usb/uyap.c +++ b/sys/dev/usb/uyap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uyap.c,v 1.7 2003/05/07 04:33:33 deraadt Exp $ */ +/* $OpenBSD: uyap.c,v 1.8 2004/12/19 15:20:13 deraadt Exp $ */ /* $NetBSD: uyap.c,v 1.6 2002/07/11 21:14:37 augustss Exp $ */ /* @@ -50,20 +50,13 @@ #include <dev/usb/ezload.h> -const struct ezdata uyap_firmware[] = { -#if defined(__OpenBSD__) -#include "dev/microcode/uyap/uyap_firmware.h" -#else -#include "dev/usb/uyap_firmware.h" -#endif -}; -const struct ezdata *uyap_firmwares[] = { uyap_firmware, NULL }; - struct uyap_softc { USBBASEDEVICE sc_dev; /* base device */ + usbd_device_handle sc_udev; }; USB_DECLARE_DRIVER(uyap); +void uyap_attachhook(void *); USB_MATCH(uyap) { @@ -80,11 +73,28 @@ USB_MATCH(uyap) return (UMATCH_NONE); } +void +uyap_attachhook(void *xsc) +{ + char *firmwares[] = { "uyap", NULL }; + struct uyap_softc *sc = xsc; + int err; + + err = ezload_downloads_and_reset(sc->sc_udev, firmwares); + if (err) { + printf("%s: download ezdata format firmware error: %s\n", + USBDEVNAME(sc->sc_dev), usbd_errstr(err)); + USB_ATTACH_ERROR_RETURN; + } + + printf("%s: firmware download complete, disconnecting.\n", + USBDEVNAME(sc->sc_dev)); +} + USB_ATTACH(uyap) { USB_ATTACH_START(uyap, sc, uaa); usbd_device_handle dev = uaa->device; - usbd_status err; char devinfo[1024]; usbd_devinfo(dev, 0, devinfo, sizeof devinfo); @@ -92,15 +102,12 @@ USB_ATTACH(uyap) printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo); printf("%s: downloading firmware\n", USBDEVNAME(sc->sc_dev)); - err = ezload_downloads_and_reset(dev, uyap_firmwares); - if (err) { - printf("%s: download ezdata error: %s\n", - USBDEVNAME(sc->sc_dev), usbd_errstr(err)); - USB_ATTACH_ERROR_RETURN; - } + sc->sc_udev = dev; + if (rootvp == NULL) + mountroothook_establish(uyap_attachhook, sc); + else + uyap_attachhook(sc); - printf("%s: firmware download complete, disconnecting.\n", - USBDEVNAME(sc->sc_dev)); USB_ATTACH_SUCCESS_RETURN; } |