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

« back to all changes in this revision

Viewing changes to grub-core/disk/ieee1275/nand.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
/* nand.c - NAND flash disk access.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 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/misc.h>
 
21
#include <grub/disk.h>
 
22
#include <grub/mm.h>
 
23
#include <grub/dl.h>
 
24
#include <grub/ieee1275/ieee1275.h>
 
25
 
 
26
struct grub_nand_data
 
27
{
 
28
  grub_ieee1275_ihandle_t handle;
 
29
  grub_uint32_t block_size;
 
30
};
 
31
 
 
32
static int
 
33
grub_nand_iterate (int (*hook) (const char *name))
 
34
{
 
35
  auto int dev_iterate (struct grub_ieee1275_devalias *alias);
 
36
  int dev_iterate (struct grub_ieee1275_devalias *alias)
 
37
    {
 
38
      if (! grub_strcmp (alias->name, "nand"))
 
39
        {
 
40
          hook (alias->name);
 
41
          return 1;
 
42
        }
 
43
 
 
44
      return 0;
 
45
    }
 
46
 
 
47
  return grub_devalias_iterate (dev_iterate);
 
48
}
 
49
 
 
50
static grub_err_t
 
51
grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
 
52
                grub_size_t size, char *buf);
 
53
 
 
54
static grub_err_t
 
55
grub_nand_open (const char *name, grub_disk_t disk)
 
56
{
 
57
  grub_ieee1275_ihandle_t dev_ihandle = 0;
 
58
  struct grub_nand_data *data = 0;
 
59
  struct size_args
 
60
    {
 
61
      struct grub_ieee1275_common_hdr common;
 
62
      grub_ieee1275_cell_t method;
 
63
      grub_ieee1275_cell_t ihandle;
 
64
      grub_ieee1275_cell_t result;
 
65
      grub_ieee1275_cell_t size1;
 
66
      grub_ieee1275_cell_t size2;
 
67
    } args;
 
68
 
 
69
  if (! grub_strstr (name, "nand"))
 
70
    return  grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a NAND device");
 
71
 
 
72
  data = grub_malloc (sizeof (*data));
 
73
  if (! data)
 
74
    goto fail;
 
75
 
 
76
  grub_ieee1275_open (name, &dev_ihandle);
 
77
  if (! dev_ihandle)
 
78
    {
 
79
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
 
80
      goto fail;
 
81
    }
 
82
 
 
83
  data->handle = dev_ihandle;
 
84
 
 
85
  INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 2);
 
86
  args.method = (grub_ieee1275_cell_t) "block-size";
 
87
  args.ihandle = dev_ihandle;
 
88
  args.result = 1;
 
89
 
 
90
  if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
 
91
    {
 
92
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't get block size");
 
93
      goto fail;
 
94
    }
 
95
 
 
96
  data->block_size = (args.size1 >> GRUB_DISK_SECTOR_BITS);
 
97
 
 
98
  INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
 
99
  args.method = (grub_ieee1275_cell_t) "size";
 
100
  args.ihandle = dev_ihandle;
 
101
  args.result = 1;
 
102
 
 
103
  if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
 
104
    {
 
105
      grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't get disk size");
 
106
      goto fail;
 
107
    }
 
108
 
 
109
  disk->total_sectors = args.size1;
 
110
  disk->total_sectors <<= 32;
 
111
  disk->total_sectors += args.size2;
 
112
  disk->total_sectors >>= GRUB_DISK_SECTOR_BITS;
 
113
 
 
114
  disk->id = dev_ihandle;
 
115
 
 
116
  disk->data = data;
 
117
 
 
118
  return 0;
 
119
 
 
120
fail:
 
121
  if (dev_ihandle)
 
122
    grub_ieee1275_close (dev_ihandle);
 
123
  grub_free (data);
 
124
  return grub_errno;
 
125
}
 
126
 
 
127
static void
 
128
grub_nand_close (grub_disk_t disk)
 
129
{
 
130
  grub_ieee1275_close (((struct grub_nand_data *) disk->data)->handle);
 
131
  grub_free (disk->data);
 
132
}
 
133
 
 
134
static grub_err_t
 
135
grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
 
136
                grub_size_t size, char *buf)
 
137
{
 
138
  struct grub_nand_data *data = disk->data;
 
139
  grub_size_t bsize, ofs;
 
140
 
 
141
  struct read_args
 
142
    {
 
143
      struct grub_ieee1275_common_hdr common;
 
144
      grub_ieee1275_cell_t method;
 
145
      grub_ieee1275_cell_t ihandle;
 
146
      grub_ieee1275_cell_t ofs;
 
147
      grub_ieee1275_cell_t page;
 
148
      grub_ieee1275_cell_t len;
 
149
      grub_ieee1275_cell_t buf;
 
150
      grub_ieee1275_cell_t result;
 
151
    } args;
 
152
 
 
153
  INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1);
 
154
  args.method = (grub_ieee1275_cell_t) "pio-read";
 
155
  args.ihandle = data->handle;
 
156
  args.buf = (grub_ieee1275_cell_t) buf;
 
157
  args.page = (grub_ieee1275_cell_t) ((grub_size_t) sector / data->block_size);
 
158
 
 
159
  ofs = ((grub_size_t) sector % data->block_size) << GRUB_DISK_SECTOR_BITS;
 
160
  size <<= GRUB_DISK_SECTOR_BITS;
 
161
  bsize = (data->block_size << GRUB_DISK_SECTOR_BITS);
 
162
 
 
163
  do
 
164
    {
 
165
      grub_size_t len;
 
166
 
 
167
      len = (ofs + size > bsize) ? (bsize - ofs) : size;
 
168
 
 
169
      args.len = (grub_ieee1275_cell_t) len;
 
170
      args.ofs = (grub_ieee1275_cell_t) ofs;
 
171
      args.result = 1;
 
172
 
 
173
      if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
 
174
        return grub_error (GRUB_ERR_READ_ERROR, "read error");
 
175
 
 
176
      ofs = 0;
 
177
      size -= len;
 
178
      args.buf += len;
 
179
      args.page++;
 
180
    } while (size);
 
181
 
 
182
  return GRUB_ERR_NONE;
 
183
}
 
184
 
 
185
static grub_err_t
 
186
grub_nand_write (grub_disk_t disk __attribute ((unused)),
 
187
                 grub_disk_addr_t sector __attribute ((unused)),
 
188
                 grub_size_t size __attribute ((unused)),
 
189
                 const char *buf __attribute ((unused)))
 
190
{
 
191
  return GRUB_ERR_NOT_IMPLEMENTED_YET;
 
192
}
 
193
 
 
194
static struct grub_disk_dev grub_nand_dev =
 
195
  {
 
196
    .name = "nand",
 
197
    .id = GRUB_DISK_DEVICE_NAND_ID,
 
198
    .iterate = grub_nand_iterate,
 
199
    .open = grub_nand_open,
 
200
    .close = grub_nand_close,
 
201
    .read = grub_nand_read,
 
202
    .write = grub_nand_write,
 
203
    .next = 0
 
204
  };
 
205
 
 
206
GRUB_MOD_INIT(nand)
 
207
{
 
208
  grub_disk_dev_register (&grub_nand_dev);
 
209
}
 
210
 
 
211
GRUB_MOD_FINI(nand)
 
212
{
 
213
  grub_disk_dev_unregister (&grub_nand_dev);
 
214
}