root / hw / onenand.c @ 1724f049
History | View | Annotate | Download (19.2 kB)
1 | 7e7c5e4c | balrog | /*
|
---|---|---|---|
2 | 7e7c5e4c | balrog | * OneNAND flash memories emulation.
|
3 | 7e7c5e4c | balrog | *
|
4 | 7e7c5e4c | balrog | * Copyright (C) 2008 Nokia Corporation
|
5 | 7e7c5e4c | balrog | * Written by Andrzej Zaborowski <andrew@openedhand.com>
|
6 | 7e7c5e4c | balrog | *
|
7 | 7e7c5e4c | balrog | * This program is free software; you can redistribute it and/or
|
8 | 7e7c5e4c | balrog | * modify it under the terms of the GNU General Public License as
|
9 | 7e7c5e4c | balrog | * published by the Free Software Foundation; either version 2 or
|
10 | 7e7c5e4c | balrog | * (at your option) version 3 of the License.
|
11 | 7e7c5e4c | balrog | *
|
12 | 7e7c5e4c | balrog | * This program is distributed in the hope that it will be useful,
|
13 | 7e7c5e4c | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 7e7c5e4c | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | 7e7c5e4c | balrog | * GNU General Public License for more details.
|
16 | 7e7c5e4c | balrog | *
|
17 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
18 | 8167ee88 | Blue Swirl | * with this program; if not, see <http://www.gnu.org/licenses/>.
|
19 | 7e7c5e4c | balrog | */
|
20 | 7e7c5e4c | balrog | |
21 | 7e7c5e4c | balrog | #include "qemu-common.h" |
22 | 7e7c5e4c | balrog | #include "flash.h" |
23 | 7e7c5e4c | balrog | #include "irq.h" |
24 | 666daa68 | Markus Armbruster | #include "blockdev.h" |
25 | 7e7c5e4c | balrog | |
26 | 7e7c5e4c | balrog | /* 11 for 2kB-page OneNAND ("2nd generation") and 10 for 1kB-page chips */
|
27 | 7e7c5e4c | balrog | #define PAGE_SHIFT 11 |
28 | 7e7c5e4c | balrog | |
29 | 7e7c5e4c | balrog | /* Fixed */
|
30 | 7e7c5e4c | balrog | #define BLOCK_SHIFT (PAGE_SHIFT + 6) |
31 | 7e7c5e4c | balrog | |
32 | bc24a225 | Paul Brook | typedef struct { |
33 | 7e7c5e4c | balrog | uint32_t id; |
34 | 7e7c5e4c | balrog | int shift;
|
35 | c227f099 | Anthony Liguori | target_phys_addr_t base; |
36 | 7e7c5e4c | balrog | qemu_irq intr; |
37 | 7e7c5e4c | balrog | qemu_irq rdy; |
38 | 7e7c5e4c | balrog | BlockDriverState *bdrv; |
39 | 7e7c5e4c | balrog | BlockDriverState *bdrv_cur; |
40 | 7e7c5e4c | balrog | uint8_t *image; |
41 | 7e7c5e4c | balrog | uint8_t *otp; |
42 | 7e7c5e4c | balrog | uint8_t *current; |
43 | c227f099 | Anthony Liguori | ram_addr_t ram; |
44 | 7e7c5e4c | balrog | uint8_t *boot[2];
|
45 | 7e7c5e4c | balrog | uint8_t *data[2][2]; |
46 | 7e7c5e4c | balrog | int iomemtype;
|
47 | 7e7c5e4c | balrog | int cycle;
|
48 | 7e7c5e4c | balrog | int otpmode;
|
49 | 7e7c5e4c | balrog | |
50 | 7e7c5e4c | balrog | uint16_t addr[8];
|
51 | 7e7c5e4c | balrog | uint16_t unladdr[8];
|
52 | 7e7c5e4c | balrog | int bufaddr;
|
53 | 7e7c5e4c | balrog | int count;
|
54 | 7e7c5e4c | balrog | uint16_t command; |
55 | 7e7c5e4c | balrog | uint16_t config[2];
|
56 | 7e7c5e4c | balrog | uint16_t status; |
57 | 7e7c5e4c | balrog | uint16_t intstatus; |
58 | 7e7c5e4c | balrog | uint16_t wpstatus; |
59 | 7e7c5e4c | balrog | |
60 | bc24a225 | Paul Brook | ECCState ecc; |
61 | 7e7c5e4c | balrog | |
62 | 7e7c5e4c | balrog | int density_mask;
|
63 | 7e7c5e4c | balrog | int secs;
|
64 | 7e7c5e4c | balrog | int secs_cur;
|
65 | 7e7c5e4c | balrog | int blocks;
|
66 | 7e7c5e4c | balrog | uint8_t *blockwp; |
67 | bc24a225 | Paul Brook | } OneNANDState; |
68 | 7e7c5e4c | balrog | |
69 | 7e7c5e4c | balrog | enum {
|
70 | 7e7c5e4c | balrog | ONEN_BUF_BLOCK = 0,
|
71 | 7e7c5e4c | balrog | ONEN_BUF_BLOCK2 = 1,
|
72 | 7e7c5e4c | balrog | ONEN_BUF_DEST_BLOCK = 2,
|
73 | 7e7c5e4c | balrog | ONEN_BUF_DEST_PAGE = 3,
|
74 | 7e7c5e4c | balrog | ONEN_BUF_PAGE = 7,
|
75 | 7e7c5e4c | balrog | }; |
76 | 7e7c5e4c | balrog | |
77 | 7e7c5e4c | balrog | enum {
|
78 | 7e7c5e4c | balrog | ONEN_ERR_CMD = 1 << 10, |
79 | 7e7c5e4c | balrog | ONEN_ERR_ERASE = 1 << 11, |
80 | 7e7c5e4c | balrog | ONEN_ERR_PROG = 1 << 12, |
81 | 7e7c5e4c | balrog | ONEN_ERR_LOAD = 1 << 13, |
82 | 7e7c5e4c | balrog | }; |
83 | 7e7c5e4c | balrog | |
84 | 7e7c5e4c | balrog | enum {
|
85 | 7e7c5e4c | balrog | ONEN_INT_RESET = 1 << 4, |
86 | 7e7c5e4c | balrog | ONEN_INT_ERASE = 1 << 5, |
87 | 7e7c5e4c | balrog | ONEN_INT_PROG = 1 << 6, |
88 | 7e7c5e4c | balrog | ONEN_INT_LOAD = 1 << 7, |
89 | 7e7c5e4c | balrog | ONEN_INT = 1 << 15, |
90 | 7e7c5e4c | balrog | }; |
91 | 7e7c5e4c | balrog | |
92 | 7e7c5e4c | balrog | enum {
|
93 | 7e7c5e4c | balrog | ONEN_LOCK_LOCKTIGHTEN = 1 << 0, |
94 | 7e7c5e4c | balrog | ONEN_LOCK_LOCKED = 1 << 1, |
95 | 7e7c5e4c | balrog | ONEN_LOCK_UNLOCKED = 1 << 2, |
96 | 7e7c5e4c | balrog | }; |
97 | 7e7c5e4c | balrog | |
98 | c227f099 | Anthony Liguori | void onenand_base_update(void *opaque, target_phys_addr_t new) |
99 | 7e7c5e4c | balrog | { |
100 | bc24a225 | Paul Brook | OneNANDState *s = (OneNANDState *) opaque; |
101 | 7e7c5e4c | balrog | |
102 | 7e7c5e4c | balrog | s->base = new; |
103 | 7e7c5e4c | balrog | |
104 | 7e7c5e4c | balrog | /* XXX: We should use IO_MEM_ROMD but we broke it earlier...
|
105 | 7e7c5e4c | balrog | * Both 0x0000 ... 0x01ff and 0x8000 ... 0x800f can be used to
|
106 | 7e7c5e4c | balrog | * write boot commands. Also take note of the BWPS bit. */
|
107 | 7e7c5e4c | balrog | cpu_register_physical_memory(s->base + (0x0000 << s->shift),
|
108 | 7e7c5e4c | balrog | 0x0200 << s->shift, s->iomemtype);
|
109 | 7e7c5e4c | balrog | cpu_register_physical_memory(s->base + (0x0200 << s->shift),
|
110 | 7e7c5e4c | balrog | 0xbe00 << s->shift,
|
111 | 7e7c5e4c | balrog | (s->ram +(0x0200 << s->shift)) | IO_MEM_RAM);
|
112 | 7e7c5e4c | balrog | if (s->iomemtype)
|
113 | 8da3ff18 | pbrook | cpu_register_physical_memory_offset(s->base + (0xc000 << s->shift),
|
114 | 8da3ff18 | pbrook | 0x4000 << s->shift, s->iomemtype, (0xc000 << s->shift)); |
115 | 7e7c5e4c | balrog | } |
116 | 7e7c5e4c | balrog | |
117 | 7e7c5e4c | balrog | void onenand_base_unmap(void *opaque) |
118 | 7e7c5e4c | balrog | { |
119 | bc24a225 | Paul Brook | OneNANDState *s = (OneNANDState *) opaque; |
120 | 7e7c5e4c | balrog | |
121 | 7e7c5e4c | balrog | cpu_register_physical_memory(s->base, |
122 | 7e7c5e4c | balrog | 0x10000 << s->shift, IO_MEM_UNASSIGNED);
|
123 | 7e7c5e4c | balrog | } |
124 | 7e7c5e4c | balrog | |
125 | bc24a225 | Paul Brook | static void onenand_intr_update(OneNANDState *s) |
126 | 7e7c5e4c | balrog | { |
127 | 7e7c5e4c | balrog | qemu_set_irq(s->intr, ((s->intstatus >> 15) ^ (~s->config[0] >> 6)) & 1); |
128 | 7e7c5e4c | balrog | } |
129 | 7e7c5e4c | balrog | |
130 | 7e7c5e4c | balrog | /* Hot reset (Reset OneNAND command) or warm reset (RP pin low) */
|
131 | bc24a225 | Paul Brook | static void onenand_reset(OneNANDState *s, int cold) |
132 | 7e7c5e4c | balrog | { |
133 | 7e7c5e4c | balrog | memset(&s->addr, 0, sizeof(s->addr)); |
134 | 7e7c5e4c | balrog | s->command = 0;
|
135 | 7e7c5e4c | balrog | s->count = 1;
|
136 | 7e7c5e4c | balrog | s->bufaddr = 0;
|
137 | 7e7c5e4c | balrog | s->config[0] = 0x40c0; |
138 | 7e7c5e4c | balrog | s->config[1] = 0x0000; |
139 | 7e7c5e4c | balrog | onenand_intr_update(s); |
140 | 7e7c5e4c | balrog | qemu_irq_raise(s->rdy); |
141 | 7e7c5e4c | balrog | s->status = 0x0000;
|
142 | 7e7c5e4c | balrog | s->intstatus = cold ? 0x8080 : 0x8010; |
143 | 7e7c5e4c | balrog | s->unladdr[0] = 0; |
144 | 7e7c5e4c | balrog | s->unladdr[1] = 0; |
145 | 7e7c5e4c | balrog | s->wpstatus = 0x0002;
|
146 | 7e7c5e4c | balrog | s->cycle = 0;
|
147 | 7e7c5e4c | balrog | s->otpmode = 0;
|
148 | 7e7c5e4c | balrog | s->bdrv_cur = s->bdrv; |
149 | 7e7c5e4c | balrog | s->current = s->image; |
150 | 7e7c5e4c | balrog | s->secs_cur = s->secs; |
151 | 7e7c5e4c | balrog | |
152 | 7e7c5e4c | balrog | if (cold) {
|
153 | 7e7c5e4c | balrog | /* Lock the whole flash */
|
154 | 7e7c5e4c | balrog | memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks); |
155 | 7e7c5e4c | balrog | |
156 | 7e7c5e4c | balrog | if (s->bdrv && bdrv_read(s->bdrv, 0, s->boot[0], 8) < 0) |
157 | 2ac71179 | Paul Brook | hw_error("%s: Loading the BootRAM failed.\n", __FUNCTION__);
|
158 | 7e7c5e4c | balrog | } |
159 | 7e7c5e4c | balrog | } |
160 | 7e7c5e4c | balrog | |
161 | bc24a225 | Paul Brook | static inline int onenand_load_main(OneNANDState *s, int sec, int secn, |
162 | 7e7c5e4c | balrog | void *dest)
|
163 | 7e7c5e4c | balrog | { |
164 | 7e7c5e4c | balrog | if (s->bdrv_cur)
|
165 | 7e7c5e4c | balrog | return bdrv_read(s->bdrv_cur, sec, dest, secn) < 0; |
166 | 7e7c5e4c | balrog | else if (sec + secn > s->secs_cur) |
167 | 7e7c5e4c | balrog | return 1; |
168 | 7e7c5e4c | balrog | |
169 | 7e7c5e4c | balrog | memcpy(dest, s->current + (sec << 9), secn << 9); |
170 | 7e7c5e4c | balrog | |
171 | 7e7c5e4c | balrog | return 0; |
172 | 7e7c5e4c | balrog | } |
173 | 7e7c5e4c | balrog | |
174 | bc24a225 | Paul Brook | static inline int onenand_prog_main(OneNANDState *s, int sec, int secn, |
175 | 7e7c5e4c | balrog | void *src)
|
176 | 7e7c5e4c | balrog | { |
177 | 7e7c5e4c | balrog | if (s->bdrv_cur)
|
178 | 7e7c5e4c | balrog | return bdrv_write(s->bdrv_cur, sec, src, secn) < 0; |
179 | 7e7c5e4c | balrog | else if (sec + secn > s->secs_cur) |
180 | 7e7c5e4c | balrog | return 1; |
181 | 7e7c5e4c | balrog | |
182 | 7e7c5e4c | balrog | memcpy(s->current + (sec << 9), src, secn << 9); |
183 | 7e7c5e4c | balrog | |
184 | 7e7c5e4c | balrog | return 0; |
185 | 7e7c5e4c | balrog | } |
186 | 7e7c5e4c | balrog | |
187 | bc24a225 | Paul Brook | static inline int onenand_load_spare(OneNANDState *s, int sec, int secn, |
188 | 7e7c5e4c | balrog | void *dest)
|
189 | 7e7c5e4c | balrog | { |
190 | 7e7c5e4c | balrog | uint8_t buf[512];
|
191 | 7e7c5e4c | balrog | |
192 | 7e7c5e4c | balrog | if (s->bdrv_cur) {
|
193 | 7e7c5e4c | balrog | if (bdrv_read(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) |
194 | 7e7c5e4c | balrog | return 1; |
195 | 7e7c5e4c | balrog | memcpy(dest, buf + ((sec & 31) << 4), secn << 4); |
196 | 7e7c5e4c | balrog | } else if (sec + secn > s->secs_cur) |
197 | 7e7c5e4c | balrog | return 1; |
198 | 7e7c5e4c | balrog | else
|
199 | 7e7c5e4c | balrog | memcpy(dest, s->current + (s->secs_cur << 9) + (sec << 4), secn << 4); |
200 | 7e7c5e4c | balrog | |
201 | 7e7c5e4c | balrog | return 0; |
202 | 7e7c5e4c | balrog | } |
203 | 7e7c5e4c | balrog | |
204 | bc24a225 | Paul Brook | static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, |
205 | 7e7c5e4c | balrog | void *src)
|
206 | 7e7c5e4c | balrog | { |
207 | 7e7c5e4c | balrog | uint8_t buf[512];
|
208 | 7e7c5e4c | balrog | |
209 | 7e7c5e4c | balrog | if (s->bdrv_cur) {
|
210 | 7e7c5e4c | balrog | if (bdrv_read(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) |
211 | 7e7c5e4c | balrog | return 1; |
212 | 7e7c5e4c | balrog | memcpy(buf + ((sec & 31) << 4), src, secn << 4); |
213 | 7e7c5e4c | balrog | return bdrv_write(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0; |
214 | 7e7c5e4c | balrog | } else if (sec + secn > s->secs_cur) |
215 | 7e7c5e4c | balrog | return 1; |
216 | 7e7c5e4c | balrog | |
217 | 7e7c5e4c | balrog | memcpy(s->current + (s->secs_cur << 9) + (sec << 4), src, secn << 4); |
218 | 7e7c5e4c | balrog | |
219 | 7e7c5e4c | balrog | return 0; |
220 | 7e7c5e4c | balrog | } |
221 | 7e7c5e4c | balrog | |
222 | bc24a225 | Paul Brook | static inline int onenand_erase(OneNANDState *s, int sec, int num) |
223 | 7e7c5e4c | balrog | { |
224 | 7e7c5e4c | balrog | /* TODO: optimise */
|
225 | 7e7c5e4c | balrog | uint8_t buf[512];
|
226 | 7e7c5e4c | balrog | |
227 | 7e7c5e4c | balrog | memset(buf, 0xff, sizeof(buf)); |
228 | 7e7c5e4c | balrog | for (; num > 0; num --, sec ++) { |
229 | 7e7c5e4c | balrog | if (onenand_prog_main(s, sec, 1, buf)) |
230 | 7e7c5e4c | balrog | return 1; |
231 | 7e7c5e4c | balrog | if (onenand_prog_spare(s, sec, 1, buf)) |
232 | 7e7c5e4c | balrog | return 1; |
233 | 7e7c5e4c | balrog | } |
234 | 7e7c5e4c | balrog | |
235 | 7e7c5e4c | balrog | return 0; |
236 | 7e7c5e4c | balrog | } |
237 | 7e7c5e4c | balrog | |
238 | bc24a225 | Paul Brook | static void onenand_command(OneNANDState *s, int cmd) |
239 | 7e7c5e4c | balrog | { |
240 | 7e7c5e4c | balrog | int b;
|
241 | 7e7c5e4c | balrog | int sec;
|
242 | 7e7c5e4c | balrog | void *buf;
|
243 | 7e7c5e4c | balrog | #define SETADDR(block, page) \
|
244 | 7e7c5e4c | balrog | sec = (s->addr[page] & 3) + \
|
245 | 7e7c5e4c | balrog | ((((s->addr[page] >> 2) & 0x3f) + \ |
246 | 7e7c5e4c | balrog | (((s->addr[block] & 0xfff) | \
|
247 | 7e7c5e4c | balrog | (s->addr[block] >> 15 ? \
|
248 | 7e7c5e4c | balrog | s->density_mask : 0)) << 6)) << (PAGE_SHIFT - 9)); |
249 | 7e7c5e4c | balrog | #define SETBUF_M() \
|
250 | 7e7c5e4c | balrog | buf = (s->bufaddr & 8) ? \
|
251 | 7e7c5e4c | balrog | s->data[(s->bufaddr >> 2) & 1][0] : s->boot[0]; \ |
252 | 7e7c5e4c | balrog | buf += (s->bufaddr & 3) << 9; |
253 | 7e7c5e4c | balrog | #define SETBUF_S() \
|
254 | 7e7c5e4c | balrog | buf = (s->bufaddr & 8) ? \
|
255 | 7e7c5e4c | balrog | s->data[(s->bufaddr >> 2) & 1][1] : s->boot[1]; \ |
256 | 7e7c5e4c | balrog | buf += (s->bufaddr & 3) << 4; |
257 | 7e7c5e4c | balrog | |
258 | 7e7c5e4c | balrog | switch (cmd) {
|
259 | 7e7c5e4c | balrog | case 0x00: /* Load single/multiple sector data unit into buffer */ |
260 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
261 | 7e7c5e4c | balrog | |
262 | 7e7c5e4c | balrog | SETBUF_M() |
263 | 7e7c5e4c | balrog | if (onenand_load_main(s, sec, s->count, buf))
|
264 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_LOAD; |
265 | 7e7c5e4c | balrog | |
266 | 7e7c5e4c | balrog | #if 0
|
267 | 7e7c5e4c | balrog | SETBUF_S()
|
268 | 7e7c5e4c | balrog | if (onenand_load_spare(s, sec, s->count, buf))
|
269 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_LOAD;
|
270 | 7e7c5e4c | balrog | #endif
|
271 | 7e7c5e4c | balrog | |
272 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
273 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
274 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
275 | 7e7c5e4c | balrog | */
|
276 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_LOAD; |
277 | 7e7c5e4c | balrog | break;
|
278 | 7e7c5e4c | balrog | case 0x13: /* Load single/multiple spare sector into buffer */ |
279 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
280 | 7e7c5e4c | balrog | |
281 | 7e7c5e4c | balrog | SETBUF_S() |
282 | 7e7c5e4c | balrog | if (onenand_load_spare(s, sec, s->count, buf))
|
283 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_LOAD; |
284 | 7e7c5e4c | balrog | |
285 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
286 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
287 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
288 | 7e7c5e4c | balrog | */
|
289 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_LOAD; |
290 | 7e7c5e4c | balrog | break;
|
291 | 7e7c5e4c | balrog | case 0x80: /* Program single/multiple sector data unit from buffer */ |
292 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
293 | 7e7c5e4c | balrog | |
294 | 7e7c5e4c | balrog | SETBUF_M() |
295 | 7e7c5e4c | balrog | if (onenand_prog_main(s, sec, s->count, buf))
|
296 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
297 | 7e7c5e4c | balrog | |
298 | 7e7c5e4c | balrog | #if 0
|
299 | 7e7c5e4c | balrog | SETBUF_S()
|
300 | 7e7c5e4c | balrog | if (onenand_prog_spare(s, sec, s->count, buf))
|
301 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG;
|
302 | 7e7c5e4c | balrog | #endif
|
303 | 7e7c5e4c | balrog | |
304 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
305 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
306 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
307 | 7e7c5e4c | balrog | */
|
308 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_PROG; |
309 | 7e7c5e4c | balrog | break;
|
310 | 7e7c5e4c | balrog | case 0x1a: /* Program single/multiple spare area sector from buffer */ |
311 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
312 | 7e7c5e4c | balrog | |
313 | 7e7c5e4c | balrog | SETBUF_S() |
314 | 7e7c5e4c | balrog | if (onenand_prog_spare(s, sec, s->count, buf))
|
315 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
316 | 7e7c5e4c | balrog | |
317 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
318 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
319 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
320 | 7e7c5e4c | balrog | */
|
321 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_PROG; |
322 | 7e7c5e4c | balrog | break;
|
323 | 7e7c5e4c | balrog | case 0x1b: /* Copy-back program */ |
324 | 7e7c5e4c | balrog | SETBUF_S() |
325 | 7e7c5e4c | balrog | |
326 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
327 | 7e7c5e4c | balrog | if (onenand_load_main(s, sec, s->count, buf))
|
328 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
329 | 7e7c5e4c | balrog | |
330 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_DEST_BLOCK, ONEN_BUF_DEST_PAGE) |
331 | 7e7c5e4c | balrog | if (onenand_prog_main(s, sec, s->count, buf))
|
332 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
333 | 7e7c5e4c | balrog | |
334 | 7e7c5e4c | balrog | /* TODO: spare areas */
|
335 | 7e7c5e4c | balrog | |
336 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_PROG; |
337 | 7e7c5e4c | balrog | break;
|
338 | 7e7c5e4c | balrog | |
339 | 7e7c5e4c | balrog | case 0x23: /* Unlock NAND array block(s) */ |
340 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
341 | 7e7c5e4c | balrog | |
342 | 7e7c5e4c | balrog | /* XXX the previous (?) area should be locked automatically */
|
343 | 7e7c5e4c | balrog | for (b = s->unladdr[0]; b <= s->unladdr[1]; b ++) { |
344 | 7e7c5e4c | balrog | if (b >= s->blocks) {
|
345 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
346 | 7e7c5e4c | balrog | break;
|
347 | 7e7c5e4c | balrog | } |
348 | 7e7c5e4c | balrog | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN)
|
349 | 7e7c5e4c | balrog | break;
|
350 | 7e7c5e4c | balrog | |
351 | 7e7c5e4c | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_UNLOCKED; |
352 | 7e7c5e4c | balrog | } |
353 | 7e7c5e4c | balrog | break;
|
354 | 89588a4b | balrog | case 0x27: /* Unlock All NAND array blocks */ |
355 | 89588a4b | balrog | s->intstatus |= ONEN_INT; |
356 | 89588a4b | balrog | |
357 | 89588a4b | balrog | for (b = 0; b < s->blocks; b ++) { |
358 | 89588a4b | balrog | if (b >= s->blocks) {
|
359 | 89588a4b | balrog | s->status |= ONEN_ERR_CMD; |
360 | 89588a4b | balrog | break;
|
361 | 89588a4b | balrog | } |
362 | 89588a4b | balrog | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN)
|
363 | 89588a4b | balrog | break;
|
364 | 89588a4b | balrog | |
365 | 89588a4b | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_UNLOCKED; |
366 | 89588a4b | balrog | } |
367 | 89588a4b | balrog | break;
|
368 | 89588a4b | balrog | |
369 | 7e7c5e4c | balrog | case 0x2a: /* Lock NAND array block(s) */ |
370 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
371 | 7e7c5e4c | balrog | |
372 | 7e7c5e4c | balrog | for (b = s->unladdr[0]; b <= s->unladdr[1]; b ++) { |
373 | 7e7c5e4c | balrog | if (b >= s->blocks) {
|
374 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
375 | 7e7c5e4c | balrog | break;
|
376 | 7e7c5e4c | balrog | } |
377 | 7e7c5e4c | balrog | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN)
|
378 | 7e7c5e4c | balrog | break;
|
379 | 7e7c5e4c | balrog | |
380 | 7e7c5e4c | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_LOCKED; |
381 | 7e7c5e4c | balrog | } |
382 | 7e7c5e4c | balrog | break;
|
383 | 7e7c5e4c | balrog | case 0x2c: /* Lock-tight NAND array block(s) */ |
384 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
385 | 7e7c5e4c | balrog | |
386 | 7e7c5e4c | balrog | for (b = s->unladdr[0]; b <= s->unladdr[1]; b ++) { |
387 | 7e7c5e4c | balrog | if (b >= s->blocks) {
|
388 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
389 | 7e7c5e4c | balrog | break;
|
390 | 7e7c5e4c | balrog | } |
391 | 7e7c5e4c | balrog | if (s->blockwp[b] == ONEN_LOCK_UNLOCKED)
|
392 | 7e7c5e4c | balrog | continue;
|
393 | 7e7c5e4c | balrog | |
394 | 7e7c5e4c | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_LOCKTIGHTEN; |
395 | 7e7c5e4c | balrog | } |
396 | 7e7c5e4c | balrog | break;
|
397 | 7e7c5e4c | balrog | |
398 | 7e7c5e4c | balrog | case 0x71: /* Erase-Verify-Read */ |
399 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
400 | 7e7c5e4c | balrog | break;
|
401 | 7e7c5e4c | balrog | case 0x95: /* Multi-block erase */ |
402 | 7e7c5e4c | balrog | qemu_irq_pulse(s->intr); |
403 | 7e7c5e4c | balrog | /* Fall through. */
|
404 | 7e7c5e4c | balrog | case 0x94: /* Block erase */ |
405 | 7e7c5e4c | balrog | sec = ((s->addr[ONEN_BUF_BLOCK] & 0xfff) |
|
406 | 7e7c5e4c | balrog | (s->addr[ONEN_BUF_BLOCK] >> 15 ? s->density_mask : 0)) |
407 | 7e7c5e4c | balrog | << (BLOCK_SHIFT - 9);
|
408 | 7e7c5e4c | balrog | if (onenand_erase(s, sec, 1 << (BLOCK_SHIFT - 9))) |
409 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_ERASE; |
410 | 7e7c5e4c | balrog | |
411 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_ERASE; |
412 | 7e7c5e4c | balrog | break;
|
413 | 7e7c5e4c | balrog | case 0xb0: /* Erase suspend */ |
414 | 7e7c5e4c | balrog | break;
|
415 | 7e7c5e4c | balrog | case 0x30: /* Erase resume */ |
416 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_ERASE; |
417 | 7e7c5e4c | balrog | break;
|
418 | 7e7c5e4c | balrog | |
419 | 7e7c5e4c | balrog | case 0xf0: /* Reset NAND Flash core */ |
420 | 7e7c5e4c | balrog | onenand_reset(s, 0);
|
421 | 7e7c5e4c | balrog | break;
|
422 | 7e7c5e4c | balrog | case 0xf3: /* Reset OneNAND */ |
423 | 7e7c5e4c | balrog | onenand_reset(s, 0);
|
424 | 7e7c5e4c | balrog | break;
|
425 | 7e7c5e4c | balrog | |
426 | 7e7c5e4c | balrog | case 0x65: /* OTP Access */ |
427 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
428 | b9d38e95 | Blue Swirl | s->bdrv_cur = NULL;
|
429 | 7e7c5e4c | balrog | s->current = s->otp; |
430 | 7e7c5e4c | balrog | s->secs_cur = 1 << (BLOCK_SHIFT - 9); |
431 | 7e7c5e4c | balrog | s->addr[ONEN_BUF_BLOCK] = 0;
|
432 | 7e7c5e4c | balrog | s->otpmode = 1;
|
433 | 7e7c5e4c | balrog | break;
|
434 | 7e7c5e4c | balrog | |
435 | 7e7c5e4c | balrog | default:
|
436 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
437 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
438 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND command %x\n",
|
439 | 7e7c5e4c | balrog | __FUNCTION__, cmd); |
440 | 7e7c5e4c | balrog | } |
441 | 7e7c5e4c | balrog | |
442 | 7e7c5e4c | balrog | onenand_intr_update(s); |
443 | 7e7c5e4c | balrog | } |
444 | 7e7c5e4c | balrog | |
445 | c227f099 | Anthony Liguori | static uint32_t onenand_read(void *opaque, target_phys_addr_t addr) |
446 | 7e7c5e4c | balrog | { |
447 | bc24a225 | Paul Brook | OneNANDState *s = (OneNANDState *) opaque; |
448 | 8da3ff18 | pbrook | int offset = addr >> s->shift;
|
449 | 7e7c5e4c | balrog | |
450 | 7e7c5e4c | balrog | switch (offset) {
|
451 | 7e7c5e4c | balrog | case 0x0000 ... 0xc000: |
452 | 8da3ff18 | pbrook | return lduw_le_p(s->boot[0] + addr); |
453 | 7e7c5e4c | balrog | |
454 | 7e7c5e4c | balrog | case 0xf000: /* Manufacturer ID */ |
455 | 7e7c5e4c | balrog | return (s->id >> 16) & 0xff; |
456 | 7e7c5e4c | balrog | case 0xf001: /* Device ID */ |
457 | 7e7c5e4c | balrog | return (s->id >> 8) & 0xff; |
458 | 7e7c5e4c | balrog | /* TODO: get the following values from a real chip! */
|
459 | 7e7c5e4c | balrog | case 0xf002: /* Version ID */ |
460 | 7e7c5e4c | balrog | return (s->id >> 0) & 0xff; |
461 | 7e7c5e4c | balrog | case 0xf003: /* Data Buffer size */ |
462 | 7e7c5e4c | balrog | return 1 << PAGE_SHIFT; |
463 | 7e7c5e4c | balrog | case 0xf004: /* Boot Buffer size */ |
464 | 7e7c5e4c | balrog | return 0x200; |
465 | 7e7c5e4c | balrog | case 0xf005: /* Amount of buffers */ |
466 | 7e7c5e4c | balrog | return 1 | (2 << 8); |
467 | 7e7c5e4c | balrog | case 0xf006: /* Technology */ |
468 | 7e7c5e4c | balrog | return 0; |
469 | 7e7c5e4c | balrog | |
470 | 7e7c5e4c | balrog | case 0xf100 ... 0xf107: /* Start addresses */ |
471 | 7e7c5e4c | balrog | return s->addr[offset - 0xf100]; |
472 | 7e7c5e4c | balrog | |
473 | 7e7c5e4c | balrog | case 0xf200: /* Start buffer */ |
474 | 7e7c5e4c | balrog | return (s->bufaddr << 8) | ((s->count - 1) & (1 << (PAGE_SHIFT - 10))); |
475 | 7e7c5e4c | balrog | |
476 | 7e7c5e4c | balrog | case 0xf220: /* Command */ |
477 | 7e7c5e4c | balrog | return s->command;
|
478 | 7e7c5e4c | balrog | case 0xf221: /* System Configuration 1 */ |
479 | 7e7c5e4c | balrog | return s->config[0] & 0xffe0; |
480 | 7e7c5e4c | balrog | case 0xf222: /* System Configuration 2 */ |
481 | 7e7c5e4c | balrog | return s->config[1]; |
482 | 7e7c5e4c | balrog | |
483 | 7e7c5e4c | balrog | case 0xf240: /* Controller Status */ |
484 | 7e7c5e4c | balrog | return s->status;
|
485 | 7e7c5e4c | balrog | case 0xf241: /* Interrupt */ |
486 | 7e7c5e4c | balrog | return s->intstatus;
|
487 | 7e7c5e4c | balrog | case 0xf24c: /* Unlock Start Block Address */ |
488 | 7e7c5e4c | balrog | return s->unladdr[0]; |
489 | 7e7c5e4c | balrog | case 0xf24d: /* Unlock End Block Address */ |
490 | 7e7c5e4c | balrog | return s->unladdr[1]; |
491 | 7e7c5e4c | balrog | case 0xf24e: /* Write Protection Status */ |
492 | 7e7c5e4c | balrog | return s->wpstatus;
|
493 | 7e7c5e4c | balrog | |
494 | 7e7c5e4c | balrog | case 0xff00: /* ECC Status */ |
495 | 7e7c5e4c | balrog | return 0x00; |
496 | 7e7c5e4c | balrog | case 0xff01: /* ECC Result of main area data */ |
497 | 7e7c5e4c | balrog | case 0xff02: /* ECC Result of spare area data */ |
498 | 7e7c5e4c | balrog | case 0xff03: /* ECC Result of main area data */ |
499 | 7e7c5e4c | balrog | case 0xff04: /* ECC Result of spare area data */ |
500 | 2ac71179 | Paul Brook | hw_error("%s: imeplement ECC\n", __FUNCTION__);
|
501 | 7e7c5e4c | balrog | return 0x0000; |
502 | 7e7c5e4c | balrog | } |
503 | 7e7c5e4c | balrog | |
504 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND register %x\n",
|
505 | 7e7c5e4c | balrog | __FUNCTION__, offset); |
506 | 7e7c5e4c | balrog | return 0; |
507 | 7e7c5e4c | balrog | } |
508 | 7e7c5e4c | balrog | |
509 | c227f099 | Anthony Liguori | static void onenand_write(void *opaque, target_phys_addr_t addr, |
510 | 7e7c5e4c | balrog | uint32_t value) |
511 | 7e7c5e4c | balrog | { |
512 | bc24a225 | Paul Brook | OneNANDState *s = (OneNANDState *) opaque; |
513 | 8da3ff18 | pbrook | int offset = addr >> s->shift;
|
514 | 7e7c5e4c | balrog | int sec;
|
515 | 7e7c5e4c | balrog | |
516 | 7e7c5e4c | balrog | switch (offset) {
|
517 | 7e7c5e4c | balrog | case 0x0000 ... 0x01ff: |
518 | 7e7c5e4c | balrog | case 0x8000 ... 0x800f: |
519 | 7e7c5e4c | balrog | if (s->cycle) {
|
520 | 7e7c5e4c | balrog | s->cycle = 0;
|
521 | 7e7c5e4c | balrog | |
522 | 7e7c5e4c | balrog | if (value == 0x0000) { |
523 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
524 | 7e7c5e4c | balrog | onenand_load_main(s, sec, |
525 | 7e7c5e4c | balrog | 1 << (PAGE_SHIFT - 9), s->data[0][0]); |
526 | 7e7c5e4c | balrog | s->addr[ONEN_BUF_PAGE] += 4;
|
527 | 7e7c5e4c | balrog | s->addr[ONEN_BUF_PAGE] &= 0xff;
|
528 | 7e7c5e4c | balrog | } |
529 | 7e7c5e4c | balrog | break;
|
530 | 7e7c5e4c | balrog | } |
531 | 7e7c5e4c | balrog | |
532 | 7e7c5e4c | balrog | switch (value) {
|
533 | 7e7c5e4c | balrog | case 0x00f0: /* Reset OneNAND */ |
534 | 7e7c5e4c | balrog | onenand_reset(s, 0);
|
535 | 7e7c5e4c | balrog | break;
|
536 | 7e7c5e4c | balrog | |
537 | 7e7c5e4c | balrog | case 0x00e0: /* Load Data into Buffer */ |
538 | 7e7c5e4c | balrog | s->cycle = 1;
|
539 | 7e7c5e4c | balrog | break;
|
540 | 7e7c5e4c | balrog | |
541 | 7e7c5e4c | balrog | case 0x0090: /* Read Identification Data */ |
542 | 7e7c5e4c | balrog | memset(s->boot[0], 0, 3 << s->shift); |
543 | 7e7c5e4c | balrog | s->boot[0][0 << s->shift] = (s->id >> 16) & 0xff; |
544 | 7e7c5e4c | balrog | s->boot[0][1 << s->shift] = (s->id >> 8) & 0xff; |
545 | 7e7c5e4c | balrog | s->boot[0][2 << s->shift] = s->wpstatus & 0xff; |
546 | 7e7c5e4c | balrog | break;
|
547 | 7e7c5e4c | balrog | |
548 | 7e7c5e4c | balrog | default:
|
549 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND boot command %x\n",
|
550 | 7e7c5e4c | balrog | __FUNCTION__, value); |
551 | 7e7c5e4c | balrog | } |
552 | 7e7c5e4c | balrog | break;
|
553 | 7e7c5e4c | balrog | |
554 | 7e7c5e4c | balrog | case 0xf100 ... 0xf107: /* Start addresses */ |
555 | 7e7c5e4c | balrog | s->addr[offset - 0xf100] = value;
|
556 | 7e7c5e4c | balrog | break;
|
557 | 7e7c5e4c | balrog | |
558 | 7e7c5e4c | balrog | case 0xf200: /* Start buffer */ |
559 | 7e7c5e4c | balrog | s->bufaddr = (value >> 8) & 0xf; |
560 | 7e7c5e4c | balrog | if (PAGE_SHIFT == 11) |
561 | 7e7c5e4c | balrog | s->count = (value & 3) ?: 4; |
562 | 7e7c5e4c | balrog | else if (PAGE_SHIFT == 10) |
563 | 7e7c5e4c | balrog | s->count = (value & 1) ?: 2; |
564 | 7e7c5e4c | balrog | break;
|
565 | 7e7c5e4c | balrog | |
566 | 7e7c5e4c | balrog | case 0xf220: /* Command */ |
567 | 7e7c5e4c | balrog | if (s->intstatus & (1 << 15)) |
568 | 7e7c5e4c | balrog | break;
|
569 | 7e7c5e4c | balrog | s->command = value; |
570 | 7e7c5e4c | balrog | onenand_command(s, s->command); |
571 | 7e7c5e4c | balrog | break;
|
572 | 7e7c5e4c | balrog | case 0xf221: /* System Configuration 1 */ |
573 | 7e7c5e4c | balrog | s->config[0] = value;
|
574 | 7e7c5e4c | balrog | onenand_intr_update(s); |
575 | 7e7c5e4c | balrog | qemu_set_irq(s->rdy, (s->config[0] >> 7) & 1); |
576 | 7e7c5e4c | balrog | break;
|
577 | 7e7c5e4c | balrog | case 0xf222: /* System Configuration 2 */ |
578 | 7e7c5e4c | balrog | s->config[1] = value;
|
579 | 7e7c5e4c | balrog | break;
|
580 | 7e7c5e4c | balrog | |
581 | 7e7c5e4c | balrog | case 0xf241: /* Interrupt */ |
582 | 7e7c5e4c | balrog | s->intstatus &= value; |
583 | 7e7c5e4c | balrog | if ((1 << 15) & ~s->intstatus) |
584 | 7e7c5e4c | balrog | s->status &= ~(ONEN_ERR_CMD | ONEN_ERR_ERASE | |
585 | 7e7c5e4c | balrog | ONEN_ERR_PROG | ONEN_ERR_LOAD); |
586 | 7e7c5e4c | balrog | onenand_intr_update(s); |
587 | 7e7c5e4c | balrog | break;
|
588 | 7e7c5e4c | balrog | case 0xf24c: /* Unlock Start Block Address */ |
589 | 7e7c5e4c | balrog | s->unladdr[0] = value & (s->blocks - 1); |
590 | 7e7c5e4c | balrog | /* For some reason we have to set the end address to by default
|
591 | 7e7c5e4c | balrog | * be same as start because the software forgets to write anything
|
592 | 7e7c5e4c | balrog | * in there. */
|
593 | 7e7c5e4c | balrog | s->unladdr[1] = value & (s->blocks - 1); |
594 | 7e7c5e4c | balrog | break;
|
595 | 7e7c5e4c | balrog | case 0xf24d: /* Unlock End Block Address */ |
596 | 7e7c5e4c | balrog | s->unladdr[1] = value & (s->blocks - 1); |
597 | 7e7c5e4c | balrog | break;
|
598 | 7e7c5e4c | balrog | |
599 | 7e7c5e4c | balrog | default:
|
600 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND register %x\n",
|
601 | 7e7c5e4c | balrog | __FUNCTION__, offset); |
602 | 7e7c5e4c | balrog | } |
603 | 7e7c5e4c | balrog | } |
604 | 7e7c5e4c | balrog | |
605 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const onenand_readfn[] = { |
606 | 7e7c5e4c | balrog | onenand_read, /* TODO */
|
607 | 7e7c5e4c | balrog | onenand_read, |
608 | 7e7c5e4c | balrog | onenand_read, |
609 | 7e7c5e4c | balrog | }; |
610 | 7e7c5e4c | balrog | |
611 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const onenand_writefn[] = { |
612 | 7e7c5e4c | balrog | onenand_write, /* TODO */
|
613 | 7e7c5e4c | balrog | onenand_write, |
614 | 7e7c5e4c | balrog | onenand_write, |
615 | 7e7c5e4c | balrog | }; |
616 | 7e7c5e4c | balrog | |
617 | 7e7c5e4c | balrog | void *onenand_init(uint32_t id, int regshift, qemu_irq irq) |
618 | 7e7c5e4c | balrog | { |
619 | bc24a225 | Paul Brook | OneNANDState *s = (OneNANDState *) qemu_mallocz(sizeof(*s));
|
620 | 751c6a17 | Gerd Hoffmann | DriveInfo *dinfo = drive_get(IF_MTD, 0, 0); |
621 | 7e7c5e4c | balrog | uint32_t size = 1 << (24 + ((id >> 12) & 7)); |
622 | 7e7c5e4c | balrog | void *ram;
|
623 | 7e7c5e4c | balrog | |
624 | 7e7c5e4c | balrog | s->shift = regshift; |
625 | 7e7c5e4c | balrog | s->intr = irq; |
626 | b9d38e95 | Blue Swirl | s->rdy = NULL;
|
627 | 7e7c5e4c | balrog | s->id = id; |
628 | 7e7c5e4c | balrog | s->blocks = size >> BLOCK_SHIFT; |
629 | 7e7c5e4c | balrog | s->secs = size >> 9;
|
630 | 7e7c5e4c | balrog | s->blockwp = qemu_malloc(s->blocks); |
631 | 7e7c5e4c | balrog | s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0; |
632 | 1eed09cb | Avi Kivity | s->iomemtype = cpu_register_io_memory(onenand_readfn, |
633 | 7e7c5e4c | balrog | onenand_writefn, s); |
634 | 751c6a17 | Gerd Hoffmann | if (!dinfo)
|
635 | 7e7c5e4c | balrog | s->image = memset(qemu_malloc(size + (size >> 5)),
|
636 | 7e7c5e4c | balrog | 0xff, size + (size >> 5)); |
637 | 7e7c5e4c | balrog | else
|
638 | 751c6a17 | Gerd Hoffmann | s->bdrv = dinfo->bdrv; |
639 | 7e7c5e4c | balrog | s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT), |
640 | 7e7c5e4c | balrog | 0xff, (64 + 2) << PAGE_SHIFT); |
641 | 1724f049 | Alex Williamson | s->ram = qemu_ram_alloc(NULL, "onenand.ram", 0xc000 << s->shift); |
642 | 5c130f65 | pbrook | ram = qemu_get_ram_ptr(s->ram); |
643 | 7e7c5e4c | balrog | s->boot[0] = ram + (0x0000 << s->shift); |
644 | 7e7c5e4c | balrog | s->boot[1] = ram + (0x8000 << s->shift); |
645 | 7e7c5e4c | balrog | s->data[0][0] = ram + ((0x0200 + (0 << (PAGE_SHIFT - 1))) << s->shift); |
646 | 7e7c5e4c | balrog | s->data[0][1] = ram + ((0x8010 + (0 << (PAGE_SHIFT - 6))) << s->shift); |
647 | 7e7c5e4c | balrog | s->data[1][0] = ram + ((0x0200 + (1 << (PAGE_SHIFT - 1))) << s->shift); |
648 | 7e7c5e4c | balrog | s->data[1][1] = ram + ((0x8010 + (1 << (PAGE_SHIFT - 6))) << s->shift); |
649 | 7e7c5e4c | balrog | |
650 | 7e7c5e4c | balrog | onenand_reset(s, 1);
|
651 | 7e7c5e4c | balrog | |
652 | 7e7c5e4c | balrog | return s;
|
653 | 7e7c5e4c | balrog | } |
654 | c580d92b | balrog | |
655 | c580d92b | balrog | void *onenand_raw_otp(void *opaque) |
656 | c580d92b | balrog | { |
657 | bc24a225 | Paul Brook | OneNANDState *s = (OneNANDState *) opaque; |
658 | c580d92b | balrog | |
659 | c580d92b | balrog | return s->otp;
|
660 | c580d92b | balrog | } |