Mercurial > yaffs-ecoscentric
annotate direct/yaffs_fileem2k.c @ 259:fe540b3f699b
Tweak tests
| author | charles |
|---|---|
| date | Fri, 16 Jan 2009 02:26:56 +0000 |
| parents | 3bd2a4e3262f |
| children | 5d34d18f33e5 |
| rev | line source |
|---|---|
| 1 | 1 /* |
| 173 | 2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. |
| 1 | 3 * |
| 173 | 4 * Copyright (C) 2002-2007 Aleph One Ltd. |
| 5 * for Toby Churchill Ltd and Brightstar Engineering | |
| 1 | 6 * |
| 7 * Created by Charles Manning <charles@aleph1.co.uk> | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or modify | |
| 10 * it under the terms of the GNU General Public License version 2 as | |
| 11 * published by the Free Software Foundation. | |
| 12 */ | |
| 13 | |
| 173 | 14 /* |
| 15 * This provides a YAFFS nand emulation on a file for emulating 2kB pages. | |
| 16 * This is only intended as test code to test persistence etc. | |
| 17 */ | |
| 1 | 18 |
| 215 | 19 const char *yaffs_flashif2_c_version = "$Id$"; |
| 1 | 20 |
| 21 | |
| 22 #include "yportenv.h" | |
| 23 | |
| 215 | 24 #include "yaffs_flashif2.h" |
| 1 | 25 #include "yaffs_guts.h" |
| 26 #include "devextras.h" | |
| 27 | |
| 28 #include <sys/types.h> | |
| 29 #include <sys/stat.h> | |
| 30 #include <fcntl.h> | |
| 31 #include <unistd.h> | |
| 32 | |
| 33 #include "yaffs_fileem2k.h" | |
| 6 | 34 #include "yaffs_packedtags2.h" |
| 1 | 35 |
| 36 | |
| 215 | 37 |
| 38 #define REPORT_ERROR 0 | |
| 39 | |
| 1 | 40 typedef struct |
| 41 { | |
| 42 __u8 data[PAGE_SIZE]; // Data + spare | |
| 43 } yflash_Page; | |
| 44 | |
| 45 typedef struct | |
| 46 { | |
| 47 yflash_Page page[PAGES_PER_BLOCK]; // The pages in the block | |
| 48 | |
| 49 } yflash_Block; | |
| 50 | |
| 51 | |
| 52 | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
53 #define MAX_HANDLES 20 |
| 256 | 54 #define BLOCKS_PER_HANDLE (32*8) |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
55 |
| 1 | 56 typedef struct |
| 57 { | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
58 int handle[MAX_HANDLES]; |
| 1 | 59 int nBlocks; |
| 60 } yflash_Device; | |
| 61 | |
| 62 static yflash_Device filedisk; | |
| 63 | |
| 148 | 64 int yaffs_testPartialWrite = 0; |
| 65 | |
| 256 | 66 extern int random_seed; |
| 67 extern int simulate_power_failure; | |
| 68 static int initialised = 0; | |
| 69 static int remaining_ops; | |
| 70 static int nops_so_far; | |
| 71 | |
| 72 int ops_multiplier; | |
| 73 | |
| 74 | |
| 75 static void yflash2_MaybePowerFail(void) | |
| 76 { | |
| 77 | |
| 78 nops_so_far++; | |
| 79 | |
| 80 | |
| 81 remaining_ops--; | |
| 82 if(simulate_power_failure && | |
| 83 remaining_ops < 1){ | |
| 84 printf("Simulated power failure after %d operations\n",nops_so_far); | |
| 85 exit(0); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
90 |
| 167 | 91 |
| 92 | |
| 93 static __u8 localBuffer[PAGE_SIZE]; | |
| 94 | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
95 static char *NToName(char *buf,int n) |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
96 { |
| 252 | 97 sprintf(buf,"emfile-2k-%d",n); |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
98 return buf; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
99 } |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
100 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
101 static char dummyBuffer[BLOCK_SIZE]; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
102 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
103 static int GetBlockFileHandle(int n) |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
104 { |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
105 int h; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
106 int requiredSize; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
107 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
108 char name[40]; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
109 NToName(name,n); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
110 int fSize; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
111 int i; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
112 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
113 h = open(name, O_RDWR | O_CREAT, S_IREAD | S_IWRITE); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
114 if(h >= 0){ |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
115 fSize = lseek(h,0,SEEK_END); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
116 requiredSize = BLOCKS_PER_HANDLE * BLOCK_SIZE; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
117 if(fSize < requiredSize){ |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
118 for(i = 0; i < BLOCKS_PER_HANDLE; i++) |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
119 if(write(h,dummyBuffer,BLOCK_SIZE) != BLOCK_SIZE) |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
120 return -1; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
121 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
122 } |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
123 } |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
124 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
125 return h; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
126 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
127 } |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
128 |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
129 static int CheckInit(void) |
| 1 | 130 { |
| 131 static int initialised = 0; | |
| 132 int i; | |
| 133 | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
134 int blk; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
135 |
| 1 | 136 |
| 137 if(initialised) | |
| 138 { | |
| 139 return YAFFS_OK; | |
| 140 } | |
| 141 | |
| 142 initialised = 1; | |
| 143 | |
| 256 | 144 |
| 145 srand(random_seed); | |
| 259 | 146 remaining_ops = (rand() % 1000) * 5; |
| 256 | 147 memset(dummyBuffer,0xff,sizeof(dummyBuffer)); |
| 148 | |
| 1 | 149 |
| 150 | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
151 filedisk.nBlocks = SIZE_IN_MB * BLOCKS_PER_MB; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
152 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
153 for(i = 0; i < MAX_HANDLES; i++) |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
154 filedisk.handle[i] = -1; |
| 1 | 155 |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
156 for(i = 0,blk = 0; blk < filedisk.nBlocks; blk+=BLOCKS_PER_HANDLE,i++) |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
157 filedisk.handle[i] = GetBlockFileHandle(i); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
158 |
| 1 | 159 |
| 160 return 1; | |
| 161 } | |
| 162 | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
163 |
| 215 | 164 int yflash2_GetNumberOfBlocks(void) |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
165 { |
|
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
166 CheckInit(); |
|
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
167 |
|
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
168 return filedisk.nBlocks; |
|
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
169 } |
|
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
170 |
| 215 | 171 int yflash2_WriteChunkWithTagsToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, const yaffs_ExtendedTags *tags) |
| 1 | 172 { |
| 173 int written; | |
| 174 int pos; | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
175 int h; |
| 167 | 176 int i; |
| 177 int nRead; | |
| 178 int error; | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
179 |
| 157 | 180 T(YAFFS_TRACE_MTD,(TSTR("write chunk %d data %x tags %x" TENDSTR),chunkInNAND,(unsigned)data, (unsigned)tags)); |
| 181 | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
182 CheckInit(); |
| 1 | 183 |
| 184 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
185 if(dev->inbandTags){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
186 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
187 yaffs_PackedTags2TagsPart * pt2tp; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
188 pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
189 yaffs_PackTags2TagsPart(pt2tp,tags); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
190 |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
191 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
192 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
193 |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
194 lseek(h,pos,SEEK_SET); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
195 written = write(h,data,dev->totalBytesPerChunk); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
196 |
| 1 | 197 |
| 148 | 198 if(yaffs_testPartialWrite){ |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
199 close(h); |
| 148 | 200 exit(1); |
| 201 } | |
| 202 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
203 if(written != dev->totalBytesPerChunk) return YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
204 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
205 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
206 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
207 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
208 else { |
| 256 | 209 /* First do a write of a partial page */ |
| 210 int n_partials; | |
| 211 int bpos; | |
| 212 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
213 if(data) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
214 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
215 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
216 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
217 |
| 256 | 218 |
| 219 memcpy(localBuffer,data, dev->nDataBytesPerChunk); | |
| 220 | |
| 221 n_partials = rand()%20; | |
| 222 | |
| 223 for(i = 0; i < n_partials; i++){ | |
| 224 bpos = rand() % dev->nDataBytesPerChunk; | |
| 225 | |
| 226 localBuffer[bpos] |= (1 << (rand() & 7)); | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
227 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
228 |
| 215 | 229 if(REPORT_ERROR && memcmp(localBuffer,data,dev->nDataBytesPerChunk)) |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
230 printf("nand simulator: data does not match\n"); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
231 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
232 lseek(h,pos,SEEK_SET); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
233 written = write(h,localBuffer,dev->nDataBytesPerChunk); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
234 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
235 if(yaffs_testPartialWrite){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
236 close(h); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
237 exit(1); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
238 } |
| 256 | 239 |
| 240 | |
| 241 if(written != dev->nDataBytesPerChunk) return YAFFS_FAIL; | |
| 242 } | |
| 243 yflash2_MaybePowerFail(); | |
| 244 | |
| 245 if(tags) | |
| 246 { | |
| 247 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE ; | |
| 248 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
249 |
| 256 | 250 lseek(h,pos,SEEK_SET); |
| 251 | |
| 252 if( 0 && dev->isYaffs2) | |
| 253 { | |
| 254 | |
| 255 written = write(h,tags,sizeof(yaffs_ExtendedTags)); | |
| 256 if(written != sizeof(yaffs_ExtendedTags)) return YAFFS_FAIL; | |
| 257 } | |
| 258 else | |
| 259 { | |
| 260 yaffs_PackedTags2 pt; | |
| 261 yaffs_PackTags2(&pt,tags); | |
| 262 __u8 * ptab = (__u8 *)&pt; | |
| 160 | 263 |
| 256 | 264 nRead = read(h,localBuffer,sizeof(pt)); |
| 265 for(i = error = 0; REPORT_ERROR && i < sizeof(pt) && !error; i++){ | |
| 266 if(localBuffer[i] != 0xFF){ | |
| 267 printf("nand simulation: chunk %d oob byte %d was %0x2\n", | |
| 268 chunkInNAND,i,localBuffer[i]); | |
| 269 error = 1; | |
| 270 } | |
| 271 } | |
| 272 | |
| 273 for(i = 0; i < sizeof(pt); i++) | |
| 274 localBuffer[i] &= ptab[i]; | |
| 275 | |
| 276 n_partials = rand()% sizeof(pt); | |
| 277 | |
| 278 for(i = 0; i < n_partials; i++){ | |
| 279 bpos = rand() % sizeof(pt); | |
| 280 | |
| 281 localBuffer[bpos] |= (1 << (rand() & 7)); | |
| 282 } | |
| 283 | |
| 284 if(REPORT_ERROR && memcmp(localBuffer,&pt,sizeof(pt))) | |
| 285 printf("nand sim: tags corruption\n"); | |
| 286 | |
| 287 lseek(h,pos,SEEK_SET); | |
| 288 | |
| 289 written = write(h,localBuffer,sizeof(pt)); | |
| 290 if(written != sizeof(pt)) return YAFFS_FAIL; | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 //yflash2_MaybePowerFail(); | |
| 295 | |
| 296 /* Next do the whole write */ | |
| 297 if(data) | |
| 298 { | |
| 299 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; | |
| 300 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; | |
| 301 | |
| 302 | |
| 303 memset(localBuffer,0xFF, PAGE_SIZE); | |
| 304 for(i = 0; i < dev->nDataBytesPerChunk; i++){ | |
| 305 localBuffer[i] &= data[i]; | |
| 306 } | |
| 307 | |
| 308 if(REPORT_ERROR && memcmp(localBuffer,data,dev->nDataBytesPerChunk)) | |
| 309 printf("nand simulator: data does not match\n"); | |
| 310 | |
| 311 lseek(h,pos,SEEK_SET); | |
| 312 written = write(h,localBuffer,dev->nDataBytesPerChunk); | |
| 313 | |
| 314 if(yaffs_testPartialWrite){ | |
| 315 close(h); | |
| 316 exit(1); | |
| 317 } | |
| 160 | 318 |
| 319 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
320 if(written != dev->nDataBytesPerChunk) return YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
321 } |
| 1 | 322 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
323 if(tags) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
324 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
325 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE ; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
326 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
327 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
328 lseek(h,pos,SEEK_SET); |
| 167 | 329 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
330 if( 0 && dev->isYaffs2) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
331 { |
| 1 | 332 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
333 written = write(h,tags,sizeof(yaffs_ExtendedTags)); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
334 if(written != sizeof(yaffs_ExtendedTags)) return YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
335 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
336 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
337 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
338 yaffs_PackedTags2 pt; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
339 yaffs_PackTags2(&pt,tags); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
340 __u8 * ptab = (__u8 *)&pt; |
| 1 | 341 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
342 nRead = read(h,localBuffer,sizeof(pt)); |
| 215 | 343 for(i = error = 0; REPORT_ERROR && i < sizeof(pt) && !error; i++){ |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
344 if(localBuffer[i] != 0xFF){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
345 printf("nand simulation: chunk %d oob byte %d was %0x2\n", |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
346 chunkInNAND,i,localBuffer[i]); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
347 error = 1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
348 } |
| 167 | 349 } |
| 350 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
351 for(i = 0; i < sizeof(pt); i++) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
352 localBuffer[i] &= ptab[i]; |
| 167 | 353 |
| 215 | 354 if(REPORT_ERROR && memcmp(localBuffer,&pt,sizeof(pt))) |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
355 printf("nand sim: tags corruption\n"); |
| 167 | 356 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
357 lseek(h,pos,SEEK_SET); |
| 167 | 358 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
359 written = write(h,localBuffer,sizeof(pt)); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
360 if(written != sizeof(pt)) return YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
361 } |
| 1 | 362 } |
| 256 | 363 |
| 364 yflash2_MaybePowerFail(); | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
365 |
| 1 | 366 } |
| 367 return YAFFS_OK; | |
| 368 | |
| 369 } | |
| 370 | |
| 371 int yaffs_CheckAllFF(const __u8 *ptr, int n) | |
| 372 { | |
| 373 while(n) | |
| 374 { | |
| 375 n--; | |
| 376 if(*ptr!=0xFF) return 0; | |
| 377 ptr++; | |
| 378 } | |
| 379 return 1; | |
| 380 } | |
| 381 | |
| 382 | |
| 153 | 383 static int fail300 = 1; |
| 384 static int fail320 = 1; | |
| 385 | |
| 167 | 386 static int failRead10 = 2; |
| 387 | |
| 215 | 388 int yflash2_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags) |
| 1 | 389 { |
| 390 int nread; | |
| 391 int pos; | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
392 int h; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
393 int localData = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
394 int retval = YAFFS_OK; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
395 int nRead; |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
396 |
| 157 | 397 T(YAFFS_TRACE_MTD,(TSTR("read chunk %d data %x tags %x" TENDSTR),chunkInNAND,(unsigned)data, (unsigned)tags)); |
| 398 | |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
399 CheckInit(); |
| 1 | 400 |
| 401 | |
| 402 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
403 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
404 if(dev->inbandTags){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
405 /* Got to suck the tags out of the data area */ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
406 if(!data) { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
407 localData=1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
408 data = yaffs_GetTempBuffer(dev,__LINE__); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
409 } |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
410 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
411 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
412 yaffs_PackedTags2TagsPart * pt2tp; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
413 pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
414 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
415 |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
416 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
417 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
418 |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
419 lseek(h,pos,SEEK_SET); |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
420 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
421 nRead = read(h, data,dev->totalBytesPerChunk); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
422 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
423 yaffs_UnpackTags2TagsPart(tags,pt2tp); |
| 1 | 424 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
425 if(nread != dev->totalBytesPerChunk) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
426 retval = YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
427 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
428 if(localData) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
429 yaffs_ReleaseTempBuffer(dev,data,__LINE__); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
430 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
431 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
432 |
| 1 | 433 } |
| 434 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
435 else { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
436 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
437 if(data) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
438 { |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
439 |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
440 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
441 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
442 lseek(h,pos,SEEK_SET); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
443 nread = read(h,data,dev->nDataBytesPerChunk); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
444 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
445 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
446 if(nread != dev->nDataBytesPerChunk) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
447 retval = YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
448 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
449 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
450 if(tags) |
| 1 | 451 { |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
452 pos = (chunkInNAND % (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE)) * PAGE_SIZE + PAGE_DATA_SIZE; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
453 h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))]; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
454 lseek(h,pos,SEEK_SET); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
455 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
456 if(0 && dev->isYaffs2) |
| 1 | 457 { |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
458 nread= read(h,tags,sizeof(yaffs_ExtendedTags)); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
459 if(nread != sizeof(yaffs_ExtendedTags)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
460 retval = YAFFS_FAIL; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
461 if(yaffs_CheckAllFF((__u8 *)tags,sizeof(yaffs_ExtendedTags))) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
462 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
463 yaffs_InitialiseTags(tags); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
464 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
465 else |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
466 { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
467 tags->chunkUsed = 1; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
468 } |
| 1 | 469 } |
| 470 else | |
| 471 { | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
472 yaffs_PackedTags2 pt; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
473 nread= read(h,&pt,sizeof(pt)); |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
474 yaffs_UnpackTags2(tags,&pt); |
| 157 | 475 #ifdef SIMULATE_FAILURES |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
476 if((chunkInNAND >> 6) == 100) { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
477 if(fail300 && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
478 tags->eccResult = YAFFS_ECC_RESULT_FIXED; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
479 fail300 = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
480 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
481 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
482 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
483 if((chunkInNAND >> 6) == 110) { |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
484 if(fail320 && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
485 tags->eccResult = YAFFS_ECC_RESULT_FIXED; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
486 fail320 = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
487 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
488 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
489 #endif |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
490 if(failRead10>0 && chunkInNAND == 10){ |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
491 failRead10--; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
492 nread = 0; |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
493 } |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
494 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
495 if(nread != sizeof(pt)) |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
496 retval = YAFFS_FAIL; |
| 153 | 497 } |
| 1 | 498 } |
| 499 } | |
| 500 | |
| 501 | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
502 |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
177
diff
changeset
|
503 return retval; |
| 1 | 504 |
| 505 } | |
| 506 | |
| 507 | |
| 215 | 508 int yflash2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
509 { |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
510 int written; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
511 int h; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
512 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
513 yaffs_PackedTags2 pt; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
514 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
515 CheckInit(); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
516 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
517 memset(&pt,0,sizeof(pt)); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
518 h = filedisk.handle[(blockNo / ( BLOCKS_PER_HANDLE))]; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
519 lseek(h,((blockNo % BLOCKS_PER_HANDLE) * dev->nChunksPerBlock) * PAGE_SIZE + PAGE_DATA_SIZE,SEEK_SET); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
520 written = write(h,&pt,sizeof(pt)); |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
521 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
522 if(written != sizeof(pt)) return YAFFS_FAIL; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
523 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
524 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
525 return YAFFS_OK; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
526 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
527 } |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
528 |
| 215 | 529 int yflash2_EraseBlockInNAND(yaffs_Device *dev, int blockNumber) |
| 1 | 530 { |
| 531 | |
| 532 int i; | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
533 int h; |
| 1 | 534 |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
535 CheckInit(); |
| 1 | 536 |
| 167 | 537 printf("erase block %d\n",blockNumber); |
| 538 | |
| 153 | 539 if(blockNumber == 320) |
| 540 fail320 = 1; | |
| 541 | |
| 1 | 542 if(blockNumber < 0 || blockNumber >= filedisk.nBlocks) |
| 543 { | |
| 544 T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber)); | |
| 545 return YAFFS_FAIL; | |
| 546 } | |
| 547 else | |
| 548 { | |
| 549 | |
| 550 __u8 pg[PAGE_SIZE]; | |
| 551 int syz = PAGE_SIZE; | |
| 552 int pos; | |
| 553 | |
| 554 memset(pg,0xff,syz); | |
| 555 | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
556 |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
557 h = filedisk.handle[(blockNumber / ( BLOCKS_PER_HANDLE))]; |
|
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
558 lseek(h,((blockNumber % BLOCKS_PER_HANDLE) * dev->nChunksPerBlock) * PAGE_SIZE,SEEK_SET); |
| 1 | 559 for(i = 0; i < dev->nChunksPerBlock; i++) |
| 560 { | |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
561 write(h,pg,PAGE_SIZE); |
| 1 | 562 } |
|
152
3bc7020d669c
Add large NAND support and improve retirement handling
charles
parents:
148
diff
changeset
|
563 pos = lseek(h, 0,SEEK_CUR); |
| 1 | 564 |
| 565 return YAFFS_OK; | |
| 566 } | |
| 567 | |
| 568 } | |
| 569 | |
| 215 | 570 int yflash2_InitialiseNAND(yaffs_Device *dev) |
| 1 | 571 { |
|
23
12ec56e7ccfa
Some tinkering on test harness and st_xxx to yst_xxx changes
charles
parents:
19
diff
changeset
|
572 CheckInit(); |
| 1 | 573 |
| 574 return YAFFS_OK; | |
| 575 } | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 215 | 580 int yflash2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState *state, __u32 *sequenceNumber) |
| 1 | 581 { |
| 582 yaffs_ExtendedTags tags; | |
| 583 int chunkNo; | |
| 584 | |
| 585 *sequenceNumber = 0; | |
| 586 | |
| 587 chunkNo = blockNo * dev->nChunksPerBlock; | |
| 588 | |
| 215 | 589 yflash2_ReadChunkWithTagsFromNAND(dev,chunkNo,NULL,&tags); |
| 1 | 590 if(tags.blockBad) |
| 591 { | |
| 592 *state = YAFFS_BLOCK_STATE_DEAD; | |
| 593 } | |
| 594 else if(!tags.chunkUsed) | |
| 595 { | |
| 596 *state = YAFFS_BLOCK_STATE_EMPTY; | |
| 597 } | |
| 598 else if(tags.chunkUsed) | |
| 599 { | |
| 600 *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; | |
| 601 *sequenceNumber = tags.sequenceNumber; | |
| 602 } | |
| 603 return YAFFS_OK; | |
| 604 } | |
| 605 |
