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