annotate direct/yaffs_norif1.c @ 228:16c5e095a48e

Extra page status checking to combat power loss causing only one bit to change
author charles <charles>
date Thu, 13 Nov 2008 01:50:16 +0000
parents 37c7c7aaf779
children 9b3e943ffae1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
1 /*
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
3 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
4 * Copyright (C) 2002-2007 Aleph One Ltd.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
5 * for Toby Churchill Ltd and Brightstar Engineering
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
6 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
7 * Created by Charles Manning <charles@aleph1.co.uk>
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
8 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
10 * it under the terms of the GNU General Public License version 2 as
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
11 * published by the Free Software Foundation.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
12 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
13
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
14 /*
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
15 * This is an interface module for handling NOR in yaffs1 mode.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
16 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
17
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
18 /* First set up for M18 with 1k chunks and 16-byte spares.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
19 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
20 * NB We're using the oddball M18 modes of operation here
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
21 * The chip is 64MB based at 0x0000, but YAFFS only going to use the top half
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
22 * ie. YAFFS will be from 32MB to 64MB.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
23 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
24 * The M18 has two ways of writing data. Every Programming Region (1kbytes)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
25 * can be programmed in two modes:
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
26 * * Object Mode 1024 bytes of write once data.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
27 * * Control Mode: 512bytes of bit-writeable data.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
28 * This is arranged as 32 * (16 bytes of bit-writable followed by 16 bytes of "dont touch")
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
29 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
30 * The block size is 256kB, making 128 blocks in the 32MB YAFFS area.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
31 * Each block comprises:
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
32 * Offset 0k: 248 x 1k data pages
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
33 * Offset 248k: 248 x 32-byte spare areas implemented as 16 bytes of spare followed by 16 bytes untouched)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
34 * Offset 248k + (248 * 32): Format marker
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
35 *
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
36 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
37
228
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
38 const char *yaffs_norif1_c_version = "$Id: yaffs_norif1.c,v 1.3 2008-11-13 01:50:16 charles Exp $";
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
39
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
40 #include "yaffs_norif1.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
41
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
42 #include "yportenv.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
43
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
44 #include "yaffs_flashif.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
45 #include "yaffs_guts.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
46
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
47 #include "devextras.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
48
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
49 #define SPARE_BYTES_PER_CHUNK 16
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
50 #define M18_SKIP 16
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
51 #define PROG_REGION_SIZE 1024
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
52 #define BLOCK_SIZE_IN_BYTES (256*1024)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
53 #define CHUNKS_PER_BLOCK 248
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
54 #define SPARE_AREA_OFFSET (CHUNKS_PER_BLOCK * PROG_REGION_SIZE)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
55
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
56 #define FORMAT_OFFSET (SPARE_AREA_OFFSET + CHUNKS_PER_BLOCK * (SPARE_BYTES_PER_CHUNK + M18_SKIP))
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
57
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
58 #define FORMAT_VALUE 0x1234
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
59
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
60 #define DATA_BYTES_PER_CHUNK 1024
226
37c7c7aaf779 Reduce size for nor simulation testing to try force errors
charles <charles>
parents: 224
diff changeset
61 #define BLOCKS_IN_DEVICE (8*1024/256)
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
62
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
63
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
64 #define YNOR_PREMARKER (0xF6)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
65 #define YNOR_POSTMARKER (0xF0)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
66
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
67
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
68 #if 1
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
69
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
70 /* Compile this for a simulation */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
71 #include "ynorsim.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
72 #define ynorif1_FlashInit() ynorsim_Initialise()
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
73 #define ynorif1_FlashDeinit() ynorsim_Shutdown()
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
74 #define ynorif1_FlashWrite32(addr,buf,nwords) ynorsim_Write32(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
75 #define ynorif1_FlashRead32(addr,buf,nwords) ynorsim_Read32(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
76 #define ynorif1_FlashEraseBlock(addr) ynorsim_EraseBlock(addr)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
77 #define DEVICE_BASE ynorsim_GetBase()
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
78 #else
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
79
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
80 /* Compile this for running on blob, hacked for yaffs access */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
81 #include "../blob/yflashrw.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
82 #define ynorif1_FlashInit() do{} while(0)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
83 #define ynorif1_FlashDeinit() do {} while(0)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
84 #define ynorif1_FlashWrite32(addr,buf,nwords) Y_FlashWrite(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
85 #define ynorif1_FlashRead32(addr,buf,nwords) Y_FlashRead(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
86 #define ynorif1_FlashEraseBlock(addr) Y_FlashErase(addr,BLOCK_SIZE_IN_BYTES)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
87 #define DEVICE_BASE (32 * 1024 * 1024)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
88 #endif
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
89
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
90 __u32 *Block2Addr(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
91 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
92 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
93
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
94 addr = (__u32) DEVICE_BASE;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
95 addr += blockNumber * BLOCK_SIZE_IN_BYTES;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
96
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
97 return (__u32 *) addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
98 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
99
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
100 __u32 *Block2FormatAddr(yaffs_Device *dev,int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
101 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
102 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
103
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
104 addr = (__u32) Block2Addr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
105 addr += FORMAT_OFFSET;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
106
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
107 return (__u32 *)addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
108 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
109 __u32 *Chunk2DataAddr(yaffs_Device *dev,int chunkId)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
110 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
111 unsigned block;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
112 unsigned chunkInBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
113 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
114
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
115 block = chunkId/dev->nChunksPerBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
116 chunkInBlock = chunkId % dev->nChunksPerBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
117
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
118 addr = (__u32) Block2Addr(dev,block);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
119 addr += chunkInBlock * DATA_BYTES_PER_CHUNK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
120
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
121 return (__u32 *)addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
122 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
123
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
124 __u32 *Chunk2SpareAddr(yaffs_Device *dev,int chunkId)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
125 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
126 unsigned block;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
127 unsigned chunkInBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
128 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
129
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
130 block = chunkId/dev->nChunksPerBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
131 chunkInBlock = chunkId % dev->nChunksPerBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
132
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
133 addr = (__u32) Block2Addr(dev,block);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
134 addr += SPARE_AREA_OFFSET;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
135 addr += chunkInBlock * (SPARE_BYTES_PER_CHUNK + M18_SKIP);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
136 return (__u32 *)addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
137 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
138
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
139
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
140 void ynorif1_AndBytes(__u8*target, const __u8 *src, int nbytes)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
141 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
142 while(nbytes > 0){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
143 *target &= *src;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
144 target++;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
145 src++;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
146 nbytes--;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
147 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
148 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
149
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
150 int ynorif1_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, const yaffs_Spare *spare)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
151 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
152 __u32 *dataAddr = Chunk2DataAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
153 __u32 *spareAddr = Chunk2SpareAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
154
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
155 yaffs_Spare tmpSpare;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
156
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
157 /* We should only be getting called for one of 3 reasons:
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
158 * Writing a chunk: data and spare will not be NULL
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
159 * Writing a deletion marker: data will be NULL, spare not NULL
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
160 * Writing a bad block marker: data will be NULL, spare not NULL
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
161 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
162
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
163 if(sizeof(yaffs_Spare) != 16)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
164 YBUG();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
165
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
166 if(data && spare)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
167 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
168 if(spare->pageStatus != 0xff)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
169 YBUG();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
170 /* Write a pre-marker */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
171 memset(&tmpSpare,0xff,sizeof(tmpSpare));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
172 tmpSpare.pageStatus = YNOR_PREMARKER;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
173 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,sizeof(yaffs_Spare)/4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
174
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
175 /* Write the data */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
176 ynorif1_FlashWrite32(dataAddr,(__u32 *)data,dev->totalBytesPerChunk / 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
177
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
178
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
179 memcpy(&tmpSpare,spare,sizeof(yaffs_Spare));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
180
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
181 /* Write the real tags, but override the premarker*/
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
182 tmpSpare.pageStatus = YNOR_PREMARKER;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
183 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,sizeof(yaffs_Spare)/4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
184
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
185 /* Write a post-marker */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
186 tmpSpare.pageStatus = YNOR_POSTMARKER;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
187 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,sizeof(tmpSpare)/4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
188
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
189 } else if(spare){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
190 /* This has to be a read-modify-write operation to handle NOR-ness */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
191
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
192 ynorif1_FlashRead32(spareAddr,(__u32 *)&tmpSpare,16/ 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
193
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
194 ynorif1_AndBytes((__u8 *)&tmpSpare,(__u8 *)spare,sizeof(yaffs_Spare));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
195
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
196 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,16/ 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
197 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
198 else {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
199 YBUG();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
200 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
201
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
202
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
203 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
204
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
205 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
206
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
207 int ynorif1_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
208 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
209
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
210 __u32 *dataAddr = Chunk2DataAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
211 __u32 *spareAddr = Chunk2SpareAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
212
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
213 if(data)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
214 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
215 ynorif1_FlashRead32(dataAddr,(__u32 *)data,dev->totalBytesPerChunk / 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
216 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
217
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
218 if(spare)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
219 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
220 ynorif1_FlashRead32(spareAddr,(__u32 *)spare,16/ 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
221
228
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
222 /* If the page status is YNOR_POSTMARKER then it was written properly
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
223 * so change that to 0xFF so that the rest of yaffs is happy.
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
224 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
225 if(spare->pageStatus == YNOR_POSTMARKER)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
226 spare->pageStatus = 0xFF;
228
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
227 else if(spare->pageStatus != 0xff &&
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
228 (spare->pageStatus | YNOR_PREMARKER != 0xff))
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
229 spare->pageStatus = YNOR_PREMARKER;
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
230 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
231
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
232
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
233 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
234
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
235 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
236
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
237 static int ynorif1_FormatBlock(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
238 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
239 __u32 *blockAddr = Block2Addr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
240 __u32 *formatAddr = Block2FormatAddr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
241 __u32 formatValue = FORMAT_VALUE;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
242
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
243 ynorif1_FlashEraseBlock(blockAddr);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
244 ynorif1_FlashWrite32(formatAddr,&formatValue,1);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
245
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
246 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
247 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
248
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
249 static int ynorif1_UnformatBlock(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
250 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
251 __u32 *formatAddr = Block2FormatAddr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
252 __u32 formatValue = 0;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
253
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
254 ynorif1_FlashWrite32(formatAddr,&formatValue,1);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
255
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
256 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
257 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
258
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
259 static int ynorif1_IsBlockFormatted(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
260 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
261 __u32 *formatAddr = Block2FormatAddr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
262 __u32 formatValue;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
263
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
264
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
265 ynorif1_FlashRead32(formatAddr,&formatValue,1);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
266
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
267 return (formatValue == FORMAT_VALUE);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
268 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
269
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
270 int ynorif1_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
271 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
272
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
273 if(blockNumber < 0 || blockNumber >= BLOCKS_IN_DEVICE)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
274 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
275 T(YAFFS_TRACE_ALWAYS,("Attempt to erase non-existant block %d\n",blockNumber));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
276 return YAFFS_FAIL;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
277 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
278 else
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
279 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
280 ynorif1_UnformatBlock(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
281 ynorif1_FormatBlock(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
282 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
283 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
284
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
285 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
286
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
287 int ynorif1_InitialiseNAND(yaffs_Device *dev)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
288 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
289 int i;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
290
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
291 ynorif1_FlashInit();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
292 /* Go through the blocks formatting them if they are not formatted */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
293 for(i = dev->startBlock; i <= dev->endBlock; i++){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
294 if(!ynorif1_IsBlockFormatted(dev,i)){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
295 ynorif1_FormatBlock(dev,i);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
296 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
297 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
298 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
299 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
300
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
301 int ynorif1_DeinitialiseNAND(yaffs_Device *dev)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
302 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
303
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
304 ynorif1_FlashDeinit();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
305
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
306 return YAFFS_OK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
307 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
308
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
309