Update contrib.
1 // Copyright (c) 1998-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\misc\flash.cpp
22 RTest test(_L("FLASH"));
30 const TUint KBufferSize=4096;
31 TUint8 Buffer[KBufferSize];
32 TUint8 Buffer2[KBufferSize];
45 test.Printf(_L("Usage:\n"));
46 test.Printf(_L(" flash d <addr> <size> <file> - dump flash to file\n"));
47 test.Printf(_L(" flash b <addr> <size> - blank check flash\n"));
48 test.Printf(_L(" flash e <addr> <size> - erase flash\n"));
49 test.Printf(_L(" flash w <addr> <file> - write file to flash\n"));
50 test.Printf(_L(" flash v <addr> <file> - verify flash against file\n"));
53 TInt ParseCommandLine()
56 User::CommandLine(cmd);
61 TPtrC mode_str=lex.NextToken();
69 Mode=EBlankCheck; break;
83 TInt r=lex.Val(StartAddr,EHex);
86 if (Mode==EDump || Mode==EBlankCheck || Mode==EErase)
93 if (Mode==EDump || Mode==EWrite || Mode==EVerify)
96 FileName=lex.NextToken();
97 if (FileName.Length()==0)
101 r=File.Replace(Fs,FileName,EFileWrite);
104 test.Printf(_L("\nCould not open file %S for write\n"),&FileName);
110 r=File.Open(Fs,FileName,EFileRead);
113 test.Printf(_L("\nCould not open file %S for read\n"),&FileName);
118 r=File.Size((TInt&)Size);
121 test.Printf(_L("\nError %d accessing file %S\n"),r,&FileName);
125 test.Printf(_L("File size %x\n"),Size);
134 Flash* pF=Flash::New(StartAddr);
137 test.Printf(_L("Problem with flash device\n"));
140 TInt r=KErrNotSupported;
148 if (size>KBufferSize)
150 r=pF->Read(StartAddr,size,Buffer);
153 r=File.Write(TPtrC8(Buffer,size));
163 r=pF->BlankCheck(StartAddr,Size);
166 test.Printf(_L("Error at address %08x\n"),StartAddr+r-1);
171 r=pF->Erase(StartAddr,Size);
174 test.Printf(_L("Error at address %08x\n"),StartAddr+r-1);
181 test.Printf(_L("%08x\n"),StartAddr);
183 if (size>KBufferSize)
185 TPtr8 p8(Buffer,0,size);
189 r=pF->Write(StartAddr,size,Buffer);
202 if (size>KBufferSize)
204 r=pF->Read(StartAddr,size,Buffer);
207 TPtr8 p8(Buffer2,0,size);
212 for (i=0; i<size; ++i)
214 if (Buffer2[i]!=Buffer[i])
216 test.Printf(_L("VERIFY ERROR: Flash addr %08x, flash %02x, file %02x\n"),
217 StartAddr+i,Buffer[i],Buffer2[i]);
228 test.Printf(_L("Error %d occurred\n"),r);
235 test.Start(_L("Connect to F32"));
239 r=ParseCommandLine();