2009-02-08 Marco Gerards <marco@gnu.org>
* Makefile.in (enable_grub_emu_usb): New variable. * conf/i386-pc.rmk (grub_emu_SOURCES): Add `disk/scsi.c'. (grub_emu_SOURCES) [grub_emu_SOURCES]: Add `disk/usbms.c', `util/usb.c', `bus/usb/usb.c' and `commands/usbtest.c'. (grub_emu_LDFLAGS): Add `$(LIBUSB)'. (pkglib_MODULES): Add `usb.mod', `uhci.mod', `ohci.mod', `usbtest.mod' and `usbms.mod'. (usb_mod_SOURCES, usb_mod_CFLAGS, usb_mod_LDFLAGS) (usbtest_mod_SOURCES, usbtest_mod_CFLAGS, usbtest_mod_LDFLAGS) (uhci_mod_SOURCES, uhci_mod_CFLAGS, uhci_mod_LDFLAGS, (ohci_mod_SOURCES, ohci_mod_CFLAGS, ohci_mod_LDFLAGS) (usbms_mod_SOURCES, usbms_mod_CFLAGS, usbms_mod_LDFLAGS): New variables. * disk/usbms.c: New file. * include/grub/usb.h: Likewise. * include/grub/usbtrans.h: Likewise. * include/grub/usbdesc.h: Likewise. * bus/usb/usbtrans.c: Likewise. * bus/usb/ohci.c: Likewise. * bus/usb/uhci.c: Likewise. * bus/usb/usbhub.c: Likewise. * bus/usb/usb.c: Likewise. * commands/usbtest.c: Likewise. * util/usb.c: Likewise. * include/grub/err.h (grub_err_t): Add `GRUB_ERR_IO'. * configure.ac: Test for libusb presence. * util/grub-emu.c (main) [HAVE_LIBUSB_H]: Call `grub_libusb_init'.
This commit is contained in:
parent
2b40d6bb9f
commit
d64399b562
21 changed files with 3846 additions and 16 deletions
|
@ -52,7 +52,8 @@ typedef enum
|
|||
GRUB_ERR_SYMLINK_LOOP,
|
||||
GRUB_ERR_BAD_GZIP_DATA,
|
||||
GRUB_ERR_MENU,
|
||||
GRUB_ERR_TIMEOUT
|
||||
GRUB_ERR_TIMEOUT,
|
||||
GRUB_ERR_IO
|
||||
}
|
||||
grub_err_t;
|
||||
|
||||
|
|
207
include/grub/usb.h
Normal file
207
include/grub/usb.h
Normal file
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_USB_H
|
||||
#define GRUB_USB_H 1
|
||||
|
||||
#include <grub/usbdesc.h>
|
||||
#include <grub/usbtrans.h>
|
||||
|
||||
typedef struct grub_usb_device *grub_usb_device_t;
|
||||
typedef struct grub_usb_controller *grub_usb_controller_t;
|
||||
typedef struct grub_usb_controller_dev *grub_usb_controller_dev_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USB_ERR_NONE,
|
||||
GRUB_USB_ERR_INTERNAL,
|
||||
GRUB_USB_ERR_STALL,
|
||||
GRUB_USB_ERR_DATA,
|
||||
GRUB_USB_ERR_NAK,
|
||||
GRUB_USB_ERR_BABBLE,
|
||||
GRUB_USB_ERR_TIMEOUT,
|
||||
GRUB_USB_ERR_BITSTUFF
|
||||
} grub_usb_err_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USB_SPEED_NONE,
|
||||
GRUB_USB_SPEED_LOW,
|
||||
GRUB_USB_SPEED_FULL,
|
||||
GRUB_USB_SPEED_HIGH
|
||||
} grub_usb_speed_t;
|
||||
|
||||
/* Call HOOK with each device, until HOOK returns non-zero. */
|
||||
int grub_usb_iterate (int (*hook) (grub_usb_device_t dev));
|
||||
|
||||
grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
|
||||
|
||||
grub_usb_err_t grub_usb_get_descriptor (grub_usb_device_t dev,
|
||||
grub_uint8_t type, grub_uint8_t index,
|
||||
grub_size_t size, char *data);
|
||||
|
||||
struct grub_usb_desc_endp *
|
||||
grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr);
|
||||
|
||||
grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint);
|
||||
|
||||
|
||||
grub_usb_err_t grub_usb_set_configuration (grub_usb_device_t dev,
|
||||
int configuration);
|
||||
|
||||
grub_usb_err_t grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index,
|
||||
int langid, char **string);
|
||||
|
||||
void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb);
|
||||
|
||||
void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);
|
||||
|
||||
int grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev));
|
||||
|
||||
|
||||
grub_usb_err_t grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype,
|
||||
grub_uint8_t request, grub_uint16_t value,
|
||||
grub_uint16_t index, grub_size_t size,
|
||||
char *data);
|
||||
|
||||
grub_usb_err_t
|
||||
grub_usb_bulk_read (grub_usb_device_t dev,
|
||||
int endpoint, grub_size_t size, char *data);
|
||||
grub_usb_err_t
|
||||
grub_usb_bulk_write (grub_usb_device_t dev,
|
||||
int endpoint, grub_size_t size, char *data);
|
||||
|
||||
grub_usb_err_t
|
||||
grub_usb_root_hub (grub_usb_controller_t controller);
|
||||
|
||||
|
||||
/* XXX: All handled by libusb for now. */
|
||||
struct grub_usb_controller_dev
|
||||
{
|
||||
/* The device name. */
|
||||
const char *name;
|
||||
|
||||
int (*iterate) (int (*hook) (grub_usb_controller_t dev));
|
||||
|
||||
grub_usb_err_t (*transfer) (grub_usb_controller_t dev,
|
||||
grub_usb_transfer_t transfer);
|
||||
|
||||
int (*hubports) (grub_usb_controller_t dev);
|
||||
|
||||
grub_err_t (*portstatus) (grub_usb_controller_t dev, unsigned int port,
|
||||
unsigned int enable);
|
||||
|
||||
grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port);
|
||||
|
||||
/* The next host controller. */
|
||||
struct grub_usb_controller_dev *next;
|
||||
};
|
||||
|
||||
struct grub_usb_controller
|
||||
{
|
||||
/* The underlying USB Host Controller device. */
|
||||
grub_usb_controller_dev_t dev;
|
||||
|
||||
/* Data used by the USB Host Controller Driver. */
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
||||
struct grub_usb_interface
|
||||
{
|
||||
struct grub_usb_desc_if *descif;
|
||||
|
||||
struct grub_usb_desc_endp *descendp;
|
||||
};
|
||||
|
||||
struct grub_usb_configuration
|
||||
{
|
||||
/* Configuration descriptors . */
|
||||
struct grub_usb_desc_config *descconf;
|
||||
|
||||
/* Interfaces associated to this configuration. */
|
||||
struct grub_usb_interface interf[32];
|
||||
};
|
||||
|
||||
struct grub_usb_device
|
||||
{
|
||||
/* The device descriptor of this device. */
|
||||
struct grub_usb_desc_device descdev;
|
||||
|
||||
/* The controller the device is connected to. */
|
||||
struct grub_usb_controller controller;
|
||||
|
||||
/* Device configurations (after opening the device). */
|
||||
struct grub_usb_configuration config[8];
|
||||
|
||||
/* Device address. */
|
||||
int addr;
|
||||
|
||||
/* Device speed. */
|
||||
grub_usb_speed_t speed;
|
||||
|
||||
/* All desciptors are read if this is set to 1. */
|
||||
int initialized;
|
||||
|
||||
/* Data toggle values (used for bulk transfers only). */
|
||||
int toggle[16];
|
||||
|
||||
/* Device-specific data. */
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USB_CLASS_NOTHERE,
|
||||
GRUB_USB_CLASS_AUDIO,
|
||||
GRUB_USB_CLASS_COMMUNICATION,
|
||||
GRUB_USB_CLASS_HID,
|
||||
GRUB_USB_CLASS_XXX,
|
||||
GRUB_USB_CLASS_PHYSICAL,
|
||||
GRUB_USB_CLASS_IMAGE,
|
||||
GRUB_USB_CLASS_PRINTER,
|
||||
GRUB_USB_CLASS_MASS_STORAGE,
|
||||
GRUB_USB_CLASS_HUB,
|
||||
GRUB_USB_CLASS_DATA_INTERFACE,
|
||||
GRUB_USB_CLASS_SMART_CARD,
|
||||
GRUB_USB_CLASS_CONTENT_SECURITY,
|
||||
GRUB_USB_CLASS_VIDEO
|
||||
} grub_usb_classes_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USBMS_SUBCLASS_BULK = 0x06
|
||||
} grub_usbms_subclass_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USBMS_PROTOCOL_BULK = 0x50
|
||||
} grub_usbms_protocol_t;
|
||||
|
||||
static inline struct grub_usb_desc_if *
|
||||
grub_usb_get_config_interface (struct grub_usb_desc_config *config)
|
||||
{
|
||||
struct grub_usb_desc_if *interf;
|
||||
|
||||
interf = (struct grub_usb_desc_if *) (sizeof (*config) + (char *) config);
|
||||
return interf;
|
||||
}
|
||||
|
||||
#endif /* GRUB_USB_H */
|
119
include/grub/usbdesc.h
Normal file
119
include/grub/usbdesc.h
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_USBDESC_H
|
||||
#define GRUB_USBDESC_H 1
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/symbol.h>
|
||||
|
||||
typedef enum {
|
||||
GRUB_USB_DESCRIPTOR_DEVICE = 1,
|
||||
GRUB_USB_DESCRIPTOR_CONFIG,
|
||||
GRUB_USB_DESCRIPTOR_STRING,
|
||||
GRUB_USB_DESCRIPTOR_INTERFACE,
|
||||
GRUB_USB_DESCRIPTOR_ENDPOINT,
|
||||
GRUB_USB_DESCRIPTOR_HUB = 0x29
|
||||
} grub_usb_descriptor_t;
|
||||
|
||||
struct grub_usb_desc_device
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint16_t usbrel;
|
||||
grub_uint8_t class;
|
||||
grub_uint8_t subclass;
|
||||
grub_uint8_t protocol;
|
||||
grub_uint8_t maxsize0;
|
||||
grub_uint16_t vendorid;
|
||||
grub_uint16_t prodid;
|
||||
grub_uint16_t devrel;
|
||||
grub_uint8_t strvendor;
|
||||
grub_uint8_t strprod;
|
||||
grub_uint8_t strserial;
|
||||
grub_uint8_t configcnt;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_usb_desc_config
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint16_t totallen;
|
||||
grub_uint8_t numif;
|
||||
grub_uint8_t config;
|
||||
grub_uint8_t strconfig;
|
||||
grub_uint8_t attrib;
|
||||
grub_uint8_t maxpower;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#if 0
|
||||
struct grub_usb_desc_ifassosiation
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint8_t firstif;
|
||||
grub_uint8_t ifcnt;
|
||||
grub_uint8_t class;
|
||||
grub_uint8_t subclass;
|
||||
grub_uint8_t protocol;
|
||||
grub_uint8_t function;
|
||||
} __attribute__ ((packed));
|
||||
#endif
|
||||
|
||||
struct grub_usb_desc_if
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint8_t ifnum;
|
||||
grub_uint8_t altsetting;
|
||||
grub_uint8_t endpointcnt;
|
||||
grub_uint8_t class;
|
||||
grub_uint8_t subclass;
|
||||
grub_uint8_t protocol;
|
||||
grub_uint8_t strif;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_usb_desc_endp
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint8_t endp_addr;
|
||||
grub_uint8_t attrib;
|
||||
grub_uint16_t maxpacket;
|
||||
grub_uint8_t interval;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_usb_desc_str
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint16_t str[0];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct grub_usb_usb_hubdesc
|
||||
{
|
||||
grub_uint8_t length;
|
||||
grub_uint8_t type;
|
||||
grub_uint8_t portcnt;
|
||||
grub_uint16_t characteristics;
|
||||
grub_uint8_t pwdgood;
|
||||
grub_uint8_t current;
|
||||
/* Removable and power control bits follow. */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#endif /* GRUB_USBDESC_H */
|
107
include/grub/usbtrans.h
Normal file
107
include/grub/usbtrans.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GRUB_USBTRANS_H
|
||||
#define GRUB_USBTRANS_H 1
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USB_TRANSFER_TYPE_IN,
|
||||
GRUB_USB_TRANSFER_TYPE_OUT,
|
||||
GRUB_USB_TRANSFER_TYPE_SETUP
|
||||
} grub_transfer_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRUB_USB_TRANSACTION_TYPE_CONTROL,
|
||||
GRUB_USB_TRANSACTION_TYPE_BULK
|
||||
} grub_transaction_type_t;
|
||||
|
||||
struct grub_usb_transaction
|
||||
{
|
||||
int size;
|
||||
int toggle;
|
||||
grub_transfer_type_t pid;
|
||||
char *data;
|
||||
};
|
||||
typedef struct grub_usb_transaction *grub_usb_transaction_t;
|
||||
|
||||
struct grub_usb_transfer
|
||||
{
|
||||
int devaddr;
|
||||
|
||||
int endpoint;
|
||||
|
||||
int size;
|
||||
|
||||
int transcnt;
|
||||
|
||||
int max;
|
||||
|
||||
grub_transaction_type_t type;
|
||||
|
||||
struct grub_usb_device *dev;
|
||||
|
||||
struct grub_usb_transaction *transactions;
|
||||
};
|
||||
typedef struct grub_usb_transfer *grub_usb_transfer_t;
|
||||
|
||||
|
||||
#define GRUB_USB_REQTYPE_IN (1 << 7)
|
||||
#define GRUB_USB_REQTYPE_OUT (0 << 7)
|
||||
#define GRUB_USB_REQTYPE_STANDARD (0 << 5)
|
||||
#define GRUB_USB_REQTYPE_CLASS (1 << 5)
|
||||
#define GRUB_USB_REQTYPE_VENDOR (2 << 5)
|
||||
#define GRUB_USB_REQTYPE_TARGET_DEV (0 << 0)
|
||||
#define GRUB_USB_REQTYPE_TARGET_INTERF (1 << 0)
|
||||
#define GRUB_USB_REQTYPE_TARGET_ENDP (2 << 0)
|
||||
#define GRUB_USB_REQTYPE_TARGET_OTHER (3 << 0)
|
||||
|
||||
#define GRUB_USB_REQ_GET_STATUS 0x00
|
||||
#define GRUB_USB_REQ_CLEAR_FEATURE 0x01
|
||||
#define GRUB_USB_REQ_SET_FEATURE 0x03
|
||||
#define GRUB_USB_REQ_SET_ADDRESS 0x05
|
||||
#define GRUB_USB_REQ_GET_DESCRIPTOR 0x06
|
||||
#define GRUB_USB_REQ_SET_DESCRIPTOR 0x07
|
||||
#define GRUB_USB_REQ_GET_CONFIGURATION 0x08
|
||||
#define GRUB_USB_REQ_SET_CONFIGURATION 0x09
|
||||
#define GRUB_USB_REQ_GET_INTERFACE 0x0A
|
||||
#define GRUB_USB_REQ_SET_INTERFACE 0x0B
|
||||
#define GRUB_USB_REQ_SYNC_FRAME 0x0C
|
||||
|
||||
#define GRUB_USB_REQ_HUB_GET_PORT_STATUS 0x00
|
||||
|
||||
#define GRUB_USB_FEATURE_ENDP_HALT 0x01
|
||||
#define GRUB_USB_FEATURE_DEV_REMOTE_WU 0x02
|
||||
#define GRUB_USB_FEATURE_TEST_MODE 0x04
|
||||
|
||||
#define GRUB_USB_HUB_STATUS_CONNECTED (1 << 0)
|
||||
#define GRUB_USB_HUB_STATUS_LOWSPEED (1 << 9)
|
||||
#define GRUB_USB_HUB_STATUS_HIGHSPEED (1 << 10)
|
||||
|
||||
struct grub_usb_packet_setup
|
||||
{
|
||||
grub_uint8_t reqtype;
|
||||
grub_uint8_t request;
|
||||
grub_uint16_t value;
|
||||
grub_uint16_t index;
|
||||
grub_uint16_t length;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
#endif /* GRUB_USBTRANS_H */
|
Loading…
Add table
Add a link
Reference in a new issue