sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\pccd\t_crrdrv.cpp sl@0: // Test the Compact Rom (Programmable) card media driver sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #define TWOMEG sl@0: sl@0: LOCAL_D RTest test(_L("T_CRRDRV")); sl@0: sl@0: #if defined (__MARM__) sl@0: sl@0: const TInt KTestBufLen=0x100; sl@0: sl@0: #define PDD_NAME _L("MEDCRR") sl@0: const TInt KDriveNumber=1; // D: sl@0: #if defined (TWOMEG) sl@0: const TInt KMaxDriveLen=0x00200000; // 2M sl@0: #else sl@0: const TInt KMaxDriveLen=0x00600000; // 6M sl@0: #endif sl@0: const TUint16 KMagicSum=0x1234; sl@0: const TInt KCRomPrivateAreaLen=0x800; // 1st 2K of CRom contains CIS sl@0: sl@0: sl@0: const TInt KCRomCisDataLength=0xD0; sl@0: sl@0: LOCAL_D TBuf8 wrBuf,rdBuf; sl@0: #if defined (TWOMEG) sl@0: LOCAL_D const TText8 CompactRomCisData[KCRomCisDataLength]={ sl@0: 0x01,0xff,0x03,0xff,0x1c,0xff,0x01,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, sl@0: 0x1b,0xff,0x01,0xff,0xff,0xff,0x20,0xff,0x04,0xff,0x00,0xff,0x00,0xff,0x00,0xff, sl@0: 0x00,0xff,0x15,0xff,0x24,0xff,0x05,0xff,0x00,0xff,0x50,0xff,0x73,0xff,0x69,0xff, sl@0: 0x6f,0xff,0x6e,0xff,0x20,0xff,0x50,0xff,0x4c,0xff,0x43,0xff,0x00,0xff,0x43,0xff, sl@0: 0x6f,0xff,0x6d,0xff,0x70,0xff,0x61,0xff,0x63,0xff,0x74,0xff,0x20,0xff,0x52,0xff, sl@0: 0x6f,0xff,0x6d,0xff,0x20,0xff,0x43,0xff,0x61,0xff,0x72,0xff,0x64,0xff,0x00,0xff, sl@0: 0x56,0xff,0x30,0xff,0x2e,0xff,0x30,0xff,0x30,0xff,0x00,0xff,0xff,0xff,0x80,0xff, sl@0: 0x03,0xff,0x58,0xff,0x06,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x01,0xff,0x00,0xff, sl@0: 0x40,0xff,0x0b,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x08,0xff,0x00,0xff,0x00,0xff, sl@0: 0x00,0xff,0x00,0xff,0x01,0xff,0x00,0xff,0x00,0xff,0x41,0xff,0x0a,0xff,0x01,0xff, sl@0: 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xf8,0xff,0x1f,0xff, sl@0: 0x00,0xff,0x14,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff sl@0: }; sl@0: #else sl@0: LOCAL_D const TText8 CompactRomCisData[KCRomCisDataLength]={ sl@0: 0x01,0xff,0x03,0xff,0x1c,0xff,0x01,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, sl@0: 0x1b,0xff,0x01,0xff,0xff,0xff,0x20,0xff,0x04,0xff,0x00,0xff,0x00,0xff,0x00,0xff, sl@0: 0x00,0xff,0x15,0xff,0x24,0xff,0x05,0xff,0x00,0xff,0x50,0xff,0x73,0xff,0x69,0xff, sl@0: 0x6f,0xff,0x6e,0xff,0x20,0xff,0x50,0xff,0x4c,0xff,0x43,0xff,0x00,0xff,0x43,0xff, sl@0: 0x6f,0xff,0x6d,0xff,0x70,0xff,0x61,0xff,0x63,0xff,0x74,0xff,0x20,0xff,0x52,0xff, sl@0: 0x6f,0xff,0x6d,0xff,0x20,0xff,0x43,0xff,0x61,0xff,0x72,0xff,0x64,0xff,0x00,0xff, sl@0: 0x56,0xff,0x30,0xff,0x2e,0xff,0x30,0xff,0x30,0xff,0x00,0xff,0xff,0xff,0x80,0xff, sl@0: 0x0b,0xff,0x58,0xff,0x06,0xff,0x08,0xff,0x76,0xff,0x58,0xff,0x06,0xff,0x08,0xff, sl@0: 0x76,0xff,0x58,0xff,0x06,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x01,0xff,0x00,0xff, sl@0: 0x40,0xff,0x0b,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x08,0xff,0x00,0xff,0x00,0xff, sl@0: 0x00,0xff,0x00,0xff,0x01,0xff,0x00,0xff,0x00,0xff,0x41,0xff,0x0a,0xff,0x01,0xff, sl@0: 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xf8,0xff,0x5f,0xff, sl@0: 0x00,0xff,0x14,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff sl@0: }; sl@0: #endif sl@0: sl@0: /* A sample multifunction CIS to test out tuple parsing by blowing onto CRom card. sl@0: const TInt KMfcCisDataLen=0x180; sl@0: LOCAL_D const TText8 MfcCisData[KMfcCisDataLen]={ sl@0: 0x13,0xff,0x03,0xff,0x43,0xff,0x49,0xff,0x53,0xff,0x06,0xff,0x10,0xff,0x03,0xff, sl@0: 0x00,0xff,0x30,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x60,0xff,0x00,0xff, sl@0: 0x00,0xff,0x00,0xff,0x00,0xff,0x90,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, sl@0: 0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x02,0xff,0x00,0xff,0x1a,0xff, sl@0: 0x05,0xff,0x01,0xff,0x01,0xff,0x00,0xff,0x02,0xff,0x0f,0xff,0x1b,0xff,0x07,0xff, sl@0: 0xc1,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0xb5,0xff,0x1e,0xff,0x49,0xff,0x14,0xff, sl@0: 0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, sl@0: 0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x06,0xff,0x00,0xff,0x1a,0xff, sl@0: 0x05,0xff,0x01,0xff,0x02,0xff,0x00,0xff,0x04,0xff,0x0f,0xff,0x1b,0xff,0x06,0xff, sl@0: 0xc2,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0x55,0xff,0x49,0xff,0x14,0xff,0x00,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0x01,0xff,0x03,0xff,0xda,0xff,0x00,0xff,0xff,0xff,0x1c,0xff,0x04,0xff,0x02,0xff, sl@0: 0xda,0xff,0x00,0xff,0xff,0xff,0x21,0xff,0x02,0xff,0x03,0xff,0x00,0xff,0x1a,0xff, sl@0: 0x05,0xff,0x01,0xff,0x03,0xff,0x00,0xff,0x06,0xff,0x0f,0xff,0x1b,0xff,0x06,0xff, sl@0: 0xc3,0xff,0x41,0xff,0x09,0xff,0x01,0xff,0x55,0xff,0x49,0xff,0x14,0xff,0x00,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, sl@0: 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff sl@0: }; */ sl@0: sl@0: sl@0: LOCAL_C void ProgressBar(TInt aPos,TInt anEndPos,TInt anXPos) sl@0: // sl@0: // Display progress of local drive operation on screen (1-16 dots) sl@0: // sl@0: { sl@0: static TInt prev; sl@0: TInt curr; sl@0: if ((curr=(aPos-1)/(anEndPos>>4))>prev) sl@0: { // Update progress bar sl@0: test.Console()->SetPos(anXPos); sl@0: for (TInt i=curr;i>=0;i--) sl@0: test.Printf(_L(".")); sl@0: } sl@0: prev=curr; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: TInt i; sl@0: TBuf<32> b; sl@0: sl@0: test.Title(); sl@0: sl@0: // UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (in case normal CROM driver open on target). sl@0: User::After(300000); // Allow 0.3s for controller to detect door closed. sl@0: sl@0: test.Start(_L("Load CROM(repro) Media Driver")); sl@0: TInt r=User::LoadPhysicalDevice(PDD_NAME); sl@0: test(r==KErrNone||r==KErrAlreadyExists); sl@0: sl@0: b.Format(_L("Connect to local drive (%c:)"),KDriveNumber+'C'); sl@0: test.Next(b); sl@0: TBusLocalDrive theCRomDrive; sl@0: TBool changeFlag=FALSE; sl@0: test(theCRomDrive.Connect(KDriveNumber,changeFlag)==KErrNone); sl@0: sl@0: test.Next(_L("CROM drive: capabilities")); sl@0: // UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change (in case normal CROM driver open on target). sl@0: User::After(300000); // Allow 0.3s for controller to detect door closed. sl@0: TLocalDriveCapsV2Buf info; sl@0: test(theCRomDrive.Caps(info)==KErrNone); sl@0: test(info().iSize==(TInt64)KMaxDriveLen); sl@0: test(info().iType==EMediaFlash); sl@0: test(info().iConnectionBusType==EConnectionBusInternal); sl@0: test(info().iDriveAtt==(KDriveAttLocal|KDriveAttRemovable)); sl@0: test(info().iMediaAtt==KMediaAttFormattable); sl@0: test(info().iFileSystemId==KDriveFileSysFAT); sl@0: sl@0: test.Next(_L("CROM drive: format")); sl@0: TFormatInfo fi; sl@0: test.Printf(_L("Formatting ")); sl@0: TInt ret; sl@0: while((ret=theCRomDrive.Format(fi))!=KErrEof) sl@0: { sl@0: ProgressBar((fi.i512ByteSectorsFormatted<<9),KMaxDriveLen,11); sl@0: test(ret==KErrNone); sl@0: } sl@0: test.Printf(_L("\r\nReading ")); sl@0: TInt len; sl@0: TInt msgHandle = KLocalMessageHandle; sl@0: for (i=0;i>1)),KTestBufLen,&wrBuf,msgHandle,0)==KErrNone); sl@0: rdBuf.Fill(0,KTestBufLen); sl@0: test(theCRomDrive.Read((0x10000-(KTestBufLen>>1)),KTestBufLen,&rdBuf,msgHandle,0)==KErrNone); sl@0: test(rdBuf.Compare(wrBuf)==0); sl@0: sl@0: test.Next(_L("CROM drive: Write across 28F016 device boundary")); sl@0: test(theCRomDrive.Write((0x200000-(KTestBufLen>>1)),KTestBufLen,&wrBuf,msgHandle,0)==KErrNone); sl@0: rdBuf.Fill(0,KTestBufLen); sl@0: test(theCRomDrive.Read((0x200000-(KTestBufLen>>1)),KTestBufLen,&rdBuf,msgHandle,0)==KErrNone); sl@0: test(rdBuf.Compare(wrBuf)==0); sl@0: */ sl@0: test.Next(_L("CROM drive: Write/Read the entire disk")); sl@0: TInt rdwrTestLen=(KTestBufLen-3); // Test it works off word boundary sl@0: TUint *p=(TUint*)&wrBuf[0]; sl@0: TInt j; sl@0: test.Printf(_L("Writing ")); sl@0: for (i=0,j=0;i