imgtools/romtools/rombuild/r_rom.cpp
changeset 708 0757c2976f96
parent 694 c3fbb20e86f0
child 714 e5a58c351011
equal deleted inserted replaced
707:ccd52fece6ff 708:0757c2976f96
   397 	iOverhead=0;
   397 	iOverhead=0;
   398 	}
   398 	}
   399 
   399 
   400 E32Rom::~E32Rom() {
   400 E32Rom::~E32Rom() {
   401 	if(iSymGen){		
   401 	if(iSymGen){		
   402 		delete iSymGen;
   402 		SymbolGenerator::Release();
   403 		iSymGen = NULL ;
   403 		iSymGen = NULL ;
   404 	}
   404 	}
   405 	if(gLowMem)
   405 	if(gLowMem)
   406 	{
   406 	{
   407 		iImageMap->CloseMemoryMap(ETrue);
   407 		iImageMap->CloseMemoryMap(ETrue);
   697 	TRomHeader dummy;
   697 	TRomHeader dummy;
   698 	TInt r=LoadContents(addr, &dummy);
   698 	TInt r=LoadContents(addr, &dummy);
   699 	if (r!=KErrNone)
   699 	if (r!=KErrNone)
   700 		{
   700 		{
   701 		Print(EError, "LoadContents failed - return code %d\n", r);
   701 		Print(EError, "LoadContents failed - return code %d\n", r);
   702 		if(iSymGen)
       
   703 			iSymGen->WaitThreads();
       
   704 		return r;
   702 		return r;
   705 		}
   703 		}
   706 	iExtensionRomHeader->iRomRootDirectoryList = dummy.iRomRootDirectoryList;
   704 	iExtensionRomHeader->iRomRootDirectoryList = dummy.iRomRootDirectoryList;
   707 
   705 
   708 	iLoaderHeader->SetUp(iObey);
   706 	iLoaderHeader->SetUp(iObey);
   709 	FinaliseExtensionHeader(aKernelRom);
   707 	FinaliseExtensionHeader(aKernelRom);
   710 	DisplayExtensionHeader();
   708 	DisplayExtensionHeader();
   711 	if(iSymGen)
       
   712 		iSymGen->WaitThreads();
       
   713 	return KErrNone;
   709 	return KErrNone;
   714 	}
   710 	}
   715 	
   711 	
   716 TInt E32Rom::Create()
   712 TInt E32Rom::Create()
   717 	{
   713 	{
   738 
   734 
   739 	TInt r=LoadContents(addr, iHeader);
   735 	TInt r=LoadContents(addr, iHeader);
   740 	if (r!=KErrNone)
   736 	if (r!=KErrNone)
   741 		{
   737 		{
   742 		Print(EError, "LoadContents failed - return code %d\n", r);
   738 		Print(EError, "LoadContents failed - return code %d\n", r);
   743 		if(iSymGen)
       
   744 			iSymGen->WaitThreads();
       
   745 		return r;
   739 		return r;
   746 		}
   740 		}
   747 
   741 
   748 	r = SetupPages(); // initialize ROM paging info...
   742 	r = SetupPages(); // initialize ROM paging info...
   749 	if(r!=KErrNone)
   743 	if(r!=KErrNone)
   750 		{
   744 		{
   751 		Print(EError, "Setup pages information failed - return code %d\n", r);
   745 		Print(EError, "Setup pages information failed - return code %d\n", r);
   752 		if(iSymGen)
       
   753 			iSymGen->WaitThreads();
       
   754 		return r;
   746 		return r;
   755 		}
   747 		}
   756 	
   748 	
   757 	r = CheckUnpagedMemSize(); // check for unpaged memory overflow
   749 	r = CheckUnpagedMemSize(); // check for unpaged memory overflow
   758 	if(r!=KErrNone)
   750 	if(r!=KErrNone)
   759 	{
   751 	{
   760 		if(iSymGen)
       
   761 			iSymGen->WaitThreads();
       
   762 		return r;
   752 		return r;
   763 	}
   753 	}
   764 	
   754 	
   765 	r = CompressPages(); // setup ROM paging info...
   755 	r = CompressPages(); // setup ROM paging info...
   766 	if(r!=KErrNone)
   756 	if(r!=KErrNone)
   767 		{
   757 		{
   768 		Print(EError, "CompressPages failed - return code %d\n", r);
   758 		Print(EError, "CompressPages failed - return code %d\n", r);
   769 		if(iSymGen)
       
   770 			iSymGen->WaitThreads();
       
   771 		return r;
   759 		return r;
   772 		}
   760 		}
   773 
   761 
   774 	iLoaderHeader->SetUp(iObey);
   762 	iLoaderHeader->SetUp(iObey);
   775 	ImpTRomHeader* header = (ImpTRomHeader *)iHeader;
   763 	ImpTRomHeader* header = (ImpTRomHeader *)iHeader;
   793 	header->Display();
   781 	header->Display();
   794 
   782 
   795 	TUint testCheckSum = HMem::CheckSum((TUint *)iHeader, iHeader->iRomSize);
   783 	TUint testCheckSum = HMem::CheckSum((TUint *)iHeader, iHeader->iRomSize);
   796 	Print(ELog, "Rom 32bit words sum to   %08x\n", testCheckSum);
   784 	Print(ELog, "Rom 32bit words sum to   %08x\n", testCheckSum);
   797 	if (testCheckSum != iObey->iCheckSum){
   785 	if (testCheckSum != iObey->iCheckSum){
   798 		if(iSymGen)
       
   799 			iSymGen->WaitThreads();
       
   800 		return Print(EError, "Rom checksum is incorrect: %08x should be %08x\n",
   786 		return Print(EError, "Rom checksum is incorrect: %08x should be %08x\n",
   801 					testCheckSum, iObey->iCheckSum);
   787 					testCheckSum, iObey->iCheckSum);
   802 	}
   788 	}
   803 
   789 
   804 	// 8bit checksum = sum of bytes
   790 	// 8bit checksum = sum of bytes
   834 					r=(TRomEntry*)(hdr->iNextExtension-iObey->iRomLinearBase+(char*)iHeader);
   820 					r=(TRomEntry*)(hdr->iNextExtension-iObey->iRomLinearBase+(char*)iHeader);
   835 					n++;
   821 					n++;
   836 					}
   822 					}
   837 			}
   823 			}
   838 		}
   824 		}
   839 	if(iSymGen)
       
   840 			iSymGen->WaitThreads();
       
   841 	return KErrNone;
   825 	return KErrNone;
   842 	}
   826 	}
   843 
   827 
   844 char *E32Rom::WriteDirectory(char *aAddr, TRomHeader* aHeader)
   828 char *E32Rom::WriteDirectory(char *aAddr, TRomHeader* aHeader)
   845 //
   829 //
  1323 		}
  1307 		}
  1324 
  1308 
  1325 	TInt fileCount=0;
  1309 	TInt fileCount=0;
  1326 	if(gGenSymbols && !iSymGen) {
  1310 	if(gGenSymbols && !iSymGen) {
  1327 		string filename(iObey->GetFileName());
  1311 		string filename(iObey->GetFileName());
  1328 		filename.erase(filename.length() - 3,3);
  1312 		iSymGen = SymbolGenerator::GetInstance();
  1329 		filename.append("symbol");
  1313 		iSymGen ->SetImageType(ERomImage);
  1330 		iSymGen = new SymbolGenerator(filename.c_str(),gThreadNum - 1);		
  1314 		iSymGen ->SetSymbolFileName(filename);		
  1331 	}
  1315 	}
  1332 		
  1316 		
  1333 	//
  1317 	//
  1334 	// Process files in non default areas
  1318 	// Process files in non default areas
  1335 	//
  1319 	//
  1397 	TInt offset=(char*)mainptr->iImagePtr-romaddr;
  1381 	TInt offset=(char*)mainptr->iImagePtr-romaddr;
  1398 	offset = Align(offset)-offset;
  1382 	offset = Align(offset)-offset;
  1399 	mainptr->Extend(offset);
  1383 	mainptr->Extend(offset);
  1400 	iOverhead +=offset;
  1384 	iOverhead +=offset;
  1401 	if(iSymGen){
  1385 	if(iSymGen){
  1402 		SymGenContext context ;
  1386 		iSymGen->SetFinished();
  1403 		memset(&context,0,sizeof(SymGenContext));
       
  1404 		iSymGen->AddEntry(context);
       
  1405 	}
  1387 	}
  1406 	return (char*)mainptr->iImagePtr;
  1388 	return (char*)mainptr->iImagePtr;
  1407  	}
  1389  	}
  1408 
  1390 
  1409 void E32Rom::LayoutFile(TRomBuilderEntry* current, TAddressRange& aMain, TAddressRange* aSecond, CBytePair * aBPE)
  1391 void E32Rom::LayoutFile(TRomBuilderEntry* current, TAddressRange& aMain, TAddressRange* aSecond, CBytePair * aBPE)
  1452 		TInt size=LoadDataToRom(current, aMain, aBPE);
  1434 		TInt size=LoadDataToRom(current, aMain, aBPE);
  1453 		if (aSecond != 0 && aMain.iImageAddr > iObey->iSectionStart)
  1435 		if (aSecond != 0 && aMain.iImageAddr > iObey->iSectionStart)
  1454 			return;		// first section has overflowed
  1436 			return;		// first section has overflowed
  1455 		current->FixupRomEntries(size);
  1437 		current->FixupRomEntries(size);
  1456 		if(iSymGen) {
  1438 		if(iSymGen) {
  1457 			SymGenContext context ;
  1439 			TPlacedEntry context ;
  1458 			memset(&context,0,sizeof(SymGenContext));
       
  1459 			context.iFileName = current->iFileName ;
  1440 			context.iFileName = current->iFileName ;
  1460 			context.iDataAddress = savedAddr ;
  1441 			context.iDataAddress = savedAddr ;
  1461 			iSymGen->AddEntry(context); 
  1442 			iSymGen->AddEntry(context); 
  1462 		}
  1443 		}
  1463 		return;
  1444 		return;
  1468 			return;		// first section has overflowed
  1449 			return;		// first section has overflowed
  1469 		current->FixupRomEntries(size);
  1450 		current->FixupRomEntries(size);
  1470 		iHeader->iHcrFileAddress =  current->iHeaderRange.iImageAddr ;
  1451 		iHeader->iHcrFileAddress =  current->iHeaderRange.iImageAddr ;
  1471 		TRACE(TAREA, Print(ELog, "iHeader->iHcrFileAddress = %08x\n", iHeader->iHcrFileAddress));	
  1452 		TRACE(TAREA, Print(ELog, "iHeader->iHcrFileAddress = %08x\n", iHeader->iHcrFileAddress));	
  1472 		if(iSymGen) {
  1453 		if(iSymGen) {
  1473 			SymGenContext context ;
  1454 			TPlacedEntry context ;
  1474 			memset(&context,0,sizeof(SymGenContext));
       
  1475 			context.iFileName = current->iFileName ;
  1455 			context.iFileName = current->iFileName ;
  1476 			context.iDataAddress = savedAddr ;
  1456 			context.iDataAddress = savedAddr ;
  1477 			iSymGen->AddEntry(context); 
  1457 			iSymGen->AddEntry(context); 
  1478 		}		
  1458 		}		
  1479 		return ;
  1459 		return ;
  1533 		return;		// first section has overflowed
  1513 		return;		// first section has overflowed
  1534 
  1514 
  1535 	LoadFileToRom(current);
  1515 	LoadFileToRom(current);
  1536 	TRomImageHeader *header = current->iRomImageHeader;
  1516 	TRomImageHeader *header = current->iRomImageHeader;
  1537 	if(iSymGen){
  1517 	if(iSymGen){
  1538 		SymGenContext context  ;
  1518 		TPlacedEntry context  ;
  1539 		context.iFileName = current->iFileName ;		
  1519 		context.iFileName = current->iFileName ;		
  1540 		context.iTotalSize = section1size;
  1520 		context.iTotalSize = section1size;
  1541 		context.iCodeAddress = header->iCodeAddress; 
  1521 		context.iCodeAddress = header->iCodeAddress; 
  1542 		context.iDataAddress = header->iDataAddress; 
  1522 		context.iDataAddress = header->iDataAddress; 
  1543 		context.iDataBssLinearBase = header->iDataBssLinearBase;	 
  1523 		context.iDataBssLinearBase = header->iDataBssLinearBase;