|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32\drivers\crashflashnor.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <crashflashnor.h> |
|
19 |
|
20 void CrashFlashNor::StartTransaction() |
|
21 { |
|
22 } |
|
23 |
|
24 void CrashFlashNor::EndTransaction() |
|
25 { |
|
26 #ifdef _CRASHLOG_COMPR |
|
27 // Ensure any buffered data is output not all the data will be valid but |
|
28 // iWriteTotal should reflect this by only increasing by no of valid/buffered bytes |
|
29 if (iWriteBufBytes) |
|
30 { |
|
31 DoWrite(iWriteBuf); |
|
32 } |
|
33 #endif //_CRASHLOG_COMPR |
|
34 } |
|
35 |
|
36 TUint CrashFlashNor::BytesWritten() |
|
37 { |
|
38 return iWriteTotal + iWriteBufBytes; |
|
39 } |
|
40 |
|
41 void CrashFlashNor::SetReadPos(TUint aPos) |
|
42 { |
|
43 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Setting read position to %d", aPos)); |
|
44 if( (aPos%sizeof(TCFIWord)) == 0) |
|
45 { |
|
46 iReadPos = aPos; |
|
47 iReadBufBytes = 0; |
|
48 iReadBuf = 0; |
|
49 } |
|
50 else |
|
51 { |
|
52 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Invalid read position requested, ignoring.")); |
|
53 } |
|
54 } |
|
55 |
|
56 |
|
57 TInt CrashFlashNor::Initialise() |
|
58 { |
|
59 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::Initialise()")); |
|
60 TInt ret = VariantInitialise(); |
|
61 if(ret) |
|
62 { |
|
63 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::VariantInitialise() failed")); |
|
64 return ret; |
|
65 } |
|
66 // start writing after the crash log header |
|
67 |
|
68 #ifdef CDS_CRASH_LOGGER |
|
69 iWritePos = 0; |
|
70 #else |
|
71 iWritePos = KCrashLogHeaderSize; |
|
72 #endif //CDS_CRASH_LOGGER |
|
73 |
|
74 SetReadPos(0); |
|
75 iWriteTotal = 0; |
|
76 |
|
77 return KErrNone; |
|
78 } |
|
79 |
|
80 void CrashFlashNor::SetWritePos(TUint aPos) |
|
81 { |
|
82 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::SetWritePos")); |
|
83 if( (aPos%sizeof(TCFIWord)) == 0) |
|
84 { |
|
85 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Setting write position to %d", aPos)); |
|
86 iWritePos = aPos; |
|
87 iWriteTotal = 0; |
|
88 iWriteBufBytes = 0; |
|
89 iWriteBuf = 0; |
|
90 } |
|
91 else |
|
92 { |
|
93 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Invalid read position requested, ignoring.")); |
|
94 } |
|
95 } |
|
96 void CrashFlashNor::Write(const TDesC8& aDes) |
|
97 { |
|
98 if (iWritePos >= KMaxCrashLogSize) |
|
99 { |
|
100 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: log limit already exceeded")); |
|
101 return; |
|
102 } |
|
103 |
|
104 TInt size = aDes.Size(); |
|
105 #ifndef _CRASHLOG_COMPR |
|
106 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: %S, size: %d",&aDes,size)); |
|
107 #else |
|
108 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: writing %d bytes",size)); |
|
109 #endif |
|
110 const TUint8* ptr8 = aDes.Ptr(); |
|
111 |
|
112 TInt truncated = EFalse; |
|
113 #ifndef _CRASHLOG_COMPR |
|
114 // If this will take us too close to (or past) the end of the crash log, discard the current string |
|
115 // and write the truncation notice instead |
|
116 if (iWritePos+size > KMaxCrashLogSize-KCrashLogTruncated().Size()) |
|
117 { |
|
118 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: truncating log")); |
|
119 size = KCrashLogTruncated().Size(); |
|
120 ptr8 = KCrashLogTruncated().Ptr(); |
|
121 truncated = ETrue; |
|
122 } |
|
123 #else |
|
124 // If this will take us past the end of the crash log, then truncate it |
|
125 if (iWritePos+size > KMaxCrashLogSize) |
|
126 { |
|
127 // no. of bytes left in crash log sector |
|
128 TUint tmp=KMaxCrashLogSize - iWritePos; |
|
129 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: truncating log, limiting output to %d bytes as iWritePos=%d",tmp,iWritePos)); |
|
130 size = tmp; |
|
131 truncated = ETrue; |
|
132 } |
|
133 #endif |
|
134 |
|
135 const TUint8* end = ptr8 + size; |
|
136 |
|
137 for(; ptr8<end; ptr8++) |
|
138 { |
|
139 switch(iWriteBufBytes) |
|
140 { |
|
141 case 0: |
|
142 iWriteBuf |= (*ptr8); |
|
143 break; |
|
144 #if defined(TCFI_2BYTE_WORD) || defined(TCFI_4BYTE_WORD) |
|
145 case 1: |
|
146 iWriteBuf |= (*ptr8)<<8; |
|
147 break; |
|
148 #if defined(TCFI_4BYTE_WORD) |
|
149 case 2: |
|
150 iWriteBuf |= (*ptr8)<<16; |
|
151 break; |
|
152 case 3: |
|
153 iWriteBuf |= (*ptr8)<<24; |
|
154 break; |
|
155 #endif |
|
156 #endif |
|
157 } |
|
158 iWriteBufBytes++; |
|
159 if(iWriteBufBytes == (sizeof(TCFIWord))) |
|
160 { |
|
161 DoWrite(iWriteBuf); |
|
162 iWritePos+=sizeof(TCFIWord); |
|
163 iWriteTotal+=sizeof(TCFIWord); |
|
164 iWriteBuf = 0; |
|
165 } |
|
166 //equiv to iWriteBufBytes%=sizeof(TCFIWord) as long as TCFIWord is |
|
167 //a power of 2 |
|
168 iWriteBufBytes&=sizeof(TCFIWord)-1; |
|
169 } |
|
170 |
|
171 // If the log was truncated, skip the write position ahead so we don't try to write any more |
|
172 if (truncated) |
|
173 { |
|
174 iWritePos = KMaxCrashLogSize; |
|
175 } |
|
176 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Write: total %d, position %d", iWriteTotal, iWritePos)); |
|
177 } |
|
178 |
|
179 void CrashFlashNor::WriteSignature(const TDesC8& aDes) |
|
180 { |
|
181 if (iWriteBufBytes > 0) |
|
182 { |
|
183 DoWrite(iWriteBuf); |
|
184 iWriteBufBytes=0; |
|
185 iWriteBuf=0; |
|
186 } |
|
187 iWritePos = 0; |
|
188 Write(aDes); |
|
189 } |
|
190 |
|
191 void CrashFlashNor::Read(TDes8& aDes) |
|
192 { |
|
193 TUint8* ptr8 = const_cast<TUint8*>(aDes.Ptr()); |
|
194 const TUint8* end = ptr8 + aDes.Size(); |
|
195 for( ; ptr8<end; ptr8++) |
|
196 { |
|
197 switch(iReadBufBytes) |
|
198 { |
|
199 case 0: |
|
200 iReadBuf = DoRead(); |
|
201 iReadPos+=sizeof(TCFIWord); |
|
202 *ptr8 = (TUint8)(iReadBuf); |
|
203 break; |
|
204 #if defined(TCFI_2BYTE_WORD) || defined(TCFI_4BYTE_WORD) |
|
205 case 1: |
|
206 *ptr8 = (TUint8)(iReadBuf>>8); |
|
207 break; |
|
208 #if defined(TCFI_4BYTE_WORD) |
|
209 case 2: |
|
210 *ptr8 = (TUint8)(iReadBuf>>16); |
|
211 break; |
|
212 case 3: |
|
213 *ptr8 = (TUint8)(iReadBuf>>24); |
|
214 break; |
|
215 #endif |
|
216 #endif |
|
217 } |
|
218 iReadBufBytes++; |
|
219 //equiv to iReadBufBytes%=sizeof(TCFIWord) as long as TCFIWord is |
|
220 //a power of 2 |
|
221 iReadBufBytes&=sizeof(TCFIWord)-1; |
|
222 } |
|
223 } |
|
224 |
|
225 void CrashFlashNor::EraseLogArea() |
|
226 { |
|
227 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Erasing crash log area...")); |
|
228 for(TUint erased = 0; erased < KMaxCrashLogSize; erased += iEraseBlockSize) |
|
229 { |
|
230 DoEraseBlock(erased); |
|
231 } |
|
232 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Finished erasing area for crash log.")); |
|
233 } |
|
234 |
|
235 void CrashFlashNor::EraseFlashBlock(TUint aBlock) |
|
236 { |
|
237 __KTRACE_OPT(KDEBUGGER,Kern::Printf("CrashFlashNor::Erasing crash flash block offset [0x%X]", aBlock)); |
|
238 |
|
239 if(aBlock%iEraseBlockSize != 0 || aBlock > KMaxCrashLogSize) |
|
240 { |
|
241 __KTRACE_OPT(KDEBUGGER,Kern::Printf("Invalid Block Address - Not deleting [0x%X]", aBlock)); |
|
242 return; |
|
243 } |
|
244 |
|
245 DoEraseBlock(aBlock); |
|
246 } |
|
247 |
|
248 #ifdef _CRASHLOG_COMPR |
|
249 TUint CrashFlashNor::GetOutputLimit() |
|
250 { |
|
251 return KMaxCrashLogSize-KCrashLogHeaderSize; |
|
252 } |
|
253 |
|
254 TUint CrashFlashNor::GetLogOffset(void) |
|
255 { |
|
256 return 0; |
|
257 } |
|
258 #endif |
|
259 |