root / hw / onenand.c @ a3867ed2
History | View | Annotate | Download (19.4 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 | 7e7c5e4c | balrog | struct onenand_s {
|
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 | 7e7c5e4c | balrog | struct ecc_state_s 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 | 7e7c5e4c | balrog | }; |
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 | 7e7c5e4c | balrog | struct onenand_s *s = (struct onenand_s *) 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 | 7e7c5e4c | balrog | struct onenand_s *s = (struct onenand_s *) 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 | 7e7c5e4c | balrog | static void onenand_intr_update(struct onenand_s *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 | 7e7c5e4c | balrog | static void onenand_reset(struct onenand_s *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 | 7e7c5e4c | balrog | cpu_abort(cpu_single_env, "%s: Loading the BootRAM failed.\n",
|
160 | 7e7c5e4c | balrog | __FUNCTION__); |
161 | 7e7c5e4c | balrog | } |
162 | 7e7c5e4c | balrog | } |
163 | 7e7c5e4c | balrog | |
164 | 7e7c5e4c | balrog | static inline int onenand_load_main(struct onenand_s *s, int sec, int secn, |
165 | 7e7c5e4c | balrog | void *dest)
|
166 | 7e7c5e4c | balrog | { |
167 | 7e7c5e4c | balrog | if (s->bdrv_cur)
|
168 | 7e7c5e4c | balrog | return bdrv_read(s->bdrv_cur, sec, dest, secn) < 0; |
169 | 7e7c5e4c | balrog | else if (sec + secn > s->secs_cur) |
170 | 7e7c5e4c | balrog | return 1; |
171 | 7e7c5e4c | balrog | |
172 | 7e7c5e4c | balrog | memcpy(dest, s->current + (sec << 9), secn << 9); |
173 | 7e7c5e4c | balrog | |
174 | 7e7c5e4c | balrog | return 0; |
175 | 7e7c5e4c | balrog | } |
176 | 7e7c5e4c | balrog | |
177 | 7e7c5e4c | balrog | static inline int onenand_prog_main(struct onenand_s *s, int sec, int secn, |
178 | 7e7c5e4c | balrog | void *src)
|
179 | 7e7c5e4c | balrog | { |
180 | 7e7c5e4c | balrog | if (s->bdrv_cur)
|
181 | 7e7c5e4c | balrog | return bdrv_write(s->bdrv_cur, sec, src, secn) < 0; |
182 | 7e7c5e4c | balrog | else if (sec + secn > s->secs_cur) |
183 | 7e7c5e4c | balrog | return 1; |
184 | 7e7c5e4c | balrog | |
185 | 7e7c5e4c | balrog | memcpy(s->current + (sec << 9), src, secn << 9); |
186 | 7e7c5e4c | balrog | |
187 | 7e7c5e4c | balrog | return 0; |
188 | 7e7c5e4c | balrog | } |
189 | 7e7c5e4c | balrog | |
190 | 7e7c5e4c | balrog | static inline int onenand_load_spare(struct onenand_s *s, int sec, int secn, |
191 | 7e7c5e4c | balrog | void *dest)
|
192 | 7e7c5e4c | balrog | { |
193 | 7e7c5e4c | balrog | uint8_t buf[512];
|
194 | 7e7c5e4c | balrog | |
195 | 7e7c5e4c | balrog | if (s->bdrv_cur) {
|
196 | 7e7c5e4c | balrog | if (bdrv_read(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) |
197 | 7e7c5e4c | balrog | return 1; |
198 | 7e7c5e4c | balrog | memcpy(dest, buf + ((sec & 31) << 4), secn << 4); |
199 | 7e7c5e4c | balrog | } else if (sec + secn > s->secs_cur) |
200 | 7e7c5e4c | balrog | return 1; |
201 | 7e7c5e4c | balrog | else
|
202 | 7e7c5e4c | balrog | memcpy(dest, s->current + (s->secs_cur << 9) + (sec << 4), secn << 4); |
203 | 7e7c5e4c | balrog | |
204 | 7e7c5e4c | balrog | return 0; |
205 | 7e7c5e4c | balrog | } |
206 | 7e7c5e4c | balrog | |
207 | 7e7c5e4c | balrog | static inline int onenand_prog_spare(struct onenand_s *s, int sec, int secn, |
208 | 7e7c5e4c | balrog | void *src)
|
209 | 7e7c5e4c | balrog | { |
210 | 7e7c5e4c | balrog | uint8_t buf[512];
|
211 | 7e7c5e4c | balrog | |
212 | 7e7c5e4c | balrog | if (s->bdrv_cur) {
|
213 | 7e7c5e4c | balrog | if (bdrv_read(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0) |
214 | 7e7c5e4c | balrog | return 1; |
215 | 7e7c5e4c | balrog | memcpy(buf + ((sec & 31) << 4), src, secn << 4); |
216 | 7e7c5e4c | balrog | return bdrv_write(s->bdrv_cur, s->secs_cur + (sec >> 5), buf, 1) < 0; |
217 | 7e7c5e4c | balrog | } else if (sec + secn > s->secs_cur) |
218 | 7e7c5e4c | balrog | return 1; |
219 | 7e7c5e4c | balrog | |
220 | 7e7c5e4c | balrog | memcpy(s->current + (s->secs_cur << 9) + (sec << 4), src, secn << 4); |
221 | 7e7c5e4c | balrog | |
222 | 7e7c5e4c | balrog | return 0; |
223 | 7e7c5e4c | balrog | } |
224 | 7e7c5e4c | balrog | |
225 | 7e7c5e4c | balrog | static inline int onenand_erase(struct onenand_s *s, int sec, int num) |
226 | 7e7c5e4c | balrog | { |
227 | 7e7c5e4c | balrog | /* TODO: optimise */
|
228 | 7e7c5e4c | balrog | uint8_t buf[512];
|
229 | 7e7c5e4c | balrog | |
230 | 7e7c5e4c | balrog | memset(buf, 0xff, sizeof(buf)); |
231 | 7e7c5e4c | balrog | for (; num > 0; num --, sec ++) { |
232 | 7e7c5e4c | balrog | if (onenand_prog_main(s, sec, 1, buf)) |
233 | 7e7c5e4c | balrog | return 1; |
234 | 7e7c5e4c | balrog | if (onenand_prog_spare(s, sec, 1, buf)) |
235 | 7e7c5e4c | balrog | return 1; |
236 | 7e7c5e4c | balrog | } |
237 | 7e7c5e4c | balrog | |
238 | 7e7c5e4c | balrog | return 0; |
239 | 7e7c5e4c | balrog | } |
240 | 7e7c5e4c | balrog | |
241 | 7e7c5e4c | balrog | static void onenand_command(struct onenand_s *s, int cmd) |
242 | 7e7c5e4c | balrog | { |
243 | 7e7c5e4c | balrog | int b;
|
244 | 7e7c5e4c | balrog | int sec;
|
245 | 7e7c5e4c | balrog | void *buf;
|
246 | 7e7c5e4c | balrog | #define SETADDR(block, page) \
|
247 | 7e7c5e4c | balrog | sec = (s->addr[page] & 3) + \
|
248 | 7e7c5e4c | balrog | ((((s->addr[page] >> 2) & 0x3f) + \ |
249 | 7e7c5e4c | balrog | (((s->addr[block] & 0xfff) | \
|
250 | 7e7c5e4c | balrog | (s->addr[block] >> 15 ? \
|
251 | 7e7c5e4c | balrog | s->density_mask : 0)) << 6)) << (PAGE_SHIFT - 9)); |
252 | 7e7c5e4c | balrog | #define SETBUF_M() \
|
253 | 7e7c5e4c | balrog | buf = (s->bufaddr & 8) ? \
|
254 | 7e7c5e4c | balrog | s->data[(s->bufaddr >> 2) & 1][0] : s->boot[0]; \ |
255 | 7e7c5e4c | balrog | buf += (s->bufaddr & 3) << 9; |
256 | 7e7c5e4c | balrog | #define SETBUF_S() \
|
257 | 7e7c5e4c | balrog | buf = (s->bufaddr & 8) ? \
|
258 | 7e7c5e4c | balrog | s->data[(s->bufaddr >> 2) & 1][1] : s->boot[1]; \ |
259 | 7e7c5e4c | balrog | buf += (s->bufaddr & 3) << 4; |
260 | 7e7c5e4c | balrog | |
261 | 7e7c5e4c | balrog | switch (cmd) {
|
262 | 7e7c5e4c | balrog | case 0x00: /* Load single/multiple sector data unit into buffer */ |
263 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
264 | 7e7c5e4c | balrog | |
265 | 7e7c5e4c | balrog | SETBUF_M() |
266 | 7e7c5e4c | balrog | if (onenand_load_main(s, sec, s->count, buf))
|
267 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_LOAD; |
268 | 7e7c5e4c | balrog | |
269 | 7e7c5e4c | balrog | #if 0
|
270 | 7e7c5e4c | balrog | SETBUF_S()
|
271 | 7e7c5e4c | balrog | if (onenand_load_spare(s, sec, s->count, buf))
|
272 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_LOAD;
|
273 | 7e7c5e4c | balrog | #endif
|
274 | 7e7c5e4c | balrog | |
275 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
276 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
277 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
278 | 7e7c5e4c | balrog | */
|
279 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_LOAD; |
280 | 7e7c5e4c | balrog | break;
|
281 | 7e7c5e4c | balrog | case 0x13: /* Load single/multiple spare sector into buffer */ |
282 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
283 | 7e7c5e4c | balrog | |
284 | 7e7c5e4c | balrog | SETBUF_S() |
285 | 7e7c5e4c | balrog | if (onenand_load_spare(s, sec, s->count, buf))
|
286 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_LOAD; |
287 | 7e7c5e4c | balrog | |
288 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
289 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
290 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
291 | 7e7c5e4c | balrog | */
|
292 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_LOAD; |
293 | 7e7c5e4c | balrog | break;
|
294 | 7e7c5e4c | balrog | case 0x80: /* Program single/multiple sector data unit from buffer */ |
295 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
296 | 7e7c5e4c | balrog | |
297 | 7e7c5e4c | balrog | SETBUF_M() |
298 | 7e7c5e4c | balrog | if (onenand_prog_main(s, sec, s->count, buf))
|
299 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
300 | 7e7c5e4c | balrog | |
301 | 7e7c5e4c | balrog | #if 0
|
302 | 7e7c5e4c | balrog | SETBUF_S()
|
303 | 7e7c5e4c | balrog | if (onenand_prog_spare(s, sec, s->count, buf))
|
304 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG;
|
305 | 7e7c5e4c | balrog | #endif
|
306 | 7e7c5e4c | balrog | |
307 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
308 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
309 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
310 | 7e7c5e4c | balrog | */
|
311 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_PROG; |
312 | 7e7c5e4c | balrog | break;
|
313 | 7e7c5e4c | balrog | case 0x1a: /* Program single/multiple spare area sector from buffer */ |
314 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
315 | 7e7c5e4c | balrog | |
316 | 7e7c5e4c | balrog | SETBUF_S() |
317 | 7e7c5e4c | balrog | if (onenand_prog_spare(s, sec, s->count, buf))
|
318 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
319 | 7e7c5e4c | balrog | |
320 | 7e7c5e4c | balrog | /* TODO: if (s->bufaddr & 3) + s->count was > 4 (2k-pages)
|
321 | 7e7c5e4c | balrog | * or if (s->bufaddr & 1) + s->count was > 2 (1k-pages)
|
322 | 7e7c5e4c | balrog | * then we need two split the read/write into two chunks.
|
323 | 7e7c5e4c | balrog | */
|
324 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_PROG; |
325 | 7e7c5e4c | balrog | break;
|
326 | 7e7c5e4c | balrog | case 0x1b: /* Copy-back program */ |
327 | 7e7c5e4c | balrog | SETBUF_S() |
328 | 7e7c5e4c | balrog | |
329 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
330 | 7e7c5e4c | balrog | if (onenand_load_main(s, sec, s->count, buf))
|
331 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
332 | 7e7c5e4c | balrog | |
333 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_DEST_BLOCK, ONEN_BUF_DEST_PAGE) |
334 | 7e7c5e4c | balrog | if (onenand_prog_main(s, sec, s->count, buf))
|
335 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_PROG; |
336 | 7e7c5e4c | balrog | |
337 | 7e7c5e4c | balrog | /* TODO: spare areas */
|
338 | 7e7c5e4c | balrog | |
339 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_PROG; |
340 | 7e7c5e4c | balrog | break;
|
341 | 7e7c5e4c | balrog | |
342 | 7e7c5e4c | balrog | case 0x23: /* Unlock NAND array block(s) */ |
343 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
344 | 7e7c5e4c | balrog | |
345 | 7e7c5e4c | balrog | /* XXX the previous (?) area should be locked automatically */
|
346 | 7e7c5e4c | balrog | for (b = s->unladdr[0]; b <= s->unladdr[1]; b ++) { |
347 | 7e7c5e4c | balrog | if (b >= s->blocks) {
|
348 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
349 | 7e7c5e4c | balrog | break;
|
350 | 7e7c5e4c | balrog | } |
351 | 7e7c5e4c | balrog | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN)
|
352 | 7e7c5e4c | balrog | break;
|
353 | 7e7c5e4c | balrog | |
354 | 7e7c5e4c | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_UNLOCKED; |
355 | 7e7c5e4c | balrog | } |
356 | 7e7c5e4c | balrog | break;
|
357 | 89588a4b | balrog | case 0x27: /* Unlock All NAND array blocks */ |
358 | 89588a4b | balrog | s->intstatus |= ONEN_INT; |
359 | 89588a4b | balrog | |
360 | 89588a4b | balrog | for (b = 0; b < s->blocks; b ++) { |
361 | 89588a4b | balrog | if (b >= s->blocks) {
|
362 | 89588a4b | balrog | s->status |= ONEN_ERR_CMD; |
363 | 89588a4b | balrog | break;
|
364 | 89588a4b | balrog | } |
365 | 89588a4b | balrog | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN)
|
366 | 89588a4b | balrog | break;
|
367 | 89588a4b | balrog | |
368 | 89588a4b | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_UNLOCKED; |
369 | 89588a4b | balrog | } |
370 | 89588a4b | balrog | break;
|
371 | 89588a4b | balrog | |
372 | 7e7c5e4c | balrog | case 0x2a: /* Lock NAND array block(s) */ |
373 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
374 | 7e7c5e4c | balrog | |
375 | 7e7c5e4c | balrog | for (b = s->unladdr[0]; b <= s->unladdr[1]; b ++) { |
376 | 7e7c5e4c | balrog | if (b >= s->blocks) {
|
377 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
378 | 7e7c5e4c | balrog | break;
|
379 | 7e7c5e4c | balrog | } |
380 | 7e7c5e4c | balrog | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN)
|
381 | 7e7c5e4c | balrog | break;
|
382 | 7e7c5e4c | balrog | |
383 | 7e7c5e4c | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_LOCKED; |
384 | 7e7c5e4c | balrog | } |
385 | 7e7c5e4c | balrog | break;
|
386 | 7e7c5e4c | balrog | case 0x2c: /* Lock-tight NAND array block(s) */ |
387 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
388 | 7e7c5e4c | balrog | |
389 | 7e7c5e4c | balrog | for (b = s->unladdr[0]; b <= s->unladdr[1]; b ++) { |
390 | 7e7c5e4c | balrog | if (b >= s->blocks) {
|
391 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
392 | 7e7c5e4c | balrog | break;
|
393 | 7e7c5e4c | balrog | } |
394 | 7e7c5e4c | balrog | if (s->blockwp[b] == ONEN_LOCK_UNLOCKED)
|
395 | 7e7c5e4c | balrog | continue;
|
396 | 7e7c5e4c | balrog | |
397 | 7e7c5e4c | balrog | s->wpstatus = s->blockwp[b] = ONEN_LOCK_LOCKTIGHTEN; |
398 | 7e7c5e4c | balrog | } |
399 | 7e7c5e4c | balrog | break;
|
400 | 7e7c5e4c | balrog | |
401 | 7e7c5e4c | balrog | case 0x71: /* Erase-Verify-Read */ |
402 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
403 | 7e7c5e4c | balrog | break;
|
404 | 7e7c5e4c | balrog | case 0x95: /* Multi-block erase */ |
405 | 7e7c5e4c | balrog | qemu_irq_pulse(s->intr); |
406 | 7e7c5e4c | balrog | /* Fall through. */
|
407 | 7e7c5e4c | balrog | case 0x94: /* Block erase */ |
408 | 7e7c5e4c | balrog | sec = ((s->addr[ONEN_BUF_BLOCK] & 0xfff) |
|
409 | 7e7c5e4c | balrog | (s->addr[ONEN_BUF_BLOCK] >> 15 ? s->density_mask : 0)) |
410 | 7e7c5e4c | balrog | << (BLOCK_SHIFT - 9);
|
411 | 7e7c5e4c | balrog | if (onenand_erase(s, sec, 1 << (BLOCK_SHIFT - 9))) |
412 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD | ONEN_ERR_ERASE; |
413 | 7e7c5e4c | balrog | |
414 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_ERASE; |
415 | 7e7c5e4c | balrog | break;
|
416 | 7e7c5e4c | balrog | case 0xb0: /* Erase suspend */ |
417 | 7e7c5e4c | balrog | break;
|
418 | 7e7c5e4c | balrog | case 0x30: /* Erase resume */ |
419 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT | ONEN_INT_ERASE; |
420 | 7e7c5e4c | balrog | break;
|
421 | 7e7c5e4c | balrog | |
422 | 7e7c5e4c | balrog | case 0xf0: /* Reset NAND Flash core */ |
423 | 7e7c5e4c | balrog | onenand_reset(s, 0);
|
424 | 7e7c5e4c | balrog | break;
|
425 | 7e7c5e4c | balrog | case 0xf3: /* Reset OneNAND */ |
426 | 7e7c5e4c | balrog | onenand_reset(s, 0);
|
427 | 7e7c5e4c | balrog | break;
|
428 | 7e7c5e4c | balrog | |
429 | 7e7c5e4c | balrog | case 0x65: /* OTP Access */ |
430 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
431 | 7e7c5e4c | balrog | s->bdrv_cur = 0;
|
432 | 7e7c5e4c | balrog | s->current = s->otp; |
433 | 7e7c5e4c | balrog | s->secs_cur = 1 << (BLOCK_SHIFT - 9); |
434 | 7e7c5e4c | balrog | s->addr[ONEN_BUF_BLOCK] = 0;
|
435 | 7e7c5e4c | balrog | s->otpmode = 1;
|
436 | 7e7c5e4c | balrog | break;
|
437 | 7e7c5e4c | balrog | |
438 | 7e7c5e4c | balrog | default:
|
439 | 7e7c5e4c | balrog | s->status |= ONEN_ERR_CMD; |
440 | 7e7c5e4c | balrog | s->intstatus |= ONEN_INT; |
441 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND command %x\n",
|
442 | 7e7c5e4c | balrog | __FUNCTION__, cmd); |
443 | 7e7c5e4c | balrog | } |
444 | 7e7c5e4c | balrog | |
445 | 7e7c5e4c | balrog | onenand_intr_update(s); |
446 | 7e7c5e4c | balrog | } |
447 | 7e7c5e4c | balrog | |
448 | 7e7c5e4c | balrog | static uint32_t onenand_read(void *opaque, target_phys_addr_t addr) |
449 | 7e7c5e4c | balrog | { |
450 | 7e7c5e4c | balrog | struct onenand_s *s = (struct onenand_s *) opaque; |
451 | 8da3ff18 | pbrook | int offset = addr >> s->shift;
|
452 | 7e7c5e4c | balrog | |
453 | 7e7c5e4c | balrog | switch (offset) {
|
454 | 7e7c5e4c | balrog | case 0x0000 ... 0xc000: |
455 | 8da3ff18 | pbrook | return lduw_le_p(s->boot[0] + addr); |
456 | 7e7c5e4c | balrog | |
457 | 7e7c5e4c | balrog | case 0xf000: /* Manufacturer ID */ |
458 | 7e7c5e4c | balrog | return (s->id >> 16) & 0xff; |
459 | 7e7c5e4c | balrog | case 0xf001: /* Device ID */ |
460 | 7e7c5e4c | balrog | return (s->id >> 8) & 0xff; |
461 | 7e7c5e4c | balrog | /* TODO: get the following values from a real chip! */
|
462 | 7e7c5e4c | balrog | case 0xf002: /* Version ID */ |
463 | 7e7c5e4c | balrog | return (s->id >> 0) & 0xff; |
464 | 7e7c5e4c | balrog | case 0xf003: /* Data Buffer size */ |
465 | 7e7c5e4c | balrog | return 1 << PAGE_SHIFT; |
466 | 7e7c5e4c | balrog | case 0xf004: /* Boot Buffer size */ |
467 | 7e7c5e4c | balrog | return 0x200; |
468 | 7e7c5e4c | balrog | case 0xf005: /* Amount of buffers */ |
469 | 7e7c5e4c | balrog | return 1 | (2 << 8); |
470 | 7e7c5e4c | balrog | case 0xf006: /* Technology */ |
471 | 7e7c5e4c | balrog | return 0; |
472 | 7e7c5e4c | balrog | |
473 | 7e7c5e4c | balrog | case 0xf100 ... 0xf107: /* Start addresses */ |
474 | 7e7c5e4c | balrog | return s->addr[offset - 0xf100]; |
475 | 7e7c5e4c | balrog | |
476 | 7e7c5e4c | balrog | case 0xf200: /* Start buffer */ |
477 | 7e7c5e4c | balrog | return (s->bufaddr << 8) | ((s->count - 1) & (1 << (PAGE_SHIFT - 10))); |
478 | 7e7c5e4c | balrog | |
479 | 7e7c5e4c | balrog | case 0xf220: /* Command */ |
480 | 7e7c5e4c | balrog | return s->command;
|
481 | 7e7c5e4c | balrog | case 0xf221: /* System Configuration 1 */ |
482 | 7e7c5e4c | balrog | return s->config[0] & 0xffe0; |
483 | 7e7c5e4c | balrog | case 0xf222: /* System Configuration 2 */ |
484 | 7e7c5e4c | balrog | return s->config[1]; |
485 | 7e7c5e4c | balrog | |
486 | 7e7c5e4c | balrog | case 0xf240: /* Controller Status */ |
487 | 7e7c5e4c | balrog | return s->status;
|
488 | 7e7c5e4c | balrog | case 0xf241: /* Interrupt */ |
489 | 7e7c5e4c | balrog | return s->intstatus;
|
490 | 7e7c5e4c | balrog | case 0xf24c: /* Unlock Start Block Address */ |
491 | 7e7c5e4c | balrog | return s->unladdr[0]; |
492 | 7e7c5e4c | balrog | case 0xf24d: /* Unlock End Block Address */ |
493 | 7e7c5e4c | balrog | return s->unladdr[1]; |
494 | 7e7c5e4c | balrog | case 0xf24e: /* Write Protection Status */ |
495 | 7e7c5e4c | balrog | return s->wpstatus;
|
496 | 7e7c5e4c | balrog | |
497 | 7e7c5e4c | balrog | case 0xff00: /* ECC Status */ |
498 | 7e7c5e4c | balrog | return 0x00; |
499 | 7e7c5e4c | balrog | case 0xff01: /* ECC Result of main area data */ |
500 | 7e7c5e4c | balrog | case 0xff02: /* ECC Result of spare area data */ |
501 | 7e7c5e4c | balrog | case 0xff03: /* ECC Result of main area data */ |
502 | 7e7c5e4c | balrog | case 0xff04: /* ECC Result of spare area data */ |
503 | 7e7c5e4c | balrog | cpu_abort(cpu_single_env, "%s: imeplement ECC\n", __FUNCTION__);
|
504 | 7e7c5e4c | balrog | return 0x0000; |
505 | 7e7c5e4c | balrog | } |
506 | 7e7c5e4c | balrog | |
507 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND register %x\n",
|
508 | 7e7c5e4c | balrog | __FUNCTION__, offset); |
509 | 7e7c5e4c | balrog | return 0; |
510 | 7e7c5e4c | balrog | } |
511 | 7e7c5e4c | balrog | |
512 | 7e7c5e4c | balrog | static void onenand_write(void *opaque, target_phys_addr_t addr, |
513 | 7e7c5e4c | balrog | uint32_t value) |
514 | 7e7c5e4c | balrog | { |
515 | 7e7c5e4c | balrog | struct onenand_s *s = (struct onenand_s *) opaque; |
516 | 8da3ff18 | pbrook | int offset = addr >> s->shift;
|
517 | 7e7c5e4c | balrog | int sec;
|
518 | 7e7c5e4c | balrog | |
519 | 7e7c5e4c | balrog | switch (offset) {
|
520 | 7e7c5e4c | balrog | case 0x0000 ... 0x01ff: |
521 | 7e7c5e4c | balrog | case 0x8000 ... 0x800f: |
522 | 7e7c5e4c | balrog | if (s->cycle) {
|
523 | 7e7c5e4c | balrog | s->cycle = 0;
|
524 | 7e7c5e4c | balrog | |
525 | 7e7c5e4c | balrog | if (value == 0x0000) { |
526 | 7e7c5e4c | balrog | SETADDR(ONEN_BUF_BLOCK, ONEN_BUF_PAGE) |
527 | 7e7c5e4c | balrog | onenand_load_main(s, sec, |
528 | 7e7c5e4c | balrog | 1 << (PAGE_SHIFT - 9), s->data[0][0]); |
529 | 7e7c5e4c | balrog | s->addr[ONEN_BUF_PAGE] += 4;
|
530 | 7e7c5e4c | balrog | s->addr[ONEN_BUF_PAGE] &= 0xff;
|
531 | 7e7c5e4c | balrog | } |
532 | 7e7c5e4c | balrog | break;
|
533 | 7e7c5e4c | balrog | } |
534 | 7e7c5e4c | balrog | |
535 | 7e7c5e4c | balrog | switch (value) {
|
536 | 7e7c5e4c | balrog | case 0x00f0: /* Reset OneNAND */ |
537 | 7e7c5e4c | balrog | onenand_reset(s, 0);
|
538 | 7e7c5e4c | balrog | break;
|
539 | 7e7c5e4c | balrog | |
540 | 7e7c5e4c | balrog | case 0x00e0: /* Load Data into Buffer */ |
541 | 7e7c5e4c | balrog | s->cycle = 1;
|
542 | 7e7c5e4c | balrog | break;
|
543 | 7e7c5e4c | balrog | |
544 | 7e7c5e4c | balrog | case 0x0090: /* Read Identification Data */ |
545 | 7e7c5e4c | balrog | memset(s->boot[0], 0, 3 << s->shift); |
546 | 7e7c5e4c | balrog | s->boot[0][0 << s->shift] = (s->id >> 16) & 0xff; |
547 | 7e7c5e4c | balrog | s->boot[0][1 << s->shift] = (s->id >> 8) & 0xff; |
548 | 7e7c5e4c | balrog | s->boot[0][2 << s->shift] = s->wpstatus & 0xff; |
549 | 7e7c5e4c | balrog | break;
|
550 | 7e7c5e4c | balrog | |
551 | 7e7c5e4c | balrog | default:
|
552 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND boot command %x\n",
|
553 | 7e7c5e4c | balrog | __FUNCTION__, value); |
554 | 7e7c5e4c | balrog | } |
555 | 7e7c5e4c | balrog | break;
|
556 | 7e7c5e4c | balrog | |
557 | 7e7c5e4c | balrog | case 0xf100 ... 0xf107: /* Start addresses */ |
558 | 7e7c5e4c | balrog | s->addr[offset - 0xf100] = value;
|
559 | 7e7c5e4c | balrog | break;
|
560 | 7e7c5e4c | balrog | |
561 | 7e7c5e4c | balrog | case 0xf200: /* Start buffer */ |
562 | 7e7c5e4c | balrog | s->bufaddr = (value >> 8) & 0xf; |
563 | 7e7c5e4c | balrog | if (PAGE_SHIFT == 11) |
564 | 7e7c5e4c | balrog | s->count = (value & 3) ?: 4; |
565 | 7e7c5e4c | balrog | else if (PAGE_SHIFT == 10) |
566 | 7e7c5e4c | balrog | s->count = (value & 1) ?: 2; |
567 | 7e7c5e4c | balrog | break;
|
568 | 7e7c5e4c | balrog | |
569 | 7e7c5e4c | balrog | case 0xf220: /* Command */ |
570 | 7e7c5e4c | balrog | if (s->intstatus & (1 << 15)) |
571 | 7e7c5e4c | balrog | break;
|
572 | 7e7c5e4c | balrog | s->command = value; |
573 | 7e7c5e4c | balrog | onenand_command(s, s->command); |
574 | 7e7c5e4c | balrog | break;
|
575 | 7e7c5e4c | balrog | case 0xf221: /* System Configuration 1 */ |
576 | 7e7c5e4c | balrog | s->config[0] = value;
|
577 | 7e7c5e4c | balrog | onenand_intr_update(s); |
578 | 7e7c5e4c | balrog | qemu_set_irq(s->rdy, (s->config[0] >> 7) & 1); |
579 | 7e7c5e4c | balrog | break;
|
580 | 7e7c5e4c | balrog | case 0xf222: /* System Configuration 2 */ |
581 | 7e7c5e4c | balrog | s->config[1] = value;
|
582 | 7e7c5e4c | balrog | break;
|
583 | 7e7c5e4c | balrog | |
584 | 7e7c5e4c | balrog | case 0xf241: /* Interrupt */ |
585 | 7e7c5e4c | balrog | s->intstatus &= value; |
586 | 7e7c5e4c | balrog | if ((1 << 15) & ~s->intstatus) |
587 | 7e7c5e4c | balrog | s->status &= ~(ONEN_ERR_CMD | ONEN_ERR_ERASE | |
588 | 7e7c5e4c | balrog | ONEN_ERR_PROG | ONEN_ERR_LOAD); |
589 | 7e7c5e4c | balrog | onenand_intr_update(s); |
590 | 7e7c5e4c | balrog | break;
|
591 | 7e7c5e4c | balrog | case 0xf24c: /* Unlock Start Block Address */ |
592 | 7e7c5e4c | balrog | s->unladdr[0] = value & (s->blocks - 1); |
593 | 7e7c5e4c | balrog | /* For some reason we have to set the end address to by default
|
594 | 7e7c5e4c | balrog | * be same as start because the software forgets to write anything
|
595 | 7e7c5e4c | balrog | * in there. */
|
596 | 7e7c5e4c | balrog | s->unladdr[1] = value & (s->blocks - 1); |
597 | 7e7c5e4c | balrog | break;
|
598 | 7e7c5e4c | balrog | case 0xf24d: /* Unlock End Block Address */ |
599 | 7e7c5e4c | balrog | s->unladdr[1] = value & (s->blocks - 1); |
600 | 7e7c5e4c | balrog | break;
|
601 | 7e7c5e4c | balrog | |
602 | 7e7c5e4c | balrog | default:
|
603 | 7e7c5e4c | balrog | fprintf(stderr, "%s: unknown OneNAND register %x\n",
|
604 | 7e7c5e4c | balrog | __FUNCTION__, offset); |
605 | 7e7c5e4c | balrog | } |
606 | 7e7c5e4c | balrog | } |
607 | 7e7c5e4c | balrog | |
608 | 7e7c5e4c | balrog | static CPUReadMemoryFunc *onenand_readfn[] = {
|
609 | 7e7c5e4c | balrog | onenand_read, /* TODO */
|
610 | 7e7c5e4c | balrog | onenand_read, |
611 | 7e7c5e4c | balrog | onenand_read, |
612 | 7e7c5e4c | balrog | }; |
613 | 7e7c5e4c | balrog | |
614 | 7e7c5e4c | balrog | static CPUWriteMemoryFunc *onenand_writefn[] = {
|
615 | 7e7c5e4c | balrog | onenand_write, /* TODO */
|
616 | 7e7c5e4c | balrog | onenand_write, |
617 | 7e7c5e4c | balrog | onenand_write, |
618 | 7e7c5e4c | balrog | }; |
619 | 7e7c5e4c | balrog | |
620 | 7e7c5e4c | balrog | void *onenand_init(uint32_t id, int regshift, qemu_irq irq) |
621 | 7e7c5e4c | balrog | { |
622 | 7e7c5e4c | balrog | struct onenand_s *s = (struct onenand_s *) qemu_mallocz(sizeof(*s)); |
623 | 7e7c5e4c | balrog | int bdrv_index = drive_get_index(IF_MTD, 0, 0); |
624 | 7e7c5e4c | balrog | uint32_t size = 1 << (24 + ((id >> 12) & 7)); |
625 | 7e7c5e4c | balrog | void *ram;
|
626 | 7e7c5e4c | balrog | |
627 | 7e7c5e4c | balrog | s->shift = regshift; |
628 | 7e7c5e4c | balrog | s->intr = irq; |
629 | 7e7c5e4c | balrog | s->rdy = 0;
|
630 | 7e7c5e4c | balrog | s->id = id; |
631 | 7e7c5e4c | balrog | s->blocks = size >> BLOCK_SHIFT; |
632 | 7e7c5e4c | balrog | s->secs = size >> 9;
|
633 | 7e7c5e4c | balrog | s->blockwp = qemu_malloc(s->blocks); |
634 | 7e7c5e4c | balrog | s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0; |
635 | 7e7c5e4c | balrog | s->iomemtype = cpu_register_io_memory(0, onenand_readfn,
|
636 | 7e7c5e4c | balrog | onenand_writefn, s); |
637 | 7e7c5e4c | balrog | if (bdrv_index == -1) |
638 | 7e7c5e4c | balrog | s->image = memset(qemu_malloc(size + (size >> 5)),
|
639 | 7e7c5e4c | balrog | 0xff, size + (size >> 5)); |
640 | 7e7c5e4c | balrog | else
|
641 | 7e7c5e4c | balrog | s->bdrv = drives_table[bdrv_index].bdrv; |
642 | 7e7c5e4c | balrog | s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT), |
643 | 7e7c5e4c | balrog | 0xff, (64 + 2) << PAGE_SHIFT); |
644 | 7e7c5e4c | balrog | s->ram = qemu_ram_alloc(0xc000 << s->shift);
|
645 | 5c130f65 | pbrook | ram = qemu_get_ram_ptr(s->ram); |
646 | 7e7c5e4c | balrog | s->boot[0] = ram + (0x0000 << s->shift); |
647 | 7e7c5e4c | balrog | s->boot[1] = ram + (0x8000 << s->shift); |
648 | 7e7c5e4c | balrog | s->data[0][0] = ram + ((0x0200 + (0 << (PAGE_SHIFT - 1))) << s->shift); |
649 | 7e7c5e4c | balrog | s->data[0][1] = ram + ((0x8010 + (0 << (PAGE_SHIFT - 6))) << s->shift); |
650 | 7e7c5e4c | balrog | s->data[1][0] = ram + ((0x0200 + (1 << (PAGE_SHIFT - 1))) << s->shift); |
651 | 7e7c5e4c | balrog | s->data[1][1] = ram + ((0x8010 + (1 << (PAGE_SHIFT - 6))) << s->shift); |
652 | 7e7c5e4c | balrog | |
653 | 7e7c5e4c | balrog | onenand_reset(s, 1);
|
654 | 7e7c5e4c | balrog | |
655 | 7e7c5e4c | balrog | return s;
|
656 | 7e7c5e4c | balrog | } |
657 | c580d92b | balrog | |
658 | c580d92b | balrog | void *onenand_raw_otp(void *opaque) |
659 | c580d92b | balrog | { |
660 | c580d92b | balrog | struct onenand_s *s = (struct onenand_s *) opaque; |
661 | c580d92b | balrog | |
662 | c580d92b | balrog | return s->otp;
|
663 | c580d92b | balrog | } |