~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, 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
/* 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
}