~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/bus/usb/serial/common.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010  Free Software Foundation, Inc.
 
4
 *
 
5
 *  GRUB is free software: you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation, either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  GRUB is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <grub/serial.h>
 
20
#include <grub/usbserial.h>
 
21
 
 
22
void
 
23
grub_usbserial_fini (struct grub_serial_port *port)
 
24
{
 
25
  port->usbdev->config[port->configno].interf[port->interfno].detach_hook = 0;
 
26
  port->usbdev->config[port->configno].interf[port->interfno].attached = 0;
 
27
}
 
28
 
 
29
void
 
30
grub_usbserial_detach (grub_usb_device_t usbdev, int configno, int interfno)
 
31
{
 
32
  static struct grub_serial_port *port;
 
33
  port = usbdev->config[configno].interf[interfno].detach_data;
 
34
 
 
35
  grub_serial_unregister (port);
 
36
}
 
37
 
 
38
static int usbnum = 0;
 
39
 
 
40
int
 
41
grub_usbserial_attach (grub_usb_device_t usbdev, int configno, int interfno,
 
42
                       struct grub_serial_driver *driver)
 
43
{
 
44
  struct grub_serial_port *port;
 
45
  int j;
 
46
  struct grub_usb_desc_if *interf;
 
47
  grub_usb_err_t err = GRUB_USB_ERR_NONE;
 
48
 
 
49
  interf = usbdev->config[configno].interf[interfno].descif;
 
50
 
 
51
  port = grub_malloc (sizeof (*port));
 
52
  if (!port)
 
53
    {
 
54
      grub_print_error ();
 
55
      return 0;
 
56
    }
 
57
 
 
58
  port->name = grub_xasprintf ("usb%d", usbnum++);
 
59
  if (!port->name)
 
60
    {
 
61
      grub_free (port);
 
62
      grub_print_error ();
 
63
      return 0;
 
64
    }
 
65
 
 
66
  port->usbdev = usbdev;
 
67
  port->driver = driver;
 
68
  for (j = 0; j < interf->endpointcnt; j++)
 
69
    {
 
70
      struct grub_usb_desc_endp *endp;
 
71
      endp = &usbdev->config[0].interf[interfno].descendp[j];
 
72
 
 
73
      if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
 
74
        {
 
75
          /* Bulk IN endpoint.  */
 
76
          port->in_endp = endp;
 
77
        }
 
78
      else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2)
 
79
        {
 
80
          /* Bulk OUT endpoint.  */
 
81
          port->out_endp = endp;
 
82
        }
 
83
    }
 
84
 
 
85
  /* Configure device */
 
86
  if (port->out_endp && port->in_endp)
 
87
    err = grub_usb_set_configuration (usbdev, configno + 1);
 
88
  
 
89
  if (!port->out_endp || !port->in_endp || err)
 
90
    {
 
91
      grub_free (port->name);
 
92
      grub_free (port);
 
93
      return 0;
 
94
    }
 
95
 
 
96
  port->configno = configno;
 
97
  port->interfno = interfno;
 
98
 
 
99
  grub_serial_config_defaults (port);
 
100
  grub_serial_register (port);
 
101
 
 
102
  port->usbdev->config[port->configno].interf[port->interfno].detach_hook
 
103
    = grub_usbserial_detach;
 
104
  port->usbdev->config[port->configno].interf[port->interfno].detach_data
 
105
    = port;
 
106
 
 
107
  return 1;
 
108
}
 
109
 
 
110
int
 
111
grub_usbserial_fetch (struct grub_serial_port *port, grub_size_t header_size)
 
112
{
 
113
  grub_usb_err_t err;
 
114
  grub_size_t actual;
 
115
 
 
116
  if (port->bufstart < port->bufend)
 
117
    return port->buf[port->bufstart++];
 
118
 
 
119
  err = grub_usb_bulk_read_extended (port->usbdev, port->in_endp->endp_addr,
 
120
                                     sizeof (port->buf), port->buf, 10,
 
121
                                     &actual);
 
122
  if (err != GRUB_USB_ERR_NONE)
 
123
    return -1;
 
124
 
 
125
  port->bufstart = header_size;
 
126
  port->bufend = actual;
 
127
  if (port->bufstart >= port->bufend)
 
128
    return -1;
 
129
 
 
130
  return port->buf[port->bufstart++];
 
131
}