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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

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/types.h>
 
21
#include <grub/dl.h>
 
22
#include <grub/misc.h>
 
23
#include <grub/mm.h>
 
24
#include <grub/usb.h>
 
25
#include <grub/usbserial.h>
 
26
 
 
27
enum
 
28
  {
 
29
    GRUB_FTDI_MODEM_CTRL = 0x01,
 
30
    GRUB_FTDI_FLOW_CTRL = 0x02,
 
31
    GRUB_FTDI_SPEED_CTRL = 0x03,
 
32
    GRUB_FTDI_DATA_CTRL = 0x04
 
33
  };
 
34
 
 
35
#define GRUB_FTDI_MODEM_CTRL_DTRRTS 3
 
36
#define GRUB_FTDI_FLOW_CTRL_DTRRTS 3
 
37
 
 
38
/* Convert speed to divisor.  */
 
39
static grub_uint32_t
 
40
get_divisor (unsigned int speed)
 
41
{
 
42
  unsigned int i;
 
43
 
 
44
  /* The structure for speed vs. divisor.  */
 
45
  struct divisor
 
46
  {
 
47
    unsigned int speed;
 
48
    grub_uint32_t div;
 
49
  };
 
50
 
 
51
  /* The table which lists common configurations.  */
 
52
  /* Computed with a division formula with 3MHz as base frequency. */
 
53
  static struct divisor divisor_tab[] =
 
54
    {
 
55
      { 2400,   0x04e2 },
 
56
      { 4800,   0x0271 },
 
57
      { 9600,   0x4138 },
 
58
      { 19200,  0x809c },
 
59
      { 38400,  0xc04e },
 
60
      { 57600,  0xc034 },
 
61
      { 115200, 0x001a }
 
62
    };
 
63
 
 
64
  /* Set the baud rate.  */
 
65
  for (i = 0; i < ARRAY_SIZE (divisor_tab); i++)
 
66
    if (divisor_tab[i].speed == speed)
 
67
      return divisor_tab[i].div;
 
68
  return 0;
 
69
}
 
70
 
 
71
static void
 
72
real_config (struct grub_serial_port *port)
 
73
{
 
74
  grub_uint32_t divisor;
 
75
  const grub_uint16_t parities[] = {
 
76
    [GRUB_SERIAL_PARITY_NONE] = 0x0000,
 
77
    [GRUB_SERIAL_PARITY_ODD] = 0x0100,
 
78
    [GRUB_SERIAL_PARITY_EVEN] = 0x0200
 
79
  };
 
80
  const grub_uint16_t stop_bits[] = {
 
81
    [GRUB_SERIAL_STOP_BITS_1] = 0x0000,
 
82
    [GRUB_SERIAL_STOP_BITS_2] = 0x1000,
 
83
  };
 
84
 
 
85
  if (port->configured)
 
86
    return;
 
87
 
 
88
  grub_usb_control_msg (port->usbdev, GRUB_USB_REQTYPE_VENDOR_OUT,
 
89
                        GRUB_FTDI_MODEM_CTRL,
 
90
                        GRUB_FTDI_MODEM_CTRL_DTRRTS, 0, 0, 0);
 
91
 
 
92
  grub_usb_control_msg (port->usbdev, GRUB_USB_REQTYPE_VENDOR_OUT,
 
93
                        GRUB_FTDI_FLOW_CTRL,
 
94
                        GRUB_FTDI_FLOW_CTRL_DTRRTS, 0, 0, 0);
 
95
 
 
96
  divisor = get_divisor (port->config.speed);
 
97
  grub_usb_control_msg (port->usbdev, GRUB_USB_REQTYPE_VENDOR_OUT,
 
98
                        GRUB_FTDI_SPEED_CTRL,
 
99
                        divisor & 0xffff, divisor >> 16, 0, 0);
 
100
 
 
101
  grub_usb_control_msg (port->usbdev, GRUB_USB_REQTYPE_VENDOR_OUT,
 
102
                        GRUB_FTDI_DATA_CTRL,
 
103
                        parities[port->config.parity]
 
104
                        | stop_bits[port->config.stop_bits]
 
105
                        | port->config.word_len, 0, 0, 0);
 
106
 
 
107
  port->configured = 1;
 
108
}
 
109
 
 
110
/* Fetch a key.  */
 
111
static int
 
112
ftdi_hw_fetch (struct grub_serial_port *port)
 
113
{
 
114
  real_config (port);
 
115
 
 
116
  return grub_usbserial_fetch (port, 2);
 
117
}
 
118
 
 
119
/* Put a character.  */
 
120
static void
 
121
ftdi_hw_put (struct grub_serial_port *port, const int c)
 
122
{
 
123
  char cc = c;
 
124
 
 
125
  real_config (port);
 
126
 
 
127
  grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc);
 
128
}
 
129
 
 
130
static grub_err_t
 
131
ftdi_hw_configure (struct grub_serial_port *port,
 
132
                        struct grub_serial_config *config)
 
133
{
 
134
  grub_uint16_t divisor;
 
135
 
 
136
  divisor = get_divisor (config->speed);
 
137
  if (divisor == 0)
 
138
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad speed");
 
139
 
 
140
  if (config->parity != GRUB_SERIAL_PARITY_NONE
 
141
      && config->parity != GRUB_SERIAL_PARITY_ODD
 
142
      && config->parity != GRUB_SERIAL_PARITY_EVEN)
 
143
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported parity");
 
144
 
 
145
  if (config->stop_bits != GRUB_SERIAL_STOP_BITS_1
 
146
      && config->stop_bits != GRUB_SERIAL_STOP_BITS_2)
 
147
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported stop bits");
 
148
 
 
149
  if (config->word_len < 5 || config->word_len > 8)
 
150
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "unsupported word length");
 
151
 
 
152
  port->config = *config;
 
153
  port->configured = 0;
 
154
 
 
155
  return GRUB_ERR_NONE;
 
156
}
 
157
 
 
158
static struct grub_serial_driver grub_ftdi_driver =
 
159
  {
 
160
    .configure = ftdi_hw_configure,
 
161
    .fetch = ftdi_hw_fetch,
 
162
    .put = ftdi_hw_put,
 
163
    .fini = grub_usbserial_fini
 
164
  };
 
165
 
 
166
static const struct 
 
167
{
 
168
  grub_uint16_t vendor, product;
 
169
} products[] =
 
170
  {
 
171
    {0x0403, 0x6001} /* QEMU virtual USBserial.  */
 
172
  };
 
173
 
 
174
static int
 
175
grub_ftdi_attach (grub_usb_device_t usbdev, int configno, int interfno)
 
176
{
 
177
  unsigned j;
 
178
 
 
179
  for (j = 0; j < ARRAY_SIZE (products); j++)
 
180
    if (usbdev->descdev.vendorid == products[j].vendor
 
181
        && usbdev->descdev.prodid == products[j].product)
 
182
      break;
 
183
  if (j == ARRAY_SIZE (products))
 
184
    return 0;
 
185
 
 
186
  return grub_usbserial_attach (usbdev, configno, interfno,
 
187
                                &grub_ftdi_driver);
 
188
}
 
189
 
 
190
static struct grub_usb_attach_desc attach_hook =
 
191
{
 
192
  .class = 0xff,
 
193
  .hook = grub_ftdi_attach
 
194
};
 
195
 
 
196
GRUB_MOD_INIT(usbserial_ftdi)
 
197
{
 
198
  grub_usb_register_attach_hook_class (&attach_hook);
 
199
}
 
200
 
 
201
GRUB_MOD_FINI(usbserial_ftdi)
 
202
{
 
203
  grub_serial_unregister_driver (&grub_ftdi_driver);
 
204
  grub_usb_unregister_attach_hook_class (&attach_hook);
 
205
}