|
1 // Copyright (c) 2008-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 "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 // |
|
15 |
|
16 #include "flashdump.h" |
|
17 #include "debuglogging.h" |
|
18 |
|
19 /** |
|
20 * 1st stage construction |
|
21 * @return pointer to the newly created object, caller takes ownership of the object. |
|
22 */ |
|
23 CCrashFlashDump* CCrashFlashDump::NewL() |
|
24 { |
|
25 LOG_MSG("->CFlashDump::NewL()->\n"); |
|
26 CCrashFlashDump* self = CCrashFlashDump::NewLC(); |
|
27 CleanupStack::Pop(); |
|
28 return self; |
|
29 } |
|
30 |
|
31 /** |
|
32 * 1st stage construction |
|
33 * @return pointer to the newly created object, caller takes ownership of the object. |
|
34 */ |
|
35 CCrashFlashDump* CCrashFlashDump::NewLC() |
|
36 { |
|
37 LOG_MSG("->CFlashDump::NewLC()->\n"); |
|
38 CCrashFlashDump* self = new(ELeave)CCrashFlashDump(); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 /** |
|
45 * Constructor |
|
46 */ |
|
47 CCrashFlashDump::CCrashFlashDump() |
|
48 { |
|
49 } |
|
50 |
|
51 /** |
|
52 * 2nd stage construction |
|
53 */ |
|
54 void CCrashFlashDump::ConstructL() |
|
55 { |
|
56 LOG_MSG("CCrashFlashDump::ConstructL"); |
|
57 |
|
58 User::LeaveIfError(iFs.Connect()); |
|
59 User::LeaveIfError(iSecSess.Connect(KSecurityServerVersion)); |
|
60 } |
|
61 |
|
62 /** |
|
63 * Opens a file to dump the flash to |
|
64 * @param aFileName name of file to open for the flash dump |
|
65 * @leave one of the OS wide codes |
|
66 */ |
|
67 void CCrashFlashDump::OpenFileL(const TDesC& aFileName) |
|
68 { |
|
69 LOG_MSG2("CCrashFlashDump::OpenFileL --> [%S]", &aFileName); |
|
70 |
|
71 iFile.Close(); |
|
72 User::LeaveIfError(iFile.Create(iFs, aFileName, EFileWrite | EFileRead)); |
|
73 } |
|
74 |
|
75 /** |
|
76 * This goes through the crash flash partition and dumps it to the file |
|
77 * @leave one of the os wide codes |
|
78 */ |
|
79 void CCrashFlashDump::DumpFlashToFileL() |
|
80 { |
|
81 LOG_MSG("CCrashFlashDump::DumpFlashToFile"); |
|
82 |
|
83 //We know on a H4 the flash |
|
84 TInt remaining = KCrashFlashPartitionSize; |
|
85 |
|
86 //We shall dump 10k at a time |
|
87 RBuf8 tmpBuf; |
|
88 TUint bufSize = 0x2800; |
|
89 TUint sizeDumped = 0; |
|
90 |
|
91 User::LeaveIfError(tmpBuf.Create(bufSize)); |
|
92 tmpBuf.CleanupClosePushL(); |
|
93 |
|
94 while(remaining > 0) |
|
95 { |
|
96 LOG_MSG3("Reading [%d] bytes from crash flash position [0x%X]", bufSize, sizeDumped); |
|
97 User::LeaveIfError(iSecSess.ReadCrashLog(sizeDumped, tmpBuf, bufSize)); |
|
98 User::LeaveIfError(iFile.Write(tmpBuf)); |
|
99 |
|
100 sizeDumped += bufSize; |
|
101 remaining -= bufSize; |
|
102 |
|
103 bufSize = (bufSize > remaining) ? remaining : bufSize; |
|
104 } |
|
105 |
|
106 CleanupStack::PopAndDestroy(); |
|
107 } |
|
108 |
|
109 /** |
|
110 * destructor |
|
111 */ |
|
112 CCrashFlashDump::~CCrashFlashDump() |
|
113 { |
|
114 iSecSess.Close(); |
|
115 iFile.Close(); |
|
116 } |
|
117 |
|
118 //eof |