author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:28:22 +0300 | |
branch | RCL_3 |
changeset 26 | c734af59ce98 |
parent 6 | 0173bcd7697c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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 |
// e32test\pccd\t_crrdrv.cpp |
|
15 |
// Test the Compact Rom (Programmable) card media driver |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include <e32test.h> |
|
20 |
#include <e32svr.h> |
|
21 |
#include <e32uid.h> |
|
22 |
#define TWOMEG |
|
23 |
||
24 |
LOCAL_D RTest test(_L("T_CRRDRV")); |
|
25 |
||
26 |
#if defined (__MARM__) |
|
27 |
||
28 |
const TInt KTestBufLen=0x100; |
|
29 |
||
30 |
#define PDD_NAME _L("MEDCRR") |
|
31 |
const TInt KDriveNumber=1; // D: |
|
32 |
#if defined (TWOMEG) |
|
33 |
const TInt KMaxDriveLen=0x00200000; // 2M |
|
34 |
#else |
|
35 |
const TInt KMaxDriveLen=0x00600000; // 6M |
|
36 |
#endif |
|
37 |
const TUint16 KMagicSum=0x1234; |
|
38 |
const TInt KCRomPrivateAreaLen=0x800; // 1st 2K of CRom contains CIS |
|
39 |
||
40 |
||
41 |
const TInt KCRomCisDataLength=0xD0; |
|
42 |
||
43 |
LOCAL_D TBuf8<KTestBufLen> wrBuf,rdBuf; |
|
44 |
#if defined (TWOMEG) |
|
45 |
LOCAL_D const TText8 CompactRomCisData[KCRomCisDataLength]={ |
|
46 |
0x01,0xff,0x03,0xff,0x1c,0xff,0x01,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, |
|
47 |
0x1b,0xff,0x01,0xff,0xff,0xff,0x20,0xff,0x04,0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
|
48 |
0x00,0xff,0x15,0xff,0x24,0xff,0x05,0xff,0x00,0xff,0x50,0xff,0x73,0xff,0x69,0xff, |
|
49 |
0x6f,0xff,0x6e,0xff,0x20,0xff,0x50,0xff,0x4c,0xff,0x43,0xff,0x00,0xff,0x43,0xff, |
|
50 |
0x6f,0xff,0x6d,0xff,0x70,0xff,0x61,0xff,0x63,0xff,0x74,0xff,0x20,0xff,0x52,0xff, |
|
51 |
0x6f,0xff,0x6d,0xff,0x20,0xff,0x43,0xff,0x61,0xff,0x72,0xff,0x64,0xff,0x00,0xff, |
|
52 |
0x56,0xff,0x30,0xff,0x2e,0xff,0x30,0xff,0x30,0xff,0x00,0xff,0xff,0xff,0x80,0xff, |
|
53 |
0x03,0xff,0x58,0xff,0x06,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x01,0xff,0x00,0xff, |
|
54 |
0x40,0xff,0x0b,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x08,0xff,0x00,0xff,0x00,0xff, |
|
55 |
0x00,0xff,0x00,0xff,0x01,0xff,0x00,0xff,0x00,0xff,0x41,0xff,0x0a,0xff,0x01,0xff, |
|
56 |
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xf8,0xff,0x1f,0xff, |
|
57 |
0x00,0xff,0x14,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
58 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff |
|
59 |
}; |
|
60 |
#else |
|
61 |
LOCAL_D const TText8 CompactRomCisData[KCRomCisDataLength]={ |
|
62 |
0x01,0xff,0x03,0xff,0x1c,0xff,0x01,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, |
|
63 |
0x1b,0xff,0x01,0xff,0xff,0xff,0x20,0xff,0x04,0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
|
64 |
0x00,0xff,0x15,0xff,0x24,0xff,0x05,0xff,0x00,0xff,0x50,0xff,0x73,0xff,0x69,0xff, |
|
65 |
0x6f,0xff,0x6e,0xff,0x20,0xff,0x50,0xff,0x4c,0xff,0x43,0xff,0x00,0xff,0x43,0xff, |
|
66 |
0x6f,0xff,0x6d,0xff,0x70,0xff,0x61,0xff,0x63,0xff,0x74,0xff,0x20,0xff,0x52,0xff, |
|
67 |
0x6f,0xff,0x6d,0xff,0x20,0xff,0x43,0xff,0x61,0xff,0x72,0xff,0x64,0xff,0x00,0xff, |
|
68 |
0x56,0xff,0x30,0xff,0x2e,0xff,0x30,0xff,0x30,0xff,0x00,0xff,0xff,0xff,0x80,0xff, |
|
69 |
0x0b,0xff,0x58,0xff,0x06,0xff,0x08,0xff,0x76,0xff,0x58,0xff,0x06,0xff,0x08,0xff, |
|
70 |
0x76,0xff,0x58,0xff,0x06,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x01,0xff,0x00,0xff, |
|
71 |
0x40,0xff,0x0b,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x08,0xff,0x00,0xff,0x00,0xff, |
|
72 |
0x00,0xff,0x00,0xff,0x01,0xff,0x00,0xff,0x00,0xff,0x41,0xff,0x0a,0xff,0x01,0xff, |
|
73 |
0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xf8,0xff,0x5f,0xff, |
|
74 |
0x00,0xff,0x14,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff |
|
75 |
}; |
|
76 |
#endif |
|
77 |
||
78 |
/* A sample multifunction CIS to test out tuple parsing by blowing onto CRom card. |
|
79 |
const TInt KMfcCisDataLen=0x180; |
|
80 |
LOCAL_D const TText8 MfcCisData[KMfcCisDataLen]={ |
|
81 |
0x13,0xff,0x03,0xff,0x43,0xff,0x49,0xff,0x53,0xff,0x06,0xff,0x10,0xff,0x03,0xff, |
|
82 |
0x00,0xff,0x30,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x60,0xff,0x00,0xff, |
|
83 |
0x00,0xff,0x00,0xff,0x00,0xff,0x90,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0xff, |
|
84 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
85 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
86 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
87 |
0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, |
|
88 |
0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x02,0xff,0x00,0xff,0x1a,0xff, |
|
89 |
0x05,0xff,0x01,0xff,0x01,0xff,0x00,0xff,0x02,0xff,0x0f,0xff,0x1b,0xff,0x07,0xff, |
|
90 |
0xc1,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0xb5,0xff,0x1e,0xff,0x49,0xff,0x14,0xff, |
|
91 |
0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
92 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
93 |
0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, |
|
94 |
0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x06,0xff,0x00,0xff,0x1a,0xff, |
|
95 |
0x05,0xff,0x01,0xff,0x02,0xff,0x00,0xff,0x04,0xff,0x0f,0xff,0x1b,0xff,0x06,0xff, |
|
96 |
0xc2,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0x55,0xff,0x49,0xff,0x14,0xff,0x00,0xff, |
|
97 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
98 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
99 |
0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, |
|
100 |
0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x03,0xff,0x00,0xff,0x1a,0xff, |
|
101 |
0x05,0xff,0x01,0xff,0x03,0xff,0x00,0xff,0x06,0xff,0x0f,0xff,0x1b,0xff,0x06,0xff, |
|
102 |
0xc3,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0x55,0xff,0x49,0xff,0x14,0xff,0x00,0xff, |
|
103 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
|
104 |
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff |
|
105 |
}; */ |
|
106 |
||
107 |
||
108 |
LOCAL_C void ProgressBar(TInt aPos,TInt anEndPos,TInt anXPos) |
|
109 |
// |
|
110 |
// Display progress of local drive operation on screen (1-16 dots) |
|
111 |
// |
|
112 |
{ |
|
113 |
static TInt prev; |
|
114 |
TInt curr; |
|
115 |
if ((curr=(aPos-1)/(anEndPos>>4))>prev) |
|
116 |
{ // Update progress bar |
|
117 |
test.Console()->SetPos(anXPos); |
|
118 |
for (TInt i=curr;i>=0;i--) |
|
119 |
test.Printf(_L(".")); |
|
120 |
} |
|
121 |
prev=curr; |
|
122 |
} |
|
123 |
||
124 |
GLDEF_C TInt E32Main() |
|
125 |
{ |
|
126 |
TInt i; |
|
127 |
TBuf<32> b; |
|
128 |
||
129 |
test.Title(); |
|
130 |
||
131 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (in case normal CROM driver open on target). |
|
132 |
User::After(300000); // Allow 0.3s for controller to detect door closed. |
|
133 |
||
134 |
test.Start(_L("Load CROM(repro) Media Driver")); |
|
135 |
TInt r=User::LoadPhysicalDevice(PDD_NAME); |
|
136 |
test(r==KErrNone||r==KErrAlreadyExists); |
|
137 |
||
138 |
b.Format(_L("Connect to local drive (%c:)"),KDriveNumber+'C'); |
|
139 |
test.Next(b); |
|
140 |
TBusLocalDrive theCRomDrive; |
|
141 |
TBool changeFlag=FALSE; |
|
142 |
test(theCRomDrive.Connect(KDriveNumber,changeFlag)==KErrNone); |
|
143 |
||
144 |
test.Next(_L("CROM drive: capabilities")); |
|
145 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (in case normal CROM driver open on target). |
|
146 |
User::After(300000); // Allow 0.3s for controller to detect door closed. |
|
147 |
TLocalDriveCapsV2Buf info; |
|
148 |
test(theCRomDrive.Caps(info)==KErrNone); |
|
149 |
test(info().iSize==(TInt64)KMaxDriveLen); |
|
150 |
test(info().iType==EMediaFlash); |
|
6
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
test(info().iConnectionBusType==EConnectionBusInternal); |
0 | 152 |
test(info().iDriveAtt==(KDriveAttLocal|KDriveAttRemovable)); |
153 |
test(info().iMediaAtt==KMediaAttFormattable); |
|
154 |
test(info().iFileSystemId==KDriveFileSysFAT); |
|
155 |
||
156 |
test.Next(_L("CROM drive: format")); |
|
157 |
TFormatInfo fi; |
|
158 |
test.Printf(_L("Formatting ")); |
|
159 |
TInt ret; |
|
160 |
while((ret=theCRomDrive.Format(fi))!=KErrEof) |
|
161 |
{ |
|
162 |
ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11); |
|
163 |
test(ret==KErrNone); |
|
164 |
} |
|
165 |
test.Printf(_L("\r\nReading ")); |
|
166 |
TInt len; |
|
167 |
TInt msgHandle = KLocalMessageHandle; |
|
168 |
for (i=0;i<KMaxDriveLen;i+=len) |
|
169 |
{ |
|
170 |
ProgressBar(i,KMaxDriveLen,11); |
|
171 |
len=Min(KTestBufLen,(KMaxDriveLen-i)); |
|
172 |
rdBuf.Fill(0x55,len); // Sets length too |
|
173 |
test(theCRomDrive.Read(i,len,&rdBuf,msgHandle,0)==KErrNone); |
|
174 |
wrBuf.Fill(0xFF,len); // Sets length too |
|
175 |
if ((ret=rdBuf.Compare(wrBuf))!=0) |
|
176 |
{ |
|
177 |
test.Printf(_L(" (C:%d@%xH)\r\n"),ret,i); |
|
178 |
test(0); |
|
179 |
} |
|
180 |
} |
|
181 |
test.Printf(_L("\r\n")); |
|
182 |
||
183 |
wrBuf.SetLength(KTestBufLen); |
|
184 |
for (i=0;i<KTestBufLen;i++) |
|
185 |
wrBuf[i]=(TUint8)i; |
|
186 |
/* |
|
187 |
test.Next(_L("CROM drive: Write at start of Drive")); |
|
188 |
test(theCRomDrive.Write(0,KTestBufLen,&wrBuf,msgHandle,0)==KErrNone); |
|
189 |
rdBuf.Fill(0,KTestBufLen); |
|
190 |
test(theCRomDrive.Read(0,KTestBufLen,&rdBuf,msgHandle,0)==KErrNone); |
|
191 |
test(rdBuf.Compare(wrBuf)==0); |
|
192 |
||
193 |
test.Next(_L("CROM drive: Write at end of Drive")); |
|
194 |
test(theCRomDrive.Write(KMaxDriveLen-KTestBufLen,KTestBufLen,&wrBuf,msgHandle,0)==KErrNone); |
|
195 |
rdBuf.Fill(0,KTestBufLen); |
|
196 |
test(theCRomDrive.Read(KMaxDriveLen-KTestBufLen,KTestBufLen,&rdBuf,msgHandle,0)==KErrNone); |
|
197 |
test(rdBuf.Compare(wrBuf)==0); |
|
198 |
||
199 |
test.Next(_L("CROM drive: Write across 64K block boundary")); |
|
200 |
test(theCRomDrive.Write((0x10000-(KTestBufLen>>1)),KTestBufLen,&wrBuf,msgHandle,0)==KErrNone); |
|
201 |
rdBuf.Fill(0,KTestBufLen); |
|
202 |
test(theCRomDrive.Read((0x10000-(KTestBufLen>>1)),KTestBufLen,&rdBuf,msgHandle,0)==KErrNone); |
|
203 |
test(rdBuf.Compare(wrBuf)==0); |
|
204 |
||
205 |
test.Next(_L("CROM drive: Write across 28F016 device boundary")); |
|
206 |
test(theCRomDrive.Write((0x200000-(KTestBufLen>>1)),KTestBufLen,&wrBuf,msgHandle,0)==KErrNone); |
|
207 |
rdBuf.Fill(0,KTestBufLen); |
|
208 |
test(theCRomDrive.Read((0x200000-(KTestBufLen>>1)),KTestBufLen,&rdBuf,msgHandle,0)==KErrNone); |
|
209 |
test(rdBuf.Compare(wrBuf)==0); |
|
210 |
*/ |
|
211 |
test.Next(_L("CROM drive: Write/Read the entire disk")); |
|
212 |
TInt rdwrTestLen=(KTestBufLen-3); // Test it works off word boundary |
|
213 |
TUint *p=(TUint*)&wrBuf[0]; |
|
214 |
TInt j; |
|
215 |
test.Printf(_L("Writing ")); |
|
216 |
for (i=0,j=0;i<KMaxDriveLen;i+=len,j++) |
|
217 |
{ |
|
218 |
ProgressBar(i,KMaxDriveLen,11); |
|
219 |
len=Min(rdwrTestLen,(KMaxDriveLen-i)); |
|
220 |
(*p)=j; |
|
221 |
test(theCRomDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone); |
|
222 |
} |
|
223 |
test.Printf(_L("\r\nReading ")); |
|
224 |
for (i=0,j=0;i<KMaxDriveLen;i+=len,j++) |
|
225 |
{ |
|
226 |
ProgressBar(i,KMaxDriveLen,11); |
|
227 |
len=Min(rdwrTestLen,(KMaxDriveLen-i)); |
|
228 |
rdBuf.Fill(0,len); |
|
229 |
if ((ret=theCRomDrive.Read(i,len,&rdBuf,msgHandle,0))!=KErrNone) |
|
230 |
{ |
|
231 |
test.Printf(_L(" (R:%d@%xH)\r\n"),ret,j); |
|
232 |
test(0); |
|
233 |
} |
|
234 |
(*p)=j; |
|
235 |
wrBuf.SetLength(len); |
|
236 |
if ((ret=rdBuf.Compare(wrBuf))!=0) |
|
237 |
{ |
|
238 |
test.Printf(_L(" (C:%d@%xH)\r\n"),ret,j); |
|
239 |
test(0); |
|
240 |
} |
|
241 |
} |
|
242 |
test.Printf(_L("\r\n")); |
|
243 |
||
244 |
test.Next(_L("CROM drive: Re-format")); |
|
245 |
test.Printf(_L("Formatting ")); |
|
246 |
while((ret=theCRomDrive.Format(fi))!=KErrEof) |
|
247 |
{ |
|
248 |
ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11); |
|
249 |
test(ret==KErrNone); |
|
250 |
} |
|
251 |
test.Printf(_L("\r\n")); |
|
252 |
||
253 |
test.Next(_L("CROM drive: Write CIS at start of Drive")); |
|
254 |
TPtrC8 buf(&CompactRomCisData[0],KCRomCisDataLength); |
|
255 |
// TPtrC8 buf(&MfcCisData[0],KMfcCisDataLen); // ??? |
|
256 |
test(theCRomDrive.Write(0,buf)==KErrNone); |
|
257 |
||
258 |
rdBuf.Fill(0,KTestBufLen); |
|
259 |
test(theCRomDrive.Read(0,KCRomCisDataLength,rdBuf)==KErrNone); |
|
260 |
test(rdBuf.Compare(buf)==0); |
|
261 |
||
262 |
test.Next(_L("Calculating & writing checksum")); |
|
263 |
TUint16 checksum=0; // 16bit arithmetic |
|
264 |
test.Printf(_L("Reading")); |
|
265 |
for (i=0;i<KMaxDriveLen;i+=len) |
|
266 |
{ |
|
267 |
ProgressBar(i,KMaxDriveLen,11); |
|
268 |
len=Min(KTestBufLen,(KMaxDriveLen-i)); |
|
269 |
test(theCRomDrive.Read(i,len,rdBuf)==KErrNone); |
|
270 |
test((len%2)==0); // 16bit checksum - length must never be odd |
|
271 |
for (TInt j=0;j<len;j+=2) |
|
272 |
checksum+=*(TUint16*)(rdBuf.Ptr()+j); |
|
273 |
} |
|
274 |
checksum-=0xFFFF; // Subtract for checksum itself |
|
275 |
TUint16 adjust=KMagicSum-checksum; |
|
276 |
test.Printf(_L("\r\n (CS:%xH)\r\n"),adjust); |
|
277 |
TPtrC8 cs((TUint8*)&adjust,2); |
|
278 |
test(theCRomDrive.Write(KCRomPrivateAreaLen-2,cs)==KErrNone); |
|
279 |
||
280 |
test.Next(_L("CROM drive: Caps following media change")); |
|
281 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change |
|
282 |
User::After(300000); // Allow 0.3s after power down for controller to detect door closed. |
|
283 |
test(changeFlag!=FALSE); |
|
284 |
test(theCRomDrive.Caps(info)==KErrNone); |
|
285 |
test(info().iSize==(TInt64)KMaxDriveLen); |
|
286 |
test(info().iType==EMediaFlash); |
|
287 |
||
288 |
b.Format(_L("Disconnect from local drive (%c:)"),KDriveNumber+'C'); |
|
289 |
test.Next(b); |
|
290 |
theCRomDrive.Disconnect(); |
|
291 |
||
292 |
TFindPhysicalDevice fDr; |
|
293 |
test.Next(_L("Unload CROM(prog) Media Driver")); |
|
294 |
TFullName drivName; |
|
295 |
fDr.Find(_L("Media.RomPrg")); |
|
296 |
test(fDr.Next(drivName)==KErrNone); |
|
297 |
test(User::FreePhysicalDevice(drivName)==KErrNone); |
|
298 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (allow normal CROM driver on next target access). |
|
299 |
||
300 |
test.End(); |
|
301 |
return(0); |
|
302 |
} |
|
303 |
||
304 |
#else |
|
305 |
TInt E32Main() |
|
306 |
{ |
|
307 |
test.Title(); |
|
308 |
test.Start(_L("T_CRRDRV only runs under ARM build.")); |
|
309 |
test.End(); |
|
310 |
return(KErrNone); |
|
311 |
} |
|
312 |
#endif |
|
313 |