100 { |
82 { |
101 Print(EError, "Keyword hcrdata has been set more than one time!"); |
83 Print(EError, "Keyword hcrdata has been set more than one time!"); |
102 return EFalse; |
84 return EFalse; |
103 } |
85 } |
104 iHcrData = aValues.at(0); |
86 iHcrData = aValues.at(0); |
105 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
87 |
106 ifstream is(iHcrData.c_str(), ios_base::binary ); |
88 ifstream is(iHcrData.c_str(), ios_base::binary ); |
107 #else //!__MSVCDOTNET__ |
|
108 ifstream is(iHcrData.c_str(), ios::nocreate | ios::binary ); |
|
109 #endif //__MSVCDOTNET__ |
|
110 if(!is) |
89 if(!is) |
111 { |
90 { |
112 Print(EError, "HCR data file: %s dose not exist!", iHcrData.c_str()); |
91 Print(EError, "HCR data file: %s dose not exist!", iHcrData.c_str()); |
113 return EFalse; |
92 return EFalse; |
114 } |
93 } |
148 if(aValues.size() > 1) |
127 if(aValues.size() > 1) |
149 { |
128 { |
150 Print(EError, "Keyword Payloadfalgs has been set more than one time!"); |
129 Print(EError, "Keyword Payloadfalgs has been set more than one time!"); |
151 return EFalse; |
130 return EFalse; |
152 } |
131 } |
153 iSmrRomHeader.iPayloadFlags = StrToInt(aValues.at(0).c_str()); |
132 Val(iSmrRomHeader.iPayloadFlags , aValues.at(0).c_str()); |
154 return ETrue; |
133 return ETrue; |
155 } |
134 } |
156 TUint32 CSmrImage::StrToInt(const char* aStr) |
|
157 { |
|
158 |
135 |
159 TUint32 value; |
|
160 #ifdef __TOOLS2__ |
|
161 istringstream val(aStr); |
|
162 #else |
|
163 istrstream val(aStr, strlen(aStr)); |
|
164 #endif |
|
165 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
166 val >> setbase(0); |
|
167 #endif //__MSVCDOTNET |
|
168 val >> value; |
|
169 return value; |
|
170 } |
|
171 TInt CSmrImage::Initialise() |
136 TInt CSmrImage::Initialise() |
172 { |
137 { |
173 TInt result = KErrGeneral; |
138 TInt result = KErrGeneral; |
174 if(! SetImageName(iObeyFile->getValues("imagename"))) |
139 if(! SetImageName(iObeyFile->getValues("imagename"))) |
175 return result; |
140 return result; |
186 } |
151 } |
187 TInt CSmrImage::CreateImage() |
152 TInt CSmrImage::CreateImage() |
188 { |
153 { |
189 TInt imageSize = 0; |
154 TInt imageSize = 0; |
190 ifstream is; |
155 ifstream is; |
191 is.open(iHcrData.c_str(), ios::binary); |
156 is.open(iHcrData.c_str(), ios_base::binary); |
192 if(!is) |
157 if(!is) |
193 { |
158 { |
194 Print(EError, "Open HCR data file: %s error!\n", iHcrData.c_str()); |
159 Print(EError, "Open HCR data file: %s error!\n", iHcrData.c_str()); |
195 return KErrGeneral; |
160 return KErrGeneral; |
196 } |
161 } |
197 is.seekg(0, ios::end); |
162 is.seekg(0, ios_base::end); |
198 TInt fsize = is.tellg(); |
163 TInt fsize = is.tellg(); |
199 imageSize = sizeof(SSmrRomHeader) + fsize; |
164 imageSize = sizeof(SSmrRomHeader) + fsize; |
200 imageSize += (4 - imageSize) & 3; |
165 imageSize += (4 - imageSize) & 3; |
201 char* vImage = new (std::nothrow) char[imageSize]; |
166 char* vImage = new (nothrow) char[imageSize]; |
202 if(vImage == NULL) |
167 if(vImage == NULL) |
203 { |
168 { |
204 Print(EError, "Not enough system memory generate SMR partition!\n"); |
169 Print(EError, "Not enough system memory generate SMR partition!\n"); |
205 return KErrNoMemory; |
170 return KErrNoMemory; |
206 } |
171 } |
207 HMem::Set(vImage, 0, imageSize); |
172 HMem::Set(vImage, 0, imageSize); |
208 HMem::Copy(vImage, &iSmrRomHeader, sizeof(SSmrRomHeader)); |
173 HMem::Copy(vImage, &iSmrRomHeader, sizeof(SSmrRomHeader)); |
209 SSmrRomHeader* pSmrHeader = (SSmrRomHeader *) vImage; |
174 SSmrRomHeader* pSmrHeader = (SSmrRomHeader *) vImage; |
210 pSmrHeader->iFingerPrint[0] = 0x5F524D53; |
175 pSmrHeader->iFingerPrint[0] = 0x5F524D53; |
211 pSmrHeader->iFingerPrint[1] = 0x54524150; |
176 pSmrHeader->iFingerPrint[1] = 0x54524150; |
212 is.seekg(0, ios::beg); |
177 is.seekg(0, ios_base::beg); |
213 is.read(vImage + sizeof(SSmrRomHeader), fsize); |
178 is.read(vImage + sizeof(SSmrRomHeader), fsize); |
214 pSmrHeader->iPayloadChecksum = HMem::CheckSum((TUint *)(vImage + sizeof(SSmrRomHeader)), imageSize - sizeof(SSmrRomHeader)); |
179 pSmrHeader->iPayloadChecksum = HMem::CheckSum((TUint *)(vImage + sizeof(SSmrRomHeader)), imageSize - sizeof(SSmrRomHeader)); |
215 pSmrHeader->iImageSize = imageSize; |
180 pSmrHeader->iImageSize = imageSize; |
216 pSmrHeader->iImageTimestamp = time(0); |
181 pSmrHeader->iImageTimestamp = time(0); |
217 ofstream os(iImageName.c_str(), ios::binary); |
182 ofstream os(iImageName.c_str(), ios_base::binary); |
218 os.write(vImage, imageSize); |
183 os.write(vImage, imageSize); |
219 os.close(); |
184 os.close(); |
220 is.close(); |
185 is.close(); |
221 delete[] vImage; |
186 delete[] vImage; |
222 |
|
223 |
187 |
224 return KErrNone; |
188 return KErrNone; |
225 |
189 |
226 |
190 |
227 } |
191 } |