annotate packages/fs/yaffs/current/src/direct/yaffs_norif1.c @ 425:dea4d7d250ad ecos

Move sources into packages/fs/yaffs/current/src/
author Ross Younger <wry@ecoscentric.com>
date Fri, 14 May 2010 16:03:09 +0100
parents direct/yaffs_norif1.c@b5309c9b6d7f
children
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 *
409
b5309c9b6d7f yaffs Some cleanups.
Charles Manning <cdhmanning@gmail.com>
parents: 356
diff changeset
4 * Copyright (C) 2002-2010 Aleph One Ltd.
224
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
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
38 const char *yaffs_norif1_c_version = "$Id: yaffs_norif1.c,v 1.6 2010-02-18 01:18:04 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"
342
ce702882929d Move tracing out of yportenv.h
charles <charles>
parents: 239
diff changeset
43 #include "yaffs_trace.h"
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
44
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
45 #include "yaffs_flashif.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
46 #include "yaffs_guts.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
47
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
48 #include "devextras.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
49
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
50 #define SPARE_BYTES_PER_CHUNK 16
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
51 #define M18_SKIP 16
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
52 #define PROG_REGION_SIZE 1024
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
53 #define BLOCK_SIZE_IN_BYTES (256*1024)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
54 #define CHUNKS_PER_BLOCK 248
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
55 #define SPARE_AREA_OFFSET (CHUNKS_PER_BLOCK * PROG_REGION_SIZE)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
56
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
57 #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
58
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
59 #define FORMAT_VALUE 0x1234
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
60
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
61 #define DATA_BYTES_PER_CHUNK 1024
226
37c7c7aaf779 Reduce size for nor simulation testing to try force errors
charles <charles>
parents: 224
diff changeset
62 #define BLOCKS_IN_DEVICE (8*1024/256)
224
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
65 #define YNOR_PREMARKER (0xF6)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
66 #define YNOR_POSTMARKER (0xF0)
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
69 #if 1
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
70
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
71 /* Compile this for a simulation */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
72 #include "ynorsim.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
73 #define ynorif1_FlashInit() ynorsim_Initialise()
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
74 #define ynorif1_FlashDeinit() ynorsim_Shutdown()
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
75 #define ynorif1_FlashWrite32(addr,buf,nwords) ynorsim_Write32(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
76 #define ynorif1_FlashRead32(addr,buf,nwords) ynorsim_Read32(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
77 #define ynorif1_FlashEraseBlock(addr) ynorsim_EraseBlock(addr)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
78 #define DEVICE_BASE ynorsim_GetBase()
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
79 #else
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
80
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
81 /* Compile this for running on blob, hacked for yaffs access */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
82 #include "../blob/yflashrw.h"
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
83 #define ynorif1_FlashInit() do{} while(0)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
84 #define ynorif1_FlashDeinit() do {} while(0)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
85 #define ynorif1_FlashWrite32(addr,buf,nwords) Y_FlashWrite(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
86 #define ynorif1_FlashRead32(addr,buf,nwords) Y_FlashRead(addr,buf,nwords)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
87 #define ynorif1_FlashEraseBlock(addr) Y_FlashErase(addr,BLOCK_SIZE_IN_BYTES)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
88 #define DEVICE_BASE (32 * 1024 * 1024)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
89 #endif
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
90
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
91 __u32 *Block2Addr(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
92 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
93 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
94
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
95 addr = (__u32) DEVICE_BASE;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
96 addr += blockNumber * BLOCK_SIZE_IN_BYTES;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
97
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
98 return (__u32 *) addr;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
101 __u32 *Block2FormatAddr(yaffs_Device *dev,int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
102 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
103 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
104
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
105 addr = (__u32) Block2Addr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
106 addr += FORMAT_OFFSET;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
107
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
108 return (__u32 *)addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
109 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
110 __u32 *Chunk2DataAddr(yaffs_Device *dev,int chunkId)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
111 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
112 unsigned block;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
113 unsigned chunkInBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
114 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
115
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
116 block = chunkId/dev->param.nChunksPerBlock;
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
117 chunkInBlock = chunkId % dev->param.nChunksPerBlock;
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
118
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
119 addr = (__u32) Block2Addr(dev,block);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
120 addr += chunkInBlock * DATA_BYTES_PER_CHUNK;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
121
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
122 return (__u32 *)addr;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
125 __u32 *Chunk2SpareAddr(yaffs_Device *dev,int chunkId)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
126 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
127 unsigned block;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
128 unsigned chunkInBlock;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
129 __u32 addr;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
130
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
131 block = chunkId/dev->param.nChunksPerBlock;
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
132 chunkInBlock = chunkId % dev->param.nChunksPerBlock;
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
133
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
134 addr = (__u32) Block2Addr(dev,block);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
135 addr += SPARE_AREA_OFFSET;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
136 addr += chunkInBlock * (SPARE_BYTES_PER_CHUNK + M18_SKIP);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
137 return (__u32 *)addr;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
141 void ynorif1_AndBytes(__u8*target, const __u8 *src, int nbytes)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
142 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
143 while(nbytes > 0){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
144 *target &= *src;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
145 target++;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
146 src++;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
147 nbytes--;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
151 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
152 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
153 __u32 *dataAddr = Chunk2DataAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
154 __u32 *spareAddr = Chunk2SpareAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
155
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
156 yaffs_Spare tmpSpare;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
157
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
158 /* We should only be getting called for one of 3 reasons:
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
159 * Writing a chunk: data and spare will not be NULL
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
160 * Writing a deletion marker: data will be NULL, spare not NULL
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
161 * 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
162 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
163
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
164 if(sizeof(yaffs_Spare) != 16)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
165 YBUG();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
166
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
167 if(data && spare)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
168 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
169 if(spare->pageStatus != 0xff)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
170 YBUG();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
171 /* Write a pre-marker */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
172 memset(&tmpSpare,0xff,sizeof(tmpSpare));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
173 tmpSpare.pageStatus = YNOR_PREMARKER;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
174 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,sizeof(yaffs_Spare)/4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
175
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
176 /* Write the data */
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
177 ynorif1_FlashWrite32(dataAddr,(__u32 *)data,dev->param.totalBytesPerChunk / 4);
224
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
180 memcpy(&tmpSpare,spare,sizeof(yaffs_Spare));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
181
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
182 /* Write the real tags, but override the premarker*/
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
183 tmpSpare.pageStatus = YNOR_PREMARKER;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
184 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,sizeof(yaffs_Spare)/4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
185
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
186 /* Write a post-marker */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
187 tmpSpare.pageStatus = YNOR_POSTMARKER;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
188 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,sizeof(tmpSpare)/4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
189
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
190 } else if(spare){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
191 /* 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
192
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
193 ynorif1_FlashRead32(spareAddr,(__u32 *)&tmpSpare,16/ 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
194
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
195 ynorif1_AndBytes((__u8 *)&tmpSpare,(__u8 *)spare,sizeof(yaffs_Spare));
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
196
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
197 ynorif1_FlashWrite32(spareAddr,(__u32 *)&tmpSpare,16/ 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
198 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
199 else {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
200 YBUG();
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
204 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
208 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
209 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
210
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
211 __u32 *dataAddr = Chunk2DataAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
212 __u32 *spareAddr = Chunk2SpareAddr(dev,chunkInNAND);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
213
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
214 if(data)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
215 {
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
216 ynorif1_FlashRead32(dataAddr,(__u32 *)data,dev->param.totalBytesPerChunk / 4);
224
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
219 if(spare)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
220 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
221 ynorif1_FlashRead32(spareAddr,(__u32 *)spare,16/ 4);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
222
228
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
223 /* 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
224 * 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
225 */
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
226 if(spare->pageStatus == YNOR_POSTMARKER)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
227 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
228 else if(spare->pageStatus != 0xff &&
239
9b3e943ffae1 Fix compiler grizzle
charles <charles>
parents: 228
diff changeset
229 (spare->pageStatus | YNOR_PREMARKER) != 0xff)
228
16c5e095a48e Extra page status checking to combat power loss causing only one bit to change
charles <charles>
parents: 226
diff changeset
230 spare->pageStatus = YNOR_PREMARKER;
224
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
234 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
238 static int ynorif1_FormatBlock(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
239 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
240 __u32 *blockAddr = Block2Addr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
241 __u32 *formatAddr = Block2FormatAddr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
242 __u32 formatValue = FORMAT_VALUE;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
243
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
244 ynorif1_FlashEraseBlock(blockAddr);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
245 ynorif1_FlashWrite32(formatAddr,&formatValue,1);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
246
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
247 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
250 static int ynorif1_UnformatBlock(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
251 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
252 __u32 *formatAddr = Block2FormatAddr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
253 __u32 formatValue = 0;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
254
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
255 ynorif1_FlashWrite32(formatAddr,&formatValue,1);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
256
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
257 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
260 static int ynorif1_IsBlockFormatted(yaffs_Device *dev, int blockNumber)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
261 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
262 __u32 *formatAddr = Block2FormatAddr(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
263 __u32 formatValue;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
266 ynorif1_FlashRead32(formatAddr,&formatValue,1);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
267
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
268 return (formatValue == FORMAT_VALUE);
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
271 int ynorif1_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
274 if(blockNumber < 0 || blockNumber >= BLOCKS_IN_DEVICE)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
275 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
276 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
277 return YAFFS_FAIL;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
278 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
279 else
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
280 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
281 ynorif1_UnformatBlock(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
282 ynorif1_FormatBlock(dev,blockNumber);
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
283 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
288 int ynorif1_InitialiseNAND(yaffs_Device *dev)
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
289 {
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
290 int i;
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
291
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
292 ynorif1_FlashInit();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
293 /* Go through the blocks formatting them if they are not formatted */
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 342
diff changeset
294 for(i = dev->param.startBlock; i <= dev->param.endBlock; i++){
224
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
295 if(!ynorif1_IsBlockFormatted(dev,i)){
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
296 ynorif1_FormatBlock(dev,i);
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 }
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
299 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
302 int ynorif1_DeinitialiseNAND(yaffs_Device *dev)
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
305 ynorif1_FlashDeinit();
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
306
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
307 return YAFFS_OK;
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
24f4db6b57b0 Some fixes and add NOR integrity code
charles <charles>
parents:
diff changeset
310