~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to grub-core/term/ieee1275/ofconsole.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
/*  ofconsole.c -- Open Firmware console for GRUB.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2003,2004,2005,2007,2008,2009  Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  GRUB is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <grub/term.h>
 
21
#include <grub/types.h>
 
22
#include <grub/misc.h>
 
23
#include <grub/mm.h>
 
24
#include <grub/time.h>
 
25
#include <grub/terminfo.h>
 
26
#include <grub/ieee1275/console.h>
 
27
#include <grub/ieee1275/ieee1275.h>
 
28
 
 
29
static grub_ieee1275_ihandle_t stdout_ihandle;
 
30
static grub_ieee1275_ihandle_t stdin_ihandle;
 
31
 
 
32
extern struct grub_terminfo_output_state grub_ofconsole_terminfo_output;
 
33
 
 
34
struct color
 
35
{
 
36
  int red;
 
37
  int green;
 
38
  int blue;
 
39
};
 
40
 
 
41
/* Use serial colors as they are default on most firmwares and some firmwares
 
42
   ignore set-color!. Additionally output may be redirected to serial.  */
 
43
static struct color colors[] =
 
44
  {
 
45
    // {R, G, B}
 
46
    {0x00, 0x00, 0x00}, // 0 = black
 
47
    {0xA8, 0x00, 0x00}, // 1 = red
 
48
    {0x00, 0xA8, 0x00}, // 2 = green
 
49
    {0xFE, 0xFE, 0x54}, // 3 = yellow
 
50
    {0x00, 0x00, 0xA8}, // 4 = blue
 
51
    {0xA8, 0x00, 0xA8}, // 5 = magenta
 
52
    {0x00, 0xA8, 0xA8}, // 6 = cyan
 
53
    {0xFE, 0xFE, 0xFE}  // 7 = white
 
54
  };
 
55
 
 
56
static void
 
57
put (struct grub_term_output *term __attribute__ ((unused)), const int c)
 
58
{
 
59
  char chr = c;
 
60
 
 
61
  grub_ieee1275_write (stdout_ihandle, &chr, 1, 0);
 
62
}
 
63
 
 
64
static int
 
65
readkey (struct grub_term_input *term __attribute__ ((unused)))
 
66
{
 
67
  grub_uint8_t c;
 
68
  grub_ssize_t actual = 0;
 
69
 
 
70
  grub_ieee1275_read (stdin_ihandle, &c, 1, &actual);
 
71
  if (actual > 0)
 
72
    return c;
 
73
  return -1;
 
74
}
 
75
 
 
76
static void
 
77
grub_ofconsole_dimensions (void)
 
78
{
 
79
  grub_ieee1275_ihandle_t options;
 
80
  grub_ssize_t lval;
 
81
 
 
82
  if (! grub_ieee1275_finddevice ("/options", &options)
 
83
      && options != (grub_ieee1275_ihandle_t) -1)
 
84
    {
 
85
      if (! grub_ieee1275_get_property_length (options, "screen-#columns",
 
86
                                               &lval)
 
87
          && lval >= 0 && lval < 1024)
 
88
        {
 
89
          char val[lval];
 
90
 
 
91
          if (! grub_ieee1275_get_property (options, "screen-#columns",
 
92
                                            val, lval, 0))
 
93
            grub_ofconsole_terminfo_output.width
 
94
              = (grub_uint8_t) grub_strtoul (val, 0, 10);
 
95
        }
 
96
      if (! grub_ieee1275_get_property_length (options, "screen-#rows", &lval)
 
97
          && lval >= 0 && lval < 1024)
 
98
        {
 
99
          char val[lval];
 
100
          if (! grub_ieee1275_get_property (options, "screen-#rows",
 
101
                                            val, lval, 0))
 
102
            grub_ofconsole_terminfo_output.height
 
103
              = (grub_uint8_t) grub_strtoul (val, 0, 10);
 
104
        }
 
105
    }
 
106
 
 
107
  /* Use a small console by default.  */
 
108
  if (! grub_ofconsole_terminfo_output.width)
 
109
    grub_ofconsole_terminfo_output.width = 80;
 
110
  if (! grub_ofconsole_terminfo_output.height)
 
111
    grub_ofconsole_terminfo_output.height = 24;
 
112
}
 
113
 
 
114
static void
 
115
grub_ofconsole_setcursor (struct grub_term_output *term,
 
116
                          int on)
 
117
{
 
118
  grub_terminfo_setcursor (term, on);
 
119
 
 
120
  if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF))
 
121
    return;
 
122
 
 
123
  /* Understood by the Open Firmware flavour in OLPC.  */
 
124
  if (on)
 
125
    grub_ieee1275_interpret ("cursor-on", 0);
 
126
  else
 
127
    grub_ieee1275_interpret ("cursor-off", 0);
 
128
}
 
129
 
 
130
static grub_err_t
 
131
grub_ofconsole_init_input (struct grub_term_input *term)
 
132
{
 
133
  grub_ssize_t actual;
 
134
 
 
135
  if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "stdin", &stdin_ihandle,
 
136
                                          sizeof stdin_ihandle, &actual)
 
137
      || actual != sizeof stdin_ihandle)
 
138
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot find stdin");
 
139
 
 
140
  return grub_terminfo_input_init (term);
 
141
}
 
142
 
 
143
static grub_err_t
 
144
grub_ofconsole_init_output (struct grub_term_output *term)
 
145
{
 
146
  grub_ssize_t actual;
 
147
 
 
148
  /* The latest PowerMacs don't actually initialize the screen for us, so we
 
149
   * use this trick to re-open the output device (but we avoid doing this on
 
150
   * platforms where it's known to be broken). */
 
151
  if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT))
 
152
    grub_ieee1275_interpret ("output-device output", 0);
 
153
 
 
154
  if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "stdout", &stdout_ihandle,
 
155
                                          sizeof stdout_ihandle, &actual)
 
156
      || actual != sizeof stdout_ihandle)
 
157
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot find stdout");
 
158
 
 
159
  /* Initialize colors.  */
 
160
  if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS))
 
161
    {
 
162
      unsigned col;
 
163
      for (col = 0; col < ARRAY_SIZE (colors); col++)
 
164
        grub_ieee1275_set_color (stdout_ihandle, col, colors[col].red,
 
165
                                 colors[col].green, colors[col].blue);
 
166
 
 
167
      /* Set the right fg and bg colors.  */
 
168
      grub_terminfo_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
 
169
    }
 
170
 
 
171
  grub_ofconsole_dimensions ();
 
172
 
 
173
  return 0;
 
174
}
 
175
 
 
176
 
 
177
 
 
178
struct grub_terminfo_input_state grub_ofconsole_terminfo_input =
 
179
  {
 
180
    .readkey = readkey
 
181
  };
 
182
 
 
183
struct grub_terminfo_output_state grub_ofconsole_terminfo_output =
 
184
  {
 
185
    .put = put,
 
186
    .width = 80,
 
187
    .height = 24
 
188
  };
 
189
 
 
190
static struct grub_term_input grub_ofconsole_term_input =
 
191
  {
 
192
    .name = "ofconsole",
 
193
    .init = grub_ofconsole_init_input,
 
194
    .getkey = grub_terminfo_getkey,
 
195
    .data = &grub_ofconsole_terminfo_input
 
196
  };
 
197
 
 
198
static struct grub_term_output grub_ofconsole_term_output =
 
199
  {
 
200
    .name = "ofconsole",
 
201
    .init = grub_ofconsole_init_output,
 
202
    .putchar = grub_terminfo_putchar,
 
203
    .getxy = grub_terminfo_getxy,
 
204
    .getwh = grub_terminfo_getwh,
 
205
    .gotoxy = grub_terminfo_gotoxy,
 
206
    .cls = grub_terminfo_cls,
 
207
    .setcolorstate = grub_terminfo_setcolorstate,
 
208
    .setcursor = grub_ofconsole_setcursor,
 
209
    .flags = GRUB_TERM_CODE_TYPE_ASCII,
 
210
    .data = &grub_ofconsole_terminfo_output,
 
211
    .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
 
212
    .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
 
213
  };
 
214
 
 
215
void grub_terminfo_fini (void);
 
216
void grub_terminfo_init (void);
 
217
 
 
218
void
 
219
grub_console_init_early (void)
 
220
{
 
221
  grub_term_register_input ("ofconsole", &grub_ofconsole_term_input);
 
222
  grub_term_register_output ("ofconsole", &grub_ofconsole_term_output);
 
223
}
 
224
 
 
225
void
 
226
grub_console_init_lately (void)
 
227
{
 
228
  const char *type;
 
229
 
 
230
  if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_ANSI))
 
231
    type = "dumb";
 
232
  else
 
233
    type = "ieee1275";
 
234
 
 
235
  grub_terminfo_init ();
 
236
  grub_terminfo_output_register (&grub_ofconsole_term_output, type);
 
237
}
 
238
 
 
239
void
 
240
grub_console_fini (void)
 
241
{
 
242
  grub_term_unregister_input (&grub_ofconsole_term_input);
 
243
  grub_term_unregister_output (&grub_ofconsole_term_output);
 
244
  grub_terminfo_output_unregister (&grub_ofconsole_term_output);
 
245
 
 
246
  grub_terminfo_fini ();
 
247
}