imgtools/romtools/rofsbuild/r_smrimage.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
child 609 f76e0f94b7ab
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    17 
    17 
    18 
    18 
    19 #include <stdlib.h>
    19 #include <stdlib.h>
    20 #include <string.h>
    20 #include <string.h>
    21 #include <time.h>
    21 #include <time.h>
    22 
       
    23 #ifdef __VC32__
       
    24  #ifdef __MSVCDOTNET__
       
    25   #include <strstream>
       
    26   #include <iomanip>
       
    27  #else //__MSVCDOTNET__
       
    28   #include <strstrea.h>
       
    29   #include <iomanip.h>
       
    30  #endif  //__MSVCDOTNET__
       
    31 #else // !__VC32__
       
    32 #ifdef __TOOLS2__
       
    33 	#include <sstream>
       
    34 	#include <iomanip>
       
    35 	#include <sys/stat.h>
       
    36 	#include <new>
       
    37 	using namespace std;
       
    38 #else
       
    39 	#include <strstrea.h>
       
    40 	#include <iomanip.h>
       
    41 #endif
       
    42  
    22  
    43 #endif //__VC32__
    23 #include <strstream>
       
    24 #include <iomanip> 
       
    25  
    44 #include <e32std.h>
    26 #include <e32std.h>
    45 #include "h_utl.h"
    27 #include "h_utl.h"
    46 #include "r_smrimage.h"
    28 #include "r_smrimage.h"
    47 
    29 using namespace std; 
    48 CSmrImage::CSmrImage(CObeyFile* aObeyFile)
    30 CSmrImage::CSmrImage(CObeyFile* aObeyFile)
    49 	:iObeyFile(aObeyFile)
    31 	:iObeyFile(aObeyFile)
    50 {	
    32 {	
    51 	HMem::Set(&iSmrRomHeader, 0, sizeof(SSmrRomHeader));
    33 	HMem::Set(&iSmrRomHeader, 0, sizeof(SSmrRomHeader));
    52 }
    34 }
    65 	{
    47 	{
    66 		Print(EError, "Keyword Imagename has been set more than one time!");
    48 		Print(EError, "Keyword Imagename has been set more than one time!");
    67 		return EFalse;
    49 		return EFalse;
    68 	}
    50 	}
    69 	iImageName = aValues.at(0);
    51 	iImageName = aValues.at(0);
    70 	if(iImageName.find(".img") == std::string::npos)
    52 	if(iImageName.find(".img") == string::npos)
    71 	{
    53 	{
    72 		iImageName += ".img";
    54 		iImageName += ".img";
    73 	}
    55 	}
    74 	return ETrue;
    56 	return ETrue;
    75 }
    57 }
    83 	if(aValues.size() > 1)
    65 	if(aValues.size() > 1)
    84 	{
    66 	{
    85 		Print(EError, "Keyword Formatversion has been set more than one time!");
    67 		Print(EError, "Keyword Formatversion has been set more than one time!");
    86 		return EFalse;
    68 		return EFalse;
    87 	}
    69 	}
    88 	iSmrRomHeader.iImageVersion = StrToInt(aValues.at(0).c_str());
    70 	Val(iSmrRomHeader.iImageVersion,aValues.at(0).c_str()); 
    89 	return ETrue;
    71 	return ETrue;
    90 }
    72 }
    91 TBool CSmrImage::SetHcrData(const StringVector& aValues)
    73 TBool CSmrImage::SetHcrData(const StringVector& aValues)
    92 {
    74 {
    93 	
    75 	
   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 	}
   132 	if(aValues.size() > 1)
   111 	if(aValues.size() > 1)
   133 	{
   112 	{
   134 		Print(EError, "Keyword PayloadUID has been set more than one time!");
   113 		Print(EError, "Keyword PayloadUID has been set more than one time!");
   135 		return EFalse;
   114 		return EFalse;
   136 	}
   115 	}
   137 	iSmrRomHeader.iPayloadUID = StrToInt(aValues.at(0).c_str());
   116 	Val(iSmrRomHeader.iPayloadUID,aValues.at(0).c_str()); 
   138 	return ETrue;
   117 	return ETrue;
   139 }
   118 }
   140 TBool CSmrImage::SetPayloadFlags(const StringVector& aValues)
   119 TBool CSmrImage::SetPayloadFlags(const StringVector& aValues)
   141 {
   120 {
   142 
   121 
   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 }