e32tools/elf2e32/source/e32imagefile.cpp
changeset 606 30b30f9da0b7
parent 0 044383f39525
child 607 378360dbbdba
equal deleted inserted replaced
605:122d2b873fd1 606:30b30f9da0b7
    31 #include "elffilesupplied.h"
    31 #include "elffilesupplied.h"
    32 #include "pl_dllsymbol.h"
    32 #include "pl_dllsymbol.h"
    33 #include "h_ver.h"
    33 #include "h_ver.h"
    34 #include "checksum.h"
    34 #include "checksum.h"
    35 #include "errorhandler.h"
    35 #include "errorhandler.h"
       
    36 #include "byte_pair.h"
    36 
    37 
    37 #include <string>
    38 #include <string>
    38 #include <vector>
    39 #include <vector>
    39 #include <cassert>
    40 #include <cassert>
    40 #include <iostream>
    41 #include <iostream>
    54 	unsigned int mask = ~inc;
    55 	unsigned int mask = ~inc;
    55 	unsigned int val = (unsigned int)v;
    56 	unsigned int val = (unsigned int)v;
    56 	unsigned int res = (val+inc) & mask;
    57 	unsigned int res = (val+inc) & mask;
    57 	return (T)res;
    58 	return (T)res;
    58 }
    59 }
    59 
       
    60 // Need a default constructor for TVersion, but don't want all the other stuff in h_utl.cpp
       
    61 /**
       
    62 Default constructor for TVersion class.
       
    63 @internalComponent
       
    64 @released
       
    65 */
       
    66 TVersion::TVersion(){}
       
    67 
       
    68 /**
       
    69 Constructor for TVersion class.
       
    70 @internalComponent
       
    71 @released
       
    72 */
       
    73 TVersion::TVersion(TInt aMajor, TInt aMinor, TInt aBuild): 
       
    74 	iMajor((TInt8)aMajor), iMinor((TInt8)aMinor), iBuild((TInt16)aBuild)
       
    75 {
       
    76 }
       
    77 
       
    78 
    60 
    79 /**
    61 /**
    80 Constructor for E32ImageChunkDesc class.
    62 Constructor for E32ImageChunkDesc class.
    81 @internalComponent
    63 @internalComponent
    82 @released
    64 @released
  1175 {
  1157 {
  1176 	iHdr->iFlags &=~ KImageHWFloatMask;
  1158 	iHdr->iFlags &=~ KImageHWFloatMask;
  1177 
  1159 
  1178 	if (iUseCase->GetFPU() == 1)
  1160 	if (iUseCase->GetFPU() == 1)
  1179 		iHdr->iFlags |= KImageHWFloat_VFPv2;
  1161 		iHdr->iFlags |= KImageHWFloat_VFPv2;
       
  1162 	else if (iUseCase->GetFPU() == 2)
       
  1163 		iHdr->iFlags |= KImageHWFloat_VFPv3;
       
  1164 	else if (iUseCase->GetFPU() == 3)
       
  1165 		iHdr->iFlags |= KImageHWFloat_VFPv3D16; 
  1180 }
  1166 }
  1181 
  1167 
  1182 /**
  1168 /**
  1183 This function sets the paging attribute in the E32 image.
  1169 This function sets the paging attribute in the E32 image.
  1184 @internalComponent
  1170 @internalComponent
  1400 @param size
  1386 @param size
  1401 @param os
  1387 @param os
  1402 @internalComponent
  1388 @internalComponent
  1403 @released
  1389 @released
  1404 */
  1390 */
  1405 void CompressPages(TUint8 * bytes, TInt size, ofstream& os);
  1391 void CompressPages(TUint8 * bytes, TInt size, ostream& os, CBytePair *aBPE);
  1406 
  1392 
  1407 
  1393 
  1408 /**
  1394 /**
  1409 This function writes into the final E32 image file.
  1395 This function writes into the final E32 image file.
  1410 @param aName - E32 image file name
  1396 @param aName - E32 image file name
  1430 		{
  1416 		{
  1431 			size_t aHeaderSize = GetExtendedE32ImageHeaderSize();
  1417 			size_t aHeaderSize = GetExtendedE32ImageHeaderSize();
  1432 			os->write(iE32Image, aHeaderSize);
  1418 			os->write(iE32Image, aHeaderSize);
  1433 			
  1419 			
  1434 			// Compress and write out code part
  1420 			// Compress and write out code part
       
  1421 			CBytePair bpe;
  1435 			int srcStart = GetExtendedE32ImageHeaderSize();
  1422 			int srcStart = GetExtendedE32ImageHeaderSize();
  1436 			CompressPages( (TUint8*)iE32Image + srcStart, iHdr->iCodeSize, *os);
  1423 			CompressPages( (TUint8*)iE32Image + srcStart, iHdr->iCodeSize, *os, &bpe);
  1437 			
  1424 			
  1438 			
  1425 			
  1439 			// Compress and write out data part
  1426 			// Compress and write out data part
  1440 			srcStart += iHdr->iCodeSize;
  1427 			srcStart += iHdr->iCodeSize;
  1441 			int srcLen = GetE32ImageSize() - srcStart;
  1428 			int srcLen = GetE32ImageSize() - srcStart;
  1442 			
  1429 			
  1443 			CompressPages((TUint8*)iE32Image + srcStart, srcLen, *os);		
  1430 			CompressPages((TUint8*)iE32Image + srcStart, srcLen, *os, &bpe);		
  1444 
  1431 
  1445 		}
  1432 		}
  1446 		else if (compression == 0)
  1433 		else if (compression == 0)
  1447 		{
  1434 		{
  1448 			os->write(iE32Image, GetE32ImageSize()); // image not compressed
  1435 			os->write(iE32Image, GetE32ImageSize()); // image not compressed
  1696 	
  1683 	
  1697 	return KErrNone;
  1684 	return KErrNone;
  1698 }
  1685 }
  1699 
  1686 
  1700 
  1687 
  1701 int  DecompressPages(TUint8 * bytes, ifstream& is);
  1688 int DecompressPages(TUint8 * bytes, istream& is, CBytePair *aBPE);
  1702 
  1689 
  1703 
  1690 
  1704 /**
  1691 /**
  1705 This function creates the E32 image reading from the file
  1692 This function creates the E32 image reading from the file
  1706 @param is
  1693 @param is
  1767 		if (aImage.iData==NULL)
  1754 		if (aImage.iData==NULL)
  1768 			return is;
  1755 			return is;
  1769 		oh = aImage.iOrigHdr;
  1756 		oh = aImage.iOrigHdr;
  1770 
  1757 
  1771 		// Read and decompress code part of the image
  1758 		// Read and decompress code part of the image
  1772 
  1759 		CBytePair bpe;
  1773 		unsigned int uncompressedCodeSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz), is);
  1760 		unsigned int uncompressedCodeSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz), is, &bpe);
  1774 
  1761 
  1775 		
  1762 		
  1776 		// Read and decompress data part of the image
  1763 		// Read and decompress data part of the image
  1777 
  1764 
  1778 		unsigned int uncompressedDataSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz + uncompressedCodeSize), is);
  1765 		unsigned int uncompressedDataSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz + uncompressedCodeSize), is, &bpe);
  1779 
  1766 
  1780 		if (uncompressedCodeSize + uncompressedDataSize != uncompsize)
  1767 		if (uncompressedCodeSize + uncompressedDataSize != uncompsize)
  1781 			MessageHandler::GetInstance()->ReportMessage(WARNING, BYTEPAIRINCONSISTENTSIZEERROR);
  1768 			MessageHandler::GetInstance()->ReportMessage(WARNING, BYTEPAIRINCONSISTENTSIZEERROR);
  1782 
  1769 
  1783 		if ((TUint)orighdrsz > oh->iCodeOffset)
  1770 		if ((TUint)orighdrsz > oh->iCodeOffset)