First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_crrdrv.cpp
15 // Test the Compact Rom (Programmable) card media driver
24 LOCAL_D RTest test(_L("T_CRRDRV"));
26 #if defined (__MARM__)
28 const TInt KTestBufLen=0x100;
30 #define PDD_NAME _L("MEDCRR")
31 const TInt KDriveNumber=1; // D:
33 const TInt KMaxDriveLen=0x00200000; // 2M
35 const TInt KMaxDriveLen=0x00600000; // 6M
37 const TUint16 KMagicSum=0x1234;
38 const TInt KCRomPrivateAreaLen=0x800; // 1st 2K of CRom contains CIS
41 const TInt KCRomCisDataLength=0xD0;
43 LOCAL_D TBuf8<KTestBufLen> wrBuf,rdBuf;
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
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
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
108 LOCAL_C void ProgressBar(TInt aPos,TInt anEndPos,TInt anXPos)
110 // Display progress of local drive operation on screen (1-16 dots)
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("."));
124 GLDEF_C TInt E32Main()
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.
134 test.Start(_L("Load CROM(repro) Media Driver"));
135 TInt r=User::LoadPhysicalDevice(PDD_NAME);
136 test(r==KErrNone||r==KErrAlreadyExists);
138 b.Format(_L("Connect to local drive (%c:)"),KDriveNumber+'C');
140 TBusLocalDrive theCRomDrive;
141 TBool changeFlag=FALSE;
142 test(theCRomDrive.Connect(KDriveNumber,changeFlag)==KErrNone);
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);
151 test(info().iConnectionBusType==EConnectionBusInternal);
152 test(info().iDriveAtt==(KDriveAttLocal|KDriveAttRemovable));
153 test(info().iMediaAtt==KMediaAttFormattable);
154 test(info().iFileSystemId==KDriveFileSysFAT);
156 test.Next(_L("CROM drive: format"));
158 test.Printf(_L("Formatting "));
160 while((ret=theCRomDrive.Format(fi))!=KErrEof)
162 ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11);
165 test.Printf(_L("\r\nReading "));
167 TInt msgHandle = KLocalMessageHandle;
168 for (i=0;i<KMaxDriveLen;i+=len)
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)
177 test.Printf(_L(" (C:%d@%xH)\r\n"),ret,i);
181 test.Printf(_L("\r\n"));
183 wrBuf.SetLength(KTestBufLen);
184 for (i=0;i<KTestBufLen;i++)
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);
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);
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);
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);
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];
215 test.Printf(_L("Writing "));
216 for (i=0,j=0;i<KMaxDriveLen;i+=len,j++)
218 ProgressBar(i,KMaxDriveLen,11);
219 len=Min(rdwrTestLen,(KMaxDriveLen-i));
221 test(theCRomDrive.Write(i,len,&wrBuf,msgHandle,0)==KErrNone);
223 test.Printf(_L("\r\nReading "));
224 for (i=0,j=0;i<KMaxDriveLen;i+=len,j++)
226 ProgressBar(i,KMaxDriveLen,11);
227 len=Min(rdwrTestLen,(KMaxDriveLen-i));
229 if ((ret=theCRomDrive.Read(i,len,&rdBuf,msgHandle,0))!=KErrNone)
231 test.Printf(_L(" (R:%d@%xH)\r\n"),ret,j);
235 wrBuf.SetLength(len);
236 if ((ret=rdBuf.Compare(wrBuf))!=0)
238 test.Printf(_L(" (C:%d@%xH)\r\n"),ret,j);
242 test.Printf(_L("\r\n"));
244 test.Next(_L("CROM drive: Re-format"));
245 test.Printf(_L("Formatting "));
246 while((ret=theCRomDrive.Format(fi))!=KErrEof)
248 ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11);
251 test.Printf(_L("\r\n"));
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);
258 rdBuf.Fill(0,KTestBufLen);
259 test(theCRomDrive.Read(0,KCRomCisDataLength,rdBuf)==KErrNone);
260 test(rdBuf.Compare(buf)==0);
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)
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);
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);
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);
288 b.Format(_L("Disconnect from local drive (%c:)"),KDriveNumber+'C');
290 theCRomDrive.Disconnect();
292 TFindPhysicalDevice fDr;
293 test.Next(_L("Unload CROM(prog) Media Driver"));
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).
308 test.Start(_L("T_CRRDRV only runs under ARM build."));