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

« back to all changes in this revision

Viewing changes to 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->has_partitions = 0;
117
 
  disk->data = data;
118
 
 
119
 
  return 0;
120
 
 
121
 
fail:
122
 
  if (dev_ihandle)
123
 
    grub_ieee1275_close (dev_ihandle);
124
 
  grub_free (data);
125
 
  return grub_errno;
126
 
}
127
 
 
128
 
static void
129
 
grub_nand_close (grub_disk_t disk)
130
 
{
131
 
  grub_ieee1275_close (((struct grub_nand_data *) disk->data)->handle);
132
 
  grub_free (disk->data);
133
 
}
134
 
 
135
 
static grub_err_t
136
 
grub_nand_read (grub_disk_t disk, grub_disk_addr_t sector,
137
 
                grub_size_t size, char *buf)
138
 
{
139
 
  struct grub_nand_data *data = disk->data;
140
 
  grub_size_t bsize, ofs;
141
 
 
142
 
  struct read_args
143
 
    {
144
 
      struct grub_ieee1275_common_hdr common;
145
 
      grub_ieee1275_cell_t method;
146
 
      grub_ieee1275_cell_t ihandle;
147
 
      grub_ieee1275_cell_t ofs;
148
 
      grub_ieee1275_cell_t page;
149
 
      grub_ieee1275_cell_t len;
150
 
      grub_ieee1275_cell_t buf;
151
 
      grub_ieee1275_cell_t result;
152
 
    } args;
153
 
 
154
 
  INIT_IEEE1275_COMMON (&args.common, "call-method", 6, 1);
155
 
  args.method = (grub_ieee1275_cell_t) "pio-read";
156
 
  args.ihandle = data->handle;
157
 
  args.buf = (grub_ieee1275_cell_t) buf;
158
 
  args.page = (grub_ieee1275_cell_t) ((grub_size_t) sector / data->block_size);
159
 
 
160
 
  ofs = ((grub_size_t) sector % data->block_size) << GRUB_DISK_SECTOR_BITS;
161
 
  size <<= GRUB_DISK_SECTOR_BITS;
162
 
  bsize = (data->block_size << GRUB_DISK_SECTOR_BITS);
163
 
 
164
 
  do
165
 
    {
166
 
      grub_size_t len;
167
 
 
168
 
      len = (ofs + size > bsize) ? (bsize - ofs) : size;
169
 
 
170
 
      args.len = (grub_ieee1275_cell_t) len;
171
 
      args.ofs = (grub_ieee1275_cell_t) ofs;
172
 
      args.result = 1;
173
 
 
174
 
      if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.result))
175
 
        return grub_error (GRUB_ERR_READ_ERROR, "read error");
176
 
 
177
 
      ofs = 0;
178
 
      size -= len;
179
 
      args.buf += len;
180
 
      args.page++;
181
 
    } while (size);
182
 
 
183
 
  return GRUB_ERR_NONE;
184
 
}
185
 
 
186
 
static grub_err_t
187
 
grub_nand_write (grub_disk_t disk __attribute ((unused)),
188
 
                 grub_disk_addr_t sector __attribute ((unused)),
189
 
                 grub_size_t size __attribute ((unused)),
190
 
                 const char *buf __attribute ((unused)))
191
 
{
192
 
  return GRUB_ERR_NOT_IMPLEMENTED_YET;
193
 
}
194
 
 
195
 
static struct grub_disk_dev grub_nand_dev =
196
 
  {
197
 
    .name = "nand",
198
 
    .id = GRUB_DISK_DEVICE_NAND_ID,
199
 
    .iterate = grub_nand_iterate,
200
 
    .open = grub_nand_open,
201
 
    .close = grub_nand_close,
202
 
    .read = grub_nand_read,
203
 
    .write = grub_nand_write,
204
 
    .next = 0
205
 
  };
206
 
 
207
 
GRUB_MOD_INIT(nand)
208
 
{
209
 
  grub_disk_dev_register (&grub_nand_dev);
210
 
}
211
 
 
212
 
GRUB_MOD_FINI(nand)
213
 
{
214
 
  grub_disk_dev_unregister (&grub_nand_dev);
215
 
}