imgtools/romtools/rofsbuild/r_build.cpp
changeset 691 9eeecb73a5d4
parent 672 bc9ef8cca9ec
child 694 c3fbb20e86f0
equal deleted inserted replaced
690:c67de7b29582 691:9eeecb73a5d4
    57 #include "cache/cachevalidator.hpp"
    57 #include "cache/cachevalidator.hpp"
    58 #include "cache/cacheablelist.hpp"
    58 #include "cache/cacheablelist.hpp"
    59 #include "cache/cachemanager.hpp"
    59 #include "cache/cachemanager.hpp"
    60 
    60 
    61 #include "uniconv.hpp"
    61 #include "uniconv.hpp"
       
    62 
       
    63 #define MAX_LINE 65535
       
    64 
    62 extern TUint checkSum(const void* aPtr);
    65 extern TUint checkSum(const void* aPtr);
    63 
    66 
    64 extern ECompression gCompress;
    67 extern ECompression gCompress;
    65 extern TUint gCompressionMethod;
    68 extern TUint gCompressionMethod;
    66 extern TInt  gCodePagingOverride;
    69 extern TInt  gCodePagingOverride;
   623 			//Offset in 32bit words from start of file block
   626 			//Offset in 32bit words from start of file block
   624 			TUint32 offset = ((((TUint8*) entry) - fileBlockBase) >> 2);
   627 			TUint32 offset = ((((TUint8*) entry) - fileBlockBase) >> 2);
   625 			
   628 			
   626 			if(offset > 0xFFFF)
   629 			if(offset > 0xFFFF)
   627 			{
   630 			{
   628 				printf("ERROR: Offset overflow: name=%s, OFFSET = %d\n", node->iName, offset);
   631 				printf("ERROR: Offset overflow: name=%s, OFFSET = %d\n", node->iName, (unsigned int)offset);
   629 				throw "fail";
   632 				throw "fail";
   630 			}
   633 			}
   631 			
   634 			
   632 			
   635 			
   633 			array[index].iOffset = (TUint16) offset;
   636 			array[index].iOffset = (TUint16) offset;
   638 			entry = pDirEntry;
   641 			entry = pDirEntry;
   639 
   642 
   640 			TUint32 offset = ((((TUint8*) entry) - dirBlockBase) >> 2);
   643 			TUint32 offset = ((((TUint8*) entry) - dirBlockBase) >> 2);
   641 			if(offset > 0xFFFF)
   644 			if(offset > 0xFFFF)
   642 			{
   645 			{
   643 				printf("ERROR: Offset overflow: name=%s, OFFSET = %d\n", node->iName, offset);
   646 				printf("ERROR: Offset overflow: name=%s, OFFSET = %d\n", node->iName, (unsigned int)offset);
   644 				throw "fail";
   647 				throw "fail";
   645 			}
   648 			}
   646 			
   649 			
   647 			//Offset in 32bit words from start of directory block
   650 			//Offset in 32bit words from start of directory block
   648 			array[index].iOffset = (TUint16) offset;
   651 			array[index].iOffset = (TUint16) offset;
   788 		exit(666);
   791 		exit(666);
   789 		}
   792 		}
   790 	iNextNodeForSameFile = aPreviousNode;
   793 	iNextNodeForSameFile = aPreviousNode;
   791 	}
   794 	}
   792 
   795 
   793 
   796 void TRomNode::FlushLogMessages()
       
   797 {
       
   798 	if(iEntry)
       
   799 	{
       
   800 		for(int i=0; i < (int) iEntry->iLogMessages.size(); i++)
       
   801 		{
       
   802 			std::string& log = iEntry->iLogMessages[i];
       
   803 			Print(ELog, log.c_str());
       
   804 		}
       
   805 		iEntry->iLogMessages.clear();
       
   806 	}
       
   807 }
   794 
   808 
   795 
   809 
   796 
   810 
   797 //**************************************
   811 //**************************************
   798 // TRomBuilderEntry
   812 // TRomBuilderEntry
   861 //
   875 //
   862 // Returns the number of bytes used, or -ve error code
   876 // Returns the number of bytes used, or -ve error code
   863 TInt TRomBuilderEntry::PlaceFile( TUint8* &aDest,TUint aMaxSize, CBytePair *aBPE ){
   877 TInt TRomBuilderEntry::PlaceFile( TUint8* &aDest,TUint aMaxSize, CBytePair *aBPE ){
   864 
   878 
   865 
   879 
       
   880 	char tmpbuf[MAX_LINE];
   866 	TUint compression = 0;
   881 	TUint compression = 0;
   867 	TBool executable = iExecutable;
   882 	TBool executable = iExecutable;
   868 	Print(ELog,"Reading file %s to image\n", iFileName );
   883 	sprintf(tmpbuf,"Reading file %s to image\n", iFileName );
       
   884 	iLogMessages.push_back(tmpbuf);
       
   885 
   869 	TUint32 size = HFile::GetLength(iFileName);
   886 	TUint32 size = HFile::GetLength(iFileName);
   870 	if (size==0)
   887 	if (size==0)
   871 		Print(EWarning, "File %s does not exist or is 0 bytes in length.\n",iFileName);
   888 		Print(EWarning, "File %s does not exist or is 0 bytes in length.\n",iFileName);
   872 	if (aDest == NULL) {
   889 	if (aDest == NULL) {
   873 		aMaxSize = size << 1;
   890 		aMaxSize = size << 1;
  1068 			if ( oldFileComp != newFileComp )
  1085 			if ( oldFileComp != newFileComp )
  1069 			{
  1086 			{
  1070 
  1087 
  1071 				if( newFileComp == 0)
  1088 				if( newFileComp == 0)
  1072 				{
  1089 				{
  1073 					Print(ELog,"Decompressing executable '%s'\n", iFileName);
  1090 					sprintf(tmpbuf,"Decompressing executable '%s'\n", iFileName);
       
  1091 					iLogMessages.push_back(tmpbuf);
  1074 					f.iHdr->iCompressionType = 0;
  1092 					f.iHdr->iCompressionType = 0;
  1075 				}
  1093 				}
  1076 				else
  1094 				else
  1077 				{
  1095 				{
  1078 					Print(ELog,"Compressing executable '%s' with method:%08x\n", iFileName, newFileComp);
  1096 					sprintf(tmpbuf,"Compressing executable '%s' with method:%08x\n", iFileName, (unsigned int)newFileComp);
       
  1097 					iLogMessages.push_back(tmpbuf);
  1079 					f.iHdr->iCompressionType = newFileComp;
  1098 					f.iHdr->iCompressionType = newFileComp;
  1080 				}
  1099 				}
  1081 				f.UpdateHeaderCrc();
  1100 				f.UpdateHeaderCrc();
  1082 				if (overflow)
  1101 				if (overflow)
  1083 				{
  1102 				{
  1122 					memcpy(aDest, entryref->GetCachedFileBuffer(), size);
  1141 					memcpy(aDest, entryref->GetCachedFileBuffer(), size);
  1123 					memcpy(aDest,f.iHdr,sizeof(E32ImageHeaderV));
  1142 					memcpy(aDest,f.iHdr,sizeof(E32ImageHeaderV));
  1124 					compression = atoi(entryref->GetCachedFileCompressionID());
  1143 					compression = atoi(entryref->GetCachedFileCompressionID());
  1125 					memcpy(&iUids[0], aDest, sizeof(iUids));
  1144 					memcpy(&iUids[0], aDest, sizeof(iUids));
  1126 					if (compression)
  1145 					if (compression)
  1127 						Print(ELog,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, size, compression);
  1146 						sprintf(tmpbuf,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, (unsigned int) size, (unsigned int)compression);
  1128 					else if (iExecutable)
  1147 					else if (iExecutable)
  1129 						Print(ELog,"Executable File '%s' size: %08x\n", iFileName, size);
  1148 						sprintf(tmpbuf,"Executable File '%s' size: %08x\n", iFileName, (unsigned int)size);
  1130 					else
  1149 					else
  1131 						Print(ELog,"File '%s' size: %08x\n", iFileName, size);
  1150 						sprintf(tmpbuf,"File '%s' size: %08x\n", iFileName, (unsigned int) size);
       
  1151 					iLogMessages.push_back(tmpbuf);
  1132 					iRealFileSize = size;	// required later when directory is written
  1152 					iRealFileSize = size;	// required later when directory is written
  1133 
  1153 
  1134 					return size;
  1154 					return size;
  1135 				}
  1155 				}
  1136 			}
  1156 			}
  1204 		TUint32 Uidslen = (size > sizeof(iUids)) ? sizeof(iUids) : size;
  1224 		TUint32 Uidslen = (size > sizeof(iUids)) ? sizeof(iUids) : size;
  1205 		memcpy(&iUids[0], aDest, Uidslen);
  1225 		memcpy(&iUids[0], aDest, Uidslen);
  1206 	}
  1226 	}
  1207 
  1227 
  1208 	if (compression)
  1228 	if (compression)
  1209 		Print(ELog,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, size, compression);
  1229 		sprintf(tmpbuf,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, (unsigned int) size, (unsigned int) compression);
  1210 	else if (iExecutable)
  1230 	else if (iExecutable)
  1211 		Print(ELog,"Executable File '%s' size: %08x\n", iFileName, size);
  1231 		sprintf(tmpbuf,"Executable File '%s' size: %08x\n", iFileName, (unsigned int) size);
  1212 	else
  1232 	else
  1213 		Print(ELog,"File '%s' size: %08x\n", iFileName, size);
  1233 		sprintf(tmpbuf,"File '%s' size: %08x\n", iFileName, (unsigned int) size);
       
  1234 	iLogMessages.push_back(tmpbuf);
  1214 	iCompressEnabled = compression;
  1235 	iCompressEnabled = compression;
  1215 	iRealFileSize = size;	// required later when directory is written
  1236 	iRealFileSize = size;	// required later when directory is written
  1216 
  1237 
  1217 	return size;
  1238 	return size;
  1218 }
  1239 }