fprintf (stdout, " -i FileName, --inputfile FileName\n\\r
File is the input FV.inf or Cap.inf to specify\n\\r
how to construct FvImage or CapImage.\n");\r
+ fprintf (stdout, " -b BlockSize, --blocksize BlockSize\n\\r
+ BlockSize is one HEX or DEC format value\n\\r
+ BlockSize is required by Fv Image.\n");\r
+ fprintf (stdout, " -n NumberBlock, --numberblock NumberBlock\n\\r
+ NumberBlock is one HEX or DEC format value\n\\r
+ NumberBlock is one optional parameter.\n");\r
+ fprintf (stdout, " -f FfsFile, --ffsfile FfsFile\n\\r
+ FfsFile is placed into Fv Image\n\\r
+ multi files can input one by one\n");\r
fprintf (stdout, " -r Address, --baseaddr Address\n\\r
Address is the rebase start address for drivers that\n\\r
run in Flash. It supports DEC or HEX digital format.\n");\r
fprintf (stdout, " -m logfile, --map logfile\n\\r
Logfile is the output fv map file name. if it is not\n\\r
given, the FvName.map will be the default map file name\n"); \r
+ fprintf (stdout, " --capguid GuidValue\n\\r
+ GuidValue is one specific capsule vendor guid value.\n\\r
+ Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");\r
+ fprintf (stdout, " --capflag CapFlag\n\\r
+ Capsule Reset Flag can be PersistAcrossReset,\n\\r
+ or PopulateSystemTable or not set.\n");\r
+ fprintf (stdout, " --capheadsize HeadSize\n\\r
+ HeadSize is one HEX or DEC format value\n\\r
+ HeadSize is required by Capsule Image.\n"); \r
fprintf (stdout, " -c, --capsule Create Capsule Image.\n");\r
fprintf (stdout, " -p, --dump Dump Capsule Image header.\n");\r
fprintf (stdout, " -v, --verbose Turn on verbose output with informational messages.\n");\r
fprintf (stdout, " -h, --help Show this help message and exit.\n");\r
}\r
\r
+UINT32 mFvTotalSize;\r
+UINT32 mFvTakenSize;\r
+\r
int\r
main (\r
IN INTN argc,\r
MEMORY_FILE AddrMemoryFile;\r
FILE *FpFile;\r
EFI_CAPSULE_HEADER *CapsuleHeader;\r
- UINT64 LogLevel;\r
+ UINT64 LogLevel, TempNumber;\r
+ UINT32 Index;\r
\r
InfFileName = NULL;\r
AddrFileName = NULL;\r
FpFile = NULL;\r
CapsuleHeader = NULL;\r
LogLevel = 0;\r
+ TempNumber = 0;\r
+ Index = 0;\r
+ mFvTotalSize = 0;\r
+ mFvTakenSize = 0;\r
\r
SetUtilityName (UTILITY_NAME);\r
\r
return STATUS_ERROR;\r
}\r
\r
+ //\r
+ // Init global data to Zero\r
+ //\r
+ memset (&gFvDataInfo, 0, sizeof (FV_INFO));\r
+ memset (&gCapDataInfo, 0, sizeof (CAP_INFO)); \r
+ \r
//\r
// Parse command line\r
//\r
continue; \r
}\r
\r
+ if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--blocksize") == 0)) {\r
+ Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
+ return STATUS_ERROR; \r
+ }\r
+ gFvDataInfo.FvBlocks[0].Length = (UINT32) TempNumber;\r
+ DebugMsg (NULL, 0, 9, "FV Block Size", "%s = 0x%x", EFI_BLOCK_SIZE_STRING, TempNumber);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue; \r
+ }\r
+\r
+ if ((stricmp (argv[0], "-n") == 0) || (stricmp (argv[0], "--numberblock") == 0)) {\r
+ Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
+ return STATUS_ERROR; \r
+ }\r
+ gFvDataInfo.FvBlocks[0].NumBlocks = (UINT32) TempNumber;\r
+ DebugMsg (NULL, 0, 9, "FV Number Block", "%s = 0x%x", EFI_NUM_BLOCKS_STRING, TempNumber);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue; \r
+ }\r
+\r
+ if ((stricmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--ffsfile") == 0)) {\r
+ if (argv[1] == NULL) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile can't be null");\r
+ return STATUS_ERROR;\r
+ }\r
+ strcpy (gFvDataInfo.FvFiles[Index++], argv[1]);\r
+ DebugMsg (NULL, 0, 9, "FV component file", "the %dth name is %s", Index - 1, argv[1]);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue; \r
+ }\r
+\r
if ((stricmp (argv[0], "-c") == 0) || (stricmp (argv[0], "--capsule") == 0)) {\r
CapsuleFlag = TRUE;\r
argc --;\r
continue; \r
}\r
\r
+ if (stricmp (argv[0], "--capheadsize") == 0) {\r
+ //\r
+ // Get Capsule Image Header Size\r
+ //\r
+ Status = AsciiStringToUint64 (argv[1], FALSE, &TempNumber);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
+ return STATUS_ERROR; \r
+ }\r
+ gCapDataInfo.HeaderSize = (UINT32) TempNumber;\r
+ DebugMsg (NULL, 0, 9, "Capsule Header size", "%s = 0x%x", EFI_CAPSULE_HEADER_SIZE_STRING, TempNumber);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue; \r
+ }\r
+\r
+ if (stricmp (argv[0], "--capflag") == 0) {\r
+ //\r
+ // Get Capsule Header\r
+ //\r
+ if (argv[1] == NULL) {\r
+ Error (NULL, 0, 1003, "Option value is not set", "%s = %s", argv[0], argv[1]);\r
+ return STATUS_ERROR;\r
+ }\r
+ if (strcmp (argv[1], "PopulateSystemTable") == 0) {\r
+ gCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET | CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE;\r
+ } else if (strcmp (argv[1], "PersistAcrossReset") == 0) {\r
+ gCapDataInfo.Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET;\r
+ } else {\r
+ Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
+ return STATUS_ERROR;\r
+ }\r
+ DebugMsg (NULL, 0, 9, "Capsule Flag", argv[1]);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue; \r
+ }\r
+\r
+ if (stricmp (argv[0], "--capguid") == 0) {\r
+ //\r
+ // Get the Capsule Guid\r
+ //\r
+ Status = StringToGuid (argv[1], &gCapDataInfo.CapGuid);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 1003, "Invalid option value", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);\r
+ return EFI_ABORTED;\r
+ }\r
+ DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, argv[1]);\r
+ argc -= 2;\r
+ argv += 2;\r
+ continue; \r
+ }\r
+\r
if ((stricmp (argv[0], "-p") == 0) || (stricmp (argv[0], "--dump") == 0)) {\r
DumpCapsule = TRUE;\r
argc --;\r
VerboseMsg ("%s tool start.", UTILITY_NAME);\r
\r
//\r
- // check input parameter\r
+ // check input parameter, InfFileName can be NULL\r
//\r
- if (InfFileName == NULL) {\r
- Error (NULL, 0, 1001, "Missing option", "Input File");\r
+ if (InfFileName == NULL && DumpCapsule) {\r
+ Error (NULL, 0, 1001, "Missing option", "Input Capsule Image");\r
return STATUS_ERROR;\r
}\r
VerboseMsg ("the input file name is %s", InfFileName);\r
// free the allocated memory space for addr file.\r
//\r
free (InfFileImage);\r
+ InfFileImage = NULL;\r
+ InfFileSize = 0;\r
}\r
\r
//\r
// Read the INF file image\r
//\r
- Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);\r
- if (EFI_ERROR (Status)) {\r
- return STATUS_ERROR;\r
+ if (InfFileName != NULL) {\r
+ Status = GetFileImage (InfFileName, &InfFileImage, &InfFileSize);\r
+ if (EFI_ERROR (Status)) {\r
+ return STATUS_ERROR;\r
+ }\r
}\r
\r
if (DumpCapsule) {\r
//\r
// Call the GenerateCapImage to generate Capsule Image\r
//\r
- GenerateCapImage (\r
- InfFileImage, \r
- InfFileSize,\r
- OutFileName\r
- );\r
+ for (Index = 0; gFvDataInfo.FvFiles[Index][0] != '\0'; Index ++) {\r
+ strcpy (gCapDataInfo.CapFiles[Index], gFvDataInfo.FvFiles[Index]);\r
+ }\r
+\r
+ Status = GenerateCapImage (\r
+ InfFileImage, \r
+ InfFileSize,\r
+ OutFileName\r
+ );\r
} else {\r
VerboseMsg ("Create Fv image and its map file");\r
if (XipBase != 0) {\r
//\r
// Call the GenerateFvImage to generate Fv Image\r
//\r
- GenerateFvImage (\r
- InfFileImage,\r
- InfFileSize,\r
- OutFileName,\r
- MapFileName,\r
- XipBase,\r
- &BtBase,\r
- &RtBase\r
- );\r
+ Status = GenerateFvImage (\r
+ InfFileImage,\r
+ InfFileSize,\r
+ OutFileName,\r
+ MapFileName,\r
+ XipBase,\r
+ &BtBase,\r
+ &RtBase\r
+ );\r
}\r
\r
//\r
//\r
// update boot driver address and runtime driver address in address file\r
//\r
- if (AddrFileName != NULL) {\r
+ if (Status == EFI_SUCCESS && AddrFileName != NULL) {\r
FpFile = fopen (AddrFileName, "w");\r
if (FpFile == NULL) {\r
Error (NULL, 0, 0001, "Error opening file", AddrFileName);\r
fprintf (FpFile, " = 0x%x\n", RtBase);\r
DebugMsg (NULL, 0, 9, "Updated runtime driver base address", "%s = 0x%x", EFI_FV_RUNTIME_DRIVER_BASE_ADDRESS_STRING, RtBase);\r
}\r
+ if (mFvTotalSize != 0) {\r
+ fprintf (FpFile, EFI_FV_TOTAL_SIZE_STRING);\r
+ fprintf (FpFile, " = 0x%x\n", mFvTotalSize);\r
+ DebugMsg (NULL, 0, 9, "The Total Fv Size", "%s = 0x%x", EFI_FV_TOTAL_SIZE_STRING, mFvTotalSize);\r
+ }\r
+ if (mFvTakenSize != 0) {\r
+ fprintf (FpFile, EFI_FV_TAKEN_SIZE_STRING);\r
+ fprintf (FpFile, " = 0x%x\n", mFvTakenSize);\r
+ DebugMsg (NULL, 0, 9, "The used Fv Size", "%s = 0x%x", EFI_FV_TAKEN_SIZE_STRING, mFvTakenSize);\r
+ }\r
+ if (mFvTotalSize != 0 && mFvTakenSize != 0) {\r
+ fprintf (FpFile, EFI_FV_SPACE_SIZE_STRING);\r
+ fprintf (FpFile, " = 0x%x\n", mFvTotalSize - mFvTakenSize);\r
+ DebugMsg (NULL, 0, 9, "The space Fv size", "%s = 0x%x", EFI_FV_SPACE_SIZE_STRING, mFvTotalSize - mFvTakenSize);\r
+ }\r
fclose (FpFile);\r
}\r
\r
EFI_GUID mEfiFirmwareFileSystem2Guid = EFI_FIRMWARE_FILE_SYSTEM2_GUID;\r
EFI_GUID mEfiFirmwareVolumeTopFileGuid = EFI_FFS_VOLUME_TOP_FILE_GUID;\r
EFI_GUID mFileGuidArray [MAX_NUMBER_OF_FILES_IN_FV] = {0};\r
+EFI_GUID mZeroGuid = {0x0, 0x0, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};\r
+EFI_GUID mDefaultCapsuleGuid = {0x3B6686BD, 0x0D76, 0x4030, { 0xB7, 0x0E, 0xB5, 0x51, 0x9E, 0x2F, 0xC5, 0xA0 }};\r
\r
CHAR8 *mFvbAttributeName[] = {\r
EFI_FVB2_READ_DISABLED_CAP_STRING, \r
0x00\r
};\r
\r
+FV_INFO gFvDataInfo;\r
+CAP_INFO gCapDataInfo;\r
+\r
EFI_STATUS\r
ParseFvInf (\r
IN MEMORY_FILE *InfFile,\r
{\r
CHAR8 Value[_MAX_PATH];\r
UINT64 Value64;\r
- UINTN Index;\r
+ UINTN Index, Number;\r
EFI_STATUS Status;\r
\r
//\r
// Initialize FV info\r
//\r
- memset (FvInfo, 0, sizeof (FV_INFO));\r
+ // memset (FvInfo, 0, sizeof (FV_INFO));\r
+ //\r
\r
//\r
// Read the FV base address\r
//\r
// Read block maps\r
//\r
+ Number = 0;\r
for (Index = 0; Index < MAX_NUMBER_OF_FV_BLOCKS; Index++) {\r
+ if (FvInfo->FvBlocks[Index].Length != 0) {\r
+ continue;\r
+ }\r
//\r
// Read block size\r
//\r
- Status = FindToken (InfFile, OPTIONS_SECTION_STRING, EFI_BLOCK_SIZE_STRING, Index, Value);\r
+ Status = FindToken (InfFile, OPTIONS_SECTION_STRING, EFI_BLOCK_SIZE_STRING, Number, Value);\r
\r
if (Status == EFI_SUCCESS) {\r
//\r
// If there is no blocks size, but there is the number of block, then we have a mismatched pair\r
// and should return an error.\r
//\r
- Status = FindToken (InfFile, OPTIONS_SECTION_STRING, EFI_NUM_BLOCKS_STRING, Index, Value);\r
+ Status = FindToken (InfFile, OPTIONS_SECTION_STRING, EFI_NUM_BLOCKS_STRING, Number, Value);\r
if (!EFI_ERROR (Status)) {\r
Error (NULL, 0, 2000, "Invalid parameter", "both %s and %s must be specified.", EFI_NUM_BLOCKS_STRING, EFI_BLOCK_SIZE_STRING);\r
return EFI_ABORTED;\r
//\r
// Read blocks number\r
//\r
- Status = FindToken (InfFile, OPTIONS_SECTION_STRING, EFI_NUM_BLOCKS_STRING, Index, Value);\r
+ Status = FindToken (InfFile, OPTIONS_SECTION_STRING, EFI_NUM_BLOCKS_STRING, Number++, Value);\r
\r
if (Status == EFI_SUCCESS) {\r
//\r
//\r
// Read files\r
//\r
+ Number = 0;\r
for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_FV; Index++) {\r
+ if (FvInfo->FvFiles[Index][0] != '\0') {\r
+ continue;\r
+ }\r
//\r
// Read the number of blocks\r
//\r
- Status = FindToken (InfFile, FILES_SECTION_STRING, EFI_FILE_NAME_STRING, Index, Value);\r
+ Status = FindToken (InfFile, FILES_SECTION_STRING, EFI_FILE_NAME_STRING, Number++, Value);\r
\r
if (Status == EFI_SUCCESS) {\r
//\r
if (Index == 0) {\r
Warning (NULL, 0, 0, "FV components are not specified.", NULL);\r
}\r
- //\r
- // Compute size for easy access later\r
- //\r
- FvInfo->Size = 0;\r
- for (Index = 0; FvInfo->FvBlocks[Index].NumBlocks; Index++) {\r
- FvInfo->Size += FvInfo->FvBlocks[Index].NumBlocks * FvInfo->FvBlocks[Index].Length;\r
- }\r
\r
return EFI_SUCCESS;\r
}\r
EFI_STATUS Status;\r
MEMORY_FILE InfMemoryFile;\r
MEMORY_FILE FvImageMemoryFile;\r
- FV_INFO FvInfo;\r
UINTN Index;\r
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
EFI_FFS_FILE_HEADER *VtfFileImage;\r
FvBufferHeader = NULL;\r
FvFile = NULL;\r
FvMapFile = NULL;\r
- //\r
- // Check for invalid parameter\r
- //\r
- if (InfFileImage == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Initialize file structures\r
- //\r
- InfMemoryFile.FileImage = InfFileImage;\r
- InfMemoryFile.CurrentFilePointer = InfFileImage;\r
- InfMemoryFile.Eof = InfFileImage + InfFileSize;\r
\r
- //\r
- // Parse the FV inf file for header information\r
- //\r
- Status = ParseFvInf (&InfMemoryFile, &FvInfo);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 0003, "Error parsing file", "the input INF file.");\r
- return Status;\r
+ if (InfFileImage != NULL) {\r
+ //\r
+ // Initialize file structures\r
+ //\r
+ InfMemoryFile.FileImage = InfFileImage;\r
+ InfMemoryFile.CurrentFilePointer = InfFileImage;\r
+ InfMemoryFile.Eof = InfFileImage + InfFileSize;\r
+ \r
+ //\r
+ // Parse the FV inf file for header information\r
+ //\r
+ Status = ParseFvInf (&InfMemoryFile, &gFvDataInfo);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 0003, "Error parsing file", "the input INF file.");\r
+ return Status;\r
+ }\r
}\r
\r
//\r
// Update the file name return values\r
//\r
- if (FvFileName == NULL && FvInfo.FvName[0] != '\0') {\r
- FvFileName = FvInfo.FvName;\r
+ if (FvFileName == NULL && gFvDataInfo.FvName[0] != '\0') {\r
+ FvFileName = gFvDataInfo.FvName;\r
}\r
\r
if (FvFileName == NULL) {\r
return EFI_ABORTED;\r
}\r
\r
+ if (gFvDataInfo.FvBlocks[0].Length == 0) {\r
+ Error (NULL, 0, 1001, "Missing required argument", "Block Size");\r
+ return EFI_ABORTED;\r
+ }\r
+ \r
//\r
// FvMap file to log the function address of all modules in one Fvimage\r
//\r
strcat (FvMapName, ".map");\r
}\r
VerboseMsg ("FV Map file name is %s", FvMapName);\r
-\r
- FvMapFile = fopen (FvMapName, "w");\r
- if (FvMapFile == NULL) {\r
- Error (NULL, 0, 0001, "Error opening file", FvMapName);\r
- return EFI_ABORTED;\r
- }\r
\r
//\r
// Update FvImage Base Address, XipBase not same to BtBase, RtBase address.\r
//\r
if (XipBaseAddress != 0) {\r
- FvInfo.BaseAddress = XipBaseAddress;\r
+ gFvDataInfo.BaseAddress = XipBaseAddress;\r
}\r
if (*BtBaseAddress != 0) {\r
- FvInfo.BootBaseAddress = *BtBaseAddress;\r
+ gFvDataInfo.BootBaseAddress = *BtBaseAddress;\r
}\r
if (*RtBaseAddress != 0) {\r
- FvInfo.RuntimeBaseAddress = *RtBaseAddress;\r
+ gFvDataInfo.RuntimeBaseAddress = *RtBaseAddress;\r
}\r
\r
//\r
// Calculate the FV size and Update Fv Size based on the actual FFS files.\r
- // And Update FvInfo data.\r
+ // And Update gFvDataInfo data.\r
//\r
- Status = CalculateFvSize (&FvInfo);\r
+ Status = CalculateFvSize (&gFvDataInfo);\r
if (EFI_ERROR (Status)) {\r
return Status; \r
}\r
- VerboseMsg ("the generated FV image size is %d bytes", FvInfo.Size);\r
+ VerboseMsg ("the generated FV image size is %d bytes", gFvDataInfo.Size);\r
\r
//\r
// support fv image and empty fv image\r
//\r
- FvImageSize = FvInfo.Size;\r
+ FvImageSize = gFvDataInfo.Size;\r
\r
//\r
// Allocate the FV, assure FvImage Header 8 byte alignment\r
//\r
// Initialize the FV to the erase polarity\r
//\r
- if (FvInfo.FvAttributes & EFI_FVB2_ERASE_POLARITY) {\r
+ if (gFvDataInfo.FvAttributes == 0) {\r
+ //\r
+ // Set Default Fv Attribute \r
+ //\r
+ gFvDataInfo.FvAttributes = FV_DEFAULT_ATTRIBUTE;\r
+ }\r
+ if (gFvDataInfo.FvAttributes & EFI_FVB2_ERASE_POLARITY) {\r
memset (FvImage, -1, FvImageSize);\r
} else {\r
memset (FvImage, 0, FvImageSize);\r
//\r
// Copy the FFS GUID\r
//\r
- memcpy (&FvHeader->FileSystemGuid, &FvInfo.FvGuid, sizeof (EFI_GUID));\r
+ memcpy (&FvHeader->FileSystemGuid, &gFvDataInfo.FvGuid, sizeof (EFI_GUID));\r
\r
FvHeader->FvLength = FvImageSize;\r
FvHeader->Signature = EFI_FVH_SIGNATURE;\r
- FvHeader->Attributes = FvInfo.FvAttributes;\r
+ FvHeader->Attributes = gFvDataInfo.FvAttributes;\r
FvHeader->Revision = EFI_FVH_REVISION;\r
FvHeader->ExtHeaderOffset = 0;\r
FvHeader->Reserved[0] = 0;\r
//\r
// Copy firmware block map\r
//\r
- for (Index = 0; FvInfo.FvBlocks[Index].Length != 0; Index++) {\r
- FvHeader->BlockMap[Index].NumBlocks = FvInfo.FvBlocks[Index].NumBlocks;\r
- FvHeader->BlockMap[Index].Length = FvInfo.FvBlocks[Index].Length;\r
+ for (Index = 0; gFvDataInfo.FvBlocks[Index].Length != 0; Index++) {\r
+ FvHeader->BlockMap[Index].NumBlocks = gFvDataInfo.FvBlocks[Index].NumBlocks;\r
+ FvHeader->BlockMap[Index].Length = gFvDataInfo.FvBlocks[Index].Length;\r
}\r
\r
//\r
//\r
// If there is no FFS file, generate one empty FV\r
//\r
- if (FvInfo.FvFiles[0][0] == 0) {\r
+ if (gFvDataInfo.FvFiles[0][0] == 0) {\r
goto WriteFile;\r
}\r
\r
//\r
VtfFileImage = (EFI_FFS_FILE_HEADER *) FvImageMemoryFile.Eof;\r
\r
+ //\r
+ // Open FvMap file\r
+ //\r
+ FvMapFile = fopen (FvMapName, "w");\r
+ if (FvMapFile == NULL) {\r
+ Error (NULL, 0, 0001, "Error opening file", FvMapName);\r
+ return EFI_ABORTED;\r
+ }\r
+\r
//\r
// Add files to FV\r
//\r
- for (Index = 0; FvInfo.FvFiles[Index][0] != 0; Index++) {\r
+ for (Index = 0; gFvDataInfo.FvFiles[Index][0] != 0; Index++) {\r
//\r
// Add the file\r
//\r
- Status = AddFile (&FvImageMemoryFile, &FvInfo, Index, &VtfFileImage, FvMapFile);\r
+ Status = AddFile (&FvImageMemoryFile, &gFvDataInfo, Index, &VtfFileImage, FvMapFile);\r
\r
//\r
// Exit if error detected while adding the file\r
// reset vector. If the PEI Core is found, the VTF file will probably get \r
// corrupted by updating the entry point. \r
//\r
- if ((FvInfo.BaseAddress + FvInfo.Size) == FV_IMAGES_TOP_ADDRESS) { \r
- Status = UpdateResetVector (&FvImageMemoryFile, &FvInfo, VtfFileImage);\r
+ if ((gFvDataInfo.BaseAddress + gFvDataInfo.Size) == FV_IMAGES_TOP_ADDRESS) { \r
+ Status = UpdateResetVector (&FvImageMemoryFile, &gFvDataInfo, VtfFileImage);\r
if (EFI_ERROR(Status)) { \r
Error (NULL, 0, 3000, "Invalid", "Could not update the reset vector.");\r
goto Finish; \r
//\r
// Update BootAddress and RuntimeAddress\r
//\r
- *BtBaseAddress = FvInfo.BootBaseAddress;\r
- *RtBaseAddress = FvInfo.RuntimeBaseAddress;\r
+ *BtBaseAddress = gFvDataInfo.BootBaseAddress;\r
+ *RtBaseAddress = gFvDataInfo.RuntimeBaseAddress;\r
\r
return Status;\r
}\r
VtfFileFlag = FALSE;\r
fpin = NULL;\r
Index = 0;\r
+\r
+ //\r
+ // Compute size for easy access later\r
+ //\r
+ FvInfoPtr->Size = 0;\r
+ for (Index = 0; FvInfoPtr->FvBlocks[Index].NumBlocks > 0 && FvInfoPtr->FvBlocks[Index].Length > 0; Index++) {\r
+ FvInfoPtr->Size += FvInfoPtr->FvBlocks[Index].NumBlocks * FvInfoPtr->FvBlocks[Index].Length;\r
+ }\r
+ \r
+ //\r
+ // Caculate the required sizes for all FFS files.\r
+ //\r
CurrentOffset = sizeof (EFI_FIRMWARE_VOLUME_HEADER);\r
\r
for (Index = 1;; Index ++) {\r
CurrentOffset += sizeof (EFI_FV_BLOCK_MAP_ENTRY);\r
- if (FvInfoPtr->FvBlocks[Index].NumBlocks == 0 && FvInfoPtr->FvBlocks[Index].Length == 0) {\r
+ if (FvInfoPtr->FvBlocks[Index].NumBlocks == 0 || FvInfoPtr->FvBlocks[Index].Length == 0) {\r
break;\r
}\r
}\r
\r
DebugMsg (NULL, 0, 9, "FvImage size", "The caculated fv image size is 0x%x and the current set fv image size is 0x%x", CurrentOffset, FvInfoPtr->Size);\r
\r
- if (FvInfoPtr->Size < CurrentOffset) { \r
+ if (FvInfoPtr->Size == 0) { \r
//\r
// Update FvInfo data\r
//\r
FvInfoPtr->Size = FvInfoPtr->FvBlocks[0].NumBlocks * FvInfoPtr->FvBlocks[0].Length;\r
FvInfoPtr->FvBlocks[1].NumBlocks = 0;\r
FvInfoPtr->FvBlocks[1].Length = 0;\r
+ } else if (FvInfoPtr->Size < CurrentOffset) {\r
+ //\r
+ // Not invalid\r
+ //\r
+ Error (NULL, 0, 3000, "Invalid", "the required fv image size 0x%x exceeds the set fv image size 0x%x", CurrentOffset, FvInfoPtr->Size);\r
+ return EFI_INVALID_PARAMETER;\r
}\r
+ \r
+ //\r
+ // Set Fv Size Information\r
+ //\r
+ mFvTotalSize = FvInfoPtr->Size;\r
+ mFvTakenSize = CurrentOffset;\r
\r
return EFI_SUCCESS;\r
}\r
FILE *PeFile;\r
UINT8 *PeFileBuffer;\r
UINT32 PeFileSize;\r
+ CHAR8 *PdbPointer;\r
\r
Index = 0; \r
MemoryImagePointer = NULL;\r
Cptr = NULL;\r
PeFile = NULL;\r
PeFileBuffer = NULL;\r
+\r
//\r
// Check XipAddress, BootAddress and RuntimeAddress\r
//\r
default:\r
return EFI_SUCCESS;\r
}\r
-\r
//\r
// Rebase each PE32 section\r
//\r
Status = EFI_SUCCESS;\r
for (Index = 1;; Index++) {\r
+ //\r
+ // Init Value\r
+ //\r
+ NewPe32BaseAddress = 0;\r
+ \r
+ //\r
+ // Find Pe Image\r
+ //\r
Status = GetSectionByType (FfsFile, EFI_SECTION_PE32, Index, &CurrentPe32Section);\r
if (EFI_ERROR (Status)) {\r
break;\r
Error (NULL, 0, 3000, "Invalid", "GetImageInfo() call failed on rebase %s.", FileName);\r
return Status;\r
}\r
+ \r
+ //\r
+ // Get File PdbPointer\r
+ //\r
+ PdbPointer = PeCoffLoaderGetPdbPointer (ImageContext.Handle);\r
\r
//\r
// Get PeHeader pointer\r
}\r
PeFile = fopen (PeFileName, "rb");\r
if (PeFile == NULL) {\r
- Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);\r
- return EFI_ABORTED;\r
+ Warning (NULL, 0, 0, "Invalid", "The file %s has no .reloc section.", FileName);\r
+ //Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);\r
+ //return EFI_ABORTED;\r
+ break;\r
}\r
//\r
// Get the file size\r
case EFI_FV_FILETYPE_DXE_CORE:\r
if ((Flags & REBASE_BOOTTIME_FILE) == 0) {\r
//\r
- // Skip DXE core, DxeCore only contain one PE image.\r
+ // Skip DxeCore Driver\r
//\r
goto WritePeMap;\r
}\r
//\r
return EFI_SUCCESS;\r
}\r
-\r
+ \r
//\r
- // Load and Relocate Image Data\r
+ // Relocation exist and rebase\r
//\r
- MemoryImagePointer = (UINT8 *) malloc ((UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
- if (MemoryImagePointer == NULL) {\r
- Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
- ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~(ImageContext.SectionAlignment - 1));\r
- \r
- Status = PeCoffLoaderLoadImage (&ImageContext);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 3000, "Invalid", "LocateImage() call failed on rebase of %s", FileName);\r
- free ((VOID *) MemoryImagePointer);\r
- return Status;\r
- }\r
- \r
- ImageContext.DestinationAddress = NewPe32BaseAddress;\r
- Status = PeCoffLoaderRelocateImage (&ImageContext);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed on rebase of %s", FileName);\r
+ if (!ImageContext.RelocationsStripped) { \r
+ //\r
+ // Load and Relocate Image Data\r
+ //\r
+ MemoryImagePointer = (UINT8 *) malloc ((UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
+ if (MemoryImagePointer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
+ ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~(ImageContext.SectionAlignment - 1));\r
+ \r
+ Status = PeCoffLoaderLoadImage (&ImageContext);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 3000, "Invalid", "LocateImage() call failed on rebase of %s", FileName);\r
+ free ((VOID *) MemoryImagePointer);\r
+ return Status;\r
+ }\r
+ \r
+ ImageContext.DestinationAddress = NewPe32BaseAddress;\r
+ Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed on rebase of %s", FileName);\r
+ free ((VOID *) MemoryImagePointer);\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Copy Relocated data to raw image file.\r
+ //\r
+ SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (\r
+ (UINTN) PeHdr +\r
+ sizeof (UINT32) + \r
+ sizeof (EFI_IMAGE_FILE_HEADER) + \r
+ PeHdr->FileHeader.SizeOfOptionalHeader\r
+ );\r
+ \r
+ for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index ++, SectionHeader ++) {\r
+ CopyMem (\r
+ (UINT8 *) CurrentPe32Section.Pe32Section + sizeof (EFI_COMMON_SECTION_HEADER) + SectionHeader->PointerToRawData, \r
+ (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), \r
+ SectionHeader->SizeOfRawData\r
+ );\r
+ }\r
+ \r
free ((VOID *) MemoryImagePointer);\r
- return Status;\r
+ MemoryImagePointer = NULL;\r
+ if (PeFileBuffer != NULL) {\r
+ free (PeFileBuffer);\r
+ PeFileBuffer = NULL;\r
+ }\r
}\r
-\r
+ \r
//\r
- // Copy Relocated data to raw image file.\r
+ // Update Image Base Address\r
//\r
if (PeHdr->FileHeader.Machine == EFI_IMAGE_MACHINE_IA32) {\r
Optional32 = (EFI_IMAGE_OPTIONAL_HEADER32 *) &(PeHdr->OptionalHeader);\r
(UINT32) PeHdr->FileHeader.Machine,\r
FileName\r
);\r
- free ((VOID *) MemoryImagePointer);\r
return EFI_ABORTED;\r
}\r
\r
- SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (\r
- (UINTN) PeHdr +\r
- sizeof (UINT32) + \r
- sizeof (EFI_IMAGE_FILE_HEADER) + \r
- PeHdr->FileHeader.SizeOfOptionalHeader\r
- );\r
- \r
- for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index ++, SectionHeader ++) {\r
- CopyMem (\r
- (UINT8 *) CurrentPe32Section.Pe32Section + sizeof (EFI_COMMON_SECTION_HEADER) + SectionHeader->PointerToRawData, \r
- (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), \r
- SectionHeader->SizeOfRawData\r
- );\r
- }\r
-\r
- free ((VOID *) MemoryImagePointer);\r
- MemoryImagePointer = NULL;\r
- if (PeFileBuffer != NULL) {\r
- free (PeFileBuffer);\r
- PeFileBuffer = NULL;\r
- }\r
-\r
//\r
// Update BASE address by add one page size.\r
//\r
// Get this module function address from ModulePeMapFile and add them into FvMap file\r
//\r
WritePeMap:\r
- WriteMapFile (FvMapFile, FileName, ImageContext.DestinationAddress, PeHdr->OptionalHeader.AddressOfEntryPoint, 0);\r
+ //\r
+ // Default use FileName as map file path\r
+ //\r
+ if (PdbPointer == NULL) {\r
+ PdbPointer = FileName;\r
+ }\r
+ WriteMapFile (FvMapFile, PdbPointer, (EFI_GUID *) FfsFile, NewPe32BaseAddress, PeHdr->OptionalHeader.AddressOfEntryPoint, 0);\r
}\r
\r
if (FfsFile->Type != EFI_FV_FILETYPE_SECURITY_CORE &&\r
// Now process TE sections\r
//\r
for (Index = 1;; Index++) {\r
+ NewPe32BaseAddress = 0;\r
+ \r
+ //\r
+ // Find Te Image\r
+ //\r
Status = GetSectionByType (FfsFile, EFI_SECTION_TE, Index, &CurrentPe32Section);\r
if (EFI_ERROR (Status)) {\r
break;\r
}\r
-\r
+ \r
//\r
// Calculate the TE base address, the FFS file base plus the offset of the TE section less the size stripped off\r
// by GenTEImage\r
memset (&ImageContext, 0, sizeof (ImageContext));\r
ImageContext.Handle = (VOID *) TEImageHeader;\r
ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;\r
-\r
Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
-\r
if (EFI_ERROR (Status)) {\r
Error (NULL, 0, 3000, "Invalid", "GetImageInfo() call failed on rebase of TE image %s", FileName);\r
return Status;\r
}\r
+\r
+ //\r
+ // Get File PdbPointer\r
+ //\r
+ PdbPointer = PeCoffLoaderGetPdbPointer (ImageContext.Handle);\r
\r
if ((Flags & REBASE_XIP_FILE) == 0) {\r
//\r
//\r
goto WriteTeMap;\r
}\r
+\r
+ //\r
+ // Set new rebased address.\r
+ //\r
+ NewPe32BaseAddress = XipBase + (UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) \\r
+ - TEImageHeader->StrippedSize - (UINTN) FfsFile;\r
+\r
//\r
// if reloc is stripped, try to get the original efi image to get reloc info.\r
//\r
while (*Cptr != '.') {\r
Cptr --;\r
}\r
+\r
if (*Cptr != '.') {\r
Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);\r
return EFI_ABORTED;\r
*(Cptr + 3) = 'i';\r
*(Cptr + 4) = '\0';\r
}\r
+\r
PeFile = fopen (PeFileName, "rb");\r
if (PeFile == NULL) {\r
- Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);\r
- return EFI_ABORTED;\r
+ Warning (NULL, 0, 0, "Invalid", "The file %s has no .reloc section.", FileName);\r
+ //Error (NULL, 0, 3000, "Invalid", "The file %s has no .reloc section.", FileName);\r
+ //return EFI_ABORTED;\r
+ } else {\r
+ //\r
+ // Get the file size\r
+ //\r
+ PeFileSize = _filelength (fileno (PeFile));\r
+ PeFileBuffer = (UINT8 *) malloc (PeFileSize);\r
+ if (PeFileBuffer == NULL) {\r
+ Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ //\r
+ // Read Pe File\r
+ //\r
+ fread (PeFileBuffer, sizeof (UINT8), PeFileSize, PeFile);\r
+ //\r
+ // close file\r
+ //\r
+ fclose (PeFile);\r
+ //\r
+ // Append reloc section into TeImage\r
+ //\r
+ ImageContext.Handle = PeFileBuffer;\r
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 3000, "Invalid", "GetImageInfo() call failed on rebase of TE image %s", FileName);\r
+ return Status;\r
+ }\r
+ ImageContext.RelocationsStripped = FALSE;\r
}\r
+ }\r
+\r
+ //\r
+ // Relocation exist and rebase\r
+ //\r
+ if (!ImageContext.RelocationsStripped) {\r
//\r
- // Get the file size\r
+ // Load and Relocate Image Data\r
//\r
- PeFileSize = _filelength (fileno (PeFile));\r
- PeFileBuffer = (UINT8 *) malloc (PeFileSize);\r
- if (PeFileBuffer == NULL) {\r
+ MemoryImagePointer = (UINT8 *) malloc ((UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
+ if (MemoryImagePointer == NULL) {\r
Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
+ memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
+ ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~(ImageContext.SectionAlignment - 1));\r
+ \r
+ Status = PeCoffLoaderLoadImage (&ImageContext);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 3000, "Invalid", "LocateImage() call failed on rebase of %s", FileName);\r
+ free ((VOID *) MemoryImagePointer);\r
+ return Status;\r
+ }\r
//\r
- // Read Pe File\r
- //\r
- fread (PeFileBuffer, sizeof (UINT8), PeFileSize, PeFile);\r
+ // Reloacate TeImage\r
+ // \r
+ ImageContext.DestinationAddress = NewPe32BaseAddress;\r
+ Status = PeCoffLoaderRelocateImage (&ImageContext);\r
+ if (EFI_ERROR (Status)) {\r
+ Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed on rebase of TE image %s", FileName);\r
+ free ((VOID *) MemoryImagePointer);\r
+ return Status;\r
+ }\r
+ \r
//\r
- // close file\r
+ // Copy the relocated image into raw image file.\r
//\r
- fclose (PeFile);\r
+ SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (TEImageHeader + 1);\r
+ for (Index = 0; Index < TEImageHeader->NumberOfSections; Index ++, SectionHeader ++) {\r
+ if (!ImageContext.IsTeImage) {\r
+ CopyMem (\r
+ (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData, \r
+ (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), \r
+ SectionHeader->SizeOfRawData\r
+ );\r
+ } else {\r
+ CopyMem (\r
+ (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData, \r
+ (VOID*) (UINTN) (ImageContext.ImageAddress + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->VirtualAddress), \r
+ SectionHeader->SizeOfRawData\r
+ );\r
+ }\r
+ }\r
+ \r
//\r
- // Append reloc section into TeImage\r
+ // Free the allocated memory resource\r
//\r
- ImageContext.Handle = PeFileBuffer;\r
- Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 3000, "Invalid", "GetImageInfo() call failed on rebase of TE image %s", FileName);\r
- return Status;\r
- }\r
- ImageContext.RelocationsStripped = FALSE;\r
- }\r
-\r
- //\r
- // Load and Relocate Image Data\r
- //\r
- MemoryImagePointer = (UINT8 *) malloc ((UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
- if (MemoryImagePointer == NULL) {\r
- Error (NULL, 0, 4001, "Resource", "memory cannot be allocated on rebase of %s", FileName);\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
- ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~(ImageContext.SectionAlignment - 1));\r
-\r
- Status = PeCoffLoaderLoadImage (&ImageContext);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 3000, "Invalid", "LocateImage() call failed on rebase of %s", FileName);\r
free ((VOID *) MemoryImagePointer);\r
- return Status;\r
- }\r
- //\r
- // Reloacate TeImage\r
- // \r
- ImageContext.DestinationAddress = XipBase + (UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) \\r
- - TEImageHeader->StrippedSize - (UINTN) FfsFile;\r
- Status = PeCoffLoaderRelocateImage (&ImageContext);\r
- if (EFI_ERROR (Status)) {\r
- Error (NULL, 0, 3000, "Invalid", "RelocateImage() call failed on rebase of TE image %s", FileName);\r
- free ((VOID *) MemoryImagePointer);\r
- return Status;\r
- }\r
- \r
- //\r
- // Copy the relocated image into raw image file.\r
- //\r
- TEImageHeader->ImageBase = ImageContext.DestinationAddress;\r
- SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (TEImageHeader + 1);\r
- for (Index = 0; Index < TEImageHeader->NumberOfSections; Index ++, SectionHeader ++) {\r
- if (!ImageContext.IsTeImage) {\r
- CopyMem (\r
- (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData, \r
- (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), \r
- SectionHeader->SizeOfRawData\r
- );\r
- } else {\r
- CopyMem (\r
- (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData, \r
- (VOID*) (UINTN) (ImageContext.ImageAddress + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->VirtualAddress), \r
- SectionHeader->SizeOfRawData\r
- );\r
+ MemoryImagePointer = NULL;\r
+ if (PeFileBuffer != NULL) {\r
+ free (PeFileBuffer);\r
+ PeFileBuffer = NULL;\r
}\r
}\r
\r
//\r
- // Free the allocated memory resource\r
+ // Update Image Base Address\r
//\r
- free ((VOID *) MemoryImagePointer);\r
- MemoryImagePointer = NULL;\r
- if (PeFileBuffer != NULL) {\r
- free (PeFileBuffer);\r
- PeFileBuffer = NULL;\r
- }\r
+ TEImageHeader->ImageBase = NewPe32BaseAddress;\r
\r
//\r
// Now update file checksum\r
// Get this module function address from ModulePeMapFile and add them into FvMap file\r
//\r
WriteTeMap:\r
+ //\r
+ // Default use FileName as map file path\r
+ //\r
+ if (PdbPointer == NULL) {\r
+ PdbPointer = FileName;\r
+ }\r
WriteMapFile (\r
FvMapFile, \r
- FileName, \r
- ImageContext.DestinationAddress, \r
+ PdbPointer, \r
+ (EFI_GUID *) FfsFile,\r
+ NewPe32BaseAddress, \r
TEImageHeader->AddressOfEntryPoint, \r
TEImageHeader->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER)\r
- ); \r
+ );\r
}\r
\r
return EFI_SUCCESS;\r
EFI_STATUS\r
WriteMapFile (\r
IN OUT FILE *FvMapFile,\r
- IN CHAR8 *FileName, \r
+ IN CHAR8 *FileName,\r
+ IN EFI_GUID *FileGuidPtr, \r
IN EFI_PHYSICAL_ADDRESS ImageBaseAddress,\r
IN UINT32 AddressOfEntryPoint,\r
IN UINT32 Offset\r
{\r
CHAR8 PeMapFileName [_MAX_PATH];\r
CHAR8 *Cptr;\r
- CHAR8 *FileGuidName;\r
- EFI_GUID FileGuidValue;\r
+ CHAR8 FileGuidName [MAX_LINE_LEN];\r
FILE *PeMapFile;\r
CHAR8 Line [MAX_LINE_LEN];\r
CHAR8 KeyWord [MAX_LINE_LEN];\r
// Init local variable\r
//\r
FunctionType = 0;\r
+ //\r
+ // Print FileGuid to string buffer. \r
+ //\r
+ PrintGuidToBuffer (FileGuidPtr, FileGuidName, MAX_LINE_LEN, TRUE);\r
\r
//\r
// Construct Map file Name \r
//\r
strcpy (PeMapFileName, FileName);\r
+ \r
+ //\r
+ // Change '\\' to '/', unified path format.\r
+ //\r
+ Cptr = PeMapFileName;\r
+ while (*Cptr != '\0') {\r
+ if (*Cptr == '\\') {\r
+ *Cptr = FILE_SEP_CHAR;\r
+ }\r
+ Cptr ++;\r
+ }\r
+ \r
+ //\r
+ // Get Map file\r
+ // \r
Cptr = PeMapFileName + strlen (PeMapFileName);\r
while (*Cptr != '.') {\r
Cptr --;\r
// fprintf (stdout, "can't open %s file to reading\n", PeMapFileName);\r
return EFI_ABORTED;\r
}\r
- //\r
- // Get Module Guid from FileName\r
- //\r
- *Cptr = '\0';\r
- while ((*Cptr != FILE_SEP_CHAR) && (Cptr >= PeMapFileName)) {\r
- Cptr --;\r
- }\r
- if (*Cptr == FILE_SEP_CHAR) {\r
- FileGuidName = Cptr + 1;\r
- if (StringToGuid (FileGuidName, &FileGuidValue) != EFI_SUCCESS) {\r
- FileGuidName = NULL;\r
- }\r
- }\r
+ VerboseMsg ("The map file is %s", PeMapFileName);\r
+ \r
//\r
// Output Functions information into Fv Map file\r
//\r
fprintf (FvMapFile, "BaseAddress=%08lx, ", ImageBaseAddress + Offset);\r
}\r
fprintf (FvMapFile, "EntryPoint=%08lx, ", ImageBaseAddress + AddressOfEntryPoint);\r
- if (FileGuidName != NULL) {\r
- fprintf (FvMapFile, "GUID=%s", FileGuidName);\r
- }\r
+ fprintf (FvMapFile, "GUID=%s", FileGuidName);\r
fprintf (FvMapFile, ")\n\n");\r
\r
while (fgets (Line, MAX_LINE_LEN, PeMapFile) != NULL) {\r
{\r
CHAR8 Value[_MAX_PATH];\r
UINT64 Value64;\r
- UINTN Index;\r
+ UINTN Index, Number;\r
EFI_STATUS Status;\r
\r
//\r
// Initialize Cap info\r
//\r
- memset (CapInfo, 0, sizeof (CAP_INFO));\r
+ // memset (CapInfo, 0, sizeof (CAP_INFO));\r
+ //\r
\r
//\r
// Read the Capsule Guid\r
return EFI_ABORTED;\r
}\r
DebugMsg (NULL, 0, 9, "Capsule Guid", "%s = %s", EFI_CAPSULE_GUID_STRING, Value);\r
- } else {\r
- Error (NULL, 0, 2001, "Missing required argument", EFI_CAPSULE_GUID_STRING);\r
- return EFI_ABORTED;\r
}\r
\r
//\r
//\r
// Read the Capsule FileImage\r
//\r
+ Number = 0;\r
for (Index = 0; Index < MAX_NUMBER_OF_FILES_IN_CAP; Index++) {\r
+ if (CapInfo->CapFiles[Index][0] != '\0') {\r
+ continue;\r
+ }\r
//\r
// Read the capsule file name\r
//\r
- Status = FindToken (InfFile, FILES_SECTION_STRING, EFI_FILE_NAME_STRING, Index, Value);\r
+ Status = FindToken (InfFile, FILES_SECTION_STRING, EFI_FILE_NAME_STRING, Number++, Value);\r
\r
if (Status == EFI_SUCCESS) {\r
//\r
UINT32 Index;\r
FILE *fpin, *fpout;\r
EFI_STATUS Status;\r
- CAP_INFO CapInfo;\r
-\r
- //\r
- // Initialize file structures\r
- //\r
- InfMemoryFile.FileImage = InfFileImage;\r
- InfMemoryFile.CurrentFilePointer = InfFileImage;\r
- InfMemoryFile.Eof = InfFileImage + InfFileSize;\r
-\r
- //\r
- // Parse the Cap inf file for header information\r
- //\r
- Status = ParseCapInf (&InfMemoryFile, &CapInfo);\r
- if (Status != EFI_SUCCESS) {\r
- return Status;\r
+ \r
+ if (InfFileImage != NULL) {\r
+ //\r
+ // Initialize file structures\r
+ //\r
+ InfMemoryFile.FileImage = InfFileImage;\r
+ InfMemoryFile.CurrentFilePointer = InfFileImage;\r
+ InfMemoryFile.Eof = InfFileImage + InfFileSize;\r
+ \r
+ //\r
+ // Parse the Cap inf file for header information\r
+ //\r
+ Status = ParseCapInf (&InfMemoryFile, &gCapDataInfo);\r
+ if (Status != EFI_SUCCESS) {\r
+ return Status;\r
+ }\r
}\r
\r
- if (CapInfo.HeaderSize == 0) {\r
- CapInfo.HeaderSize = sizeof (EFI_CAPSULE_HEADER);\r
+ if (gCapDataInfo.HeaderSize == 0) {\r
+ //\r
+ // make header size align 16 bytes.\r
+ //\r
+ gCapDataInfo.HeaderSize = sizeof (EFI_CAPSULE_HEADER);\r
+ gCapDataInfo.HeaderSize = (gCapDataInfo.HeaderSize + 0xF) & ~0xF;\r
}\r
\r
- if (CapInfo.HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {\r
+ if (gCapDataInfo.HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {\r
Error (NULL, 0, 2000, "Invalid parameter", "The specified HeaderSize cannot be less than the size of EFI_CAPSULE_HEADER.");\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (CapFileName == NULL && CapInfo.CapName[0] != '\0') {\r
- CapFileName = CapInfo.CapName;\r
+ if (CapFileName == NULL && gCapDataInfo.CapName[0] != '\0') {\r
+ CapFileName = gCapDataInfo.CapName;\r
}\r
\r
if (CapFileName == NULL) {\r
Error (NULL, 0, 2001, "Missing required argument", "Output Capsule file name");\r
return EFI_INVALID_PARAMETER;\r
}\r
-\r
+ \r
+ //\r
+ // Set Default Capsule Guid value\r
+ //\r
+ if (CompareGuid (&gCapDataInfo.CapGuid, &mZeroGuid) == 0) {\r
+ memcpy (&gCapDataInfo.CapGuid, &mDefaultCapsuleGuid, sizeof (EFI_GUID));\r
+ }\r
//\r
// Calculate the size of capsule image.\r
//\r
Index = 0;\r
FileSize = 0;\r
- CapSize = CapInfo.HeaderSize;\r
- while (CapInfo.CapFiles [Index][0] != '\0') {\r
- fpin = fopen (CapInfo.CapFiles[Index], "rb");\r
+ CapSize = gCapDataInfo.HeaderSize;\r
+ while (gCapDataInfo.CapFiles [Index][0] != '\0') {\r
+ fpin = fopen (gCapDataInfo.CapFiles[Index], "rb");\r
if (fpin == NULL) {\r
- Error (NULL, 0, 0001, "Error opening file", CapInfo.CapFiles[Index]);\r
+ Error (NULL, 0, 0001, "Error opening file", gCapDataInfo.CapFiles[Index]);\r
return EFI_ABORTED;\r
}\r
FileSize = _filelength (fileno (fpin));\r
//\r
// Initialize the capsule header to zero\r
//\r
- memset (CapBuffer, 0, CapInfo.HeaderSize);\r
+ memset (CapBuffer, 0, gCapDataInfo.HeaderSize);\r
\r
//\r
// create capsule header and get capsule body\r
//\r
CapsuleHeader = (EFI_CAPSULE_HEADER *) CapBuffer;\r
- memcpy (&CapsuleHeader->CapsuleGuid, &CapInfo.CapGuid, sizeof (EFI_GUID));\r
- CapsuleHeader->HeaderSize = CapInfo.HeaderSize;\r
- CapsuleHeader->Flags = CapInfo.Flags;\r
+ memcpy (&CapsuleHeader->CapsuleGuid, &gCapDataInfo.CapGuid, sizeof (EFI_GUID));\r
+ CapsuleHeader->HeaderSize = gCapDataInfo.HeaderSize;\r
+ CapsuleHeader->Flags = gCapDataInfo.Flags;\r
CapsuleHeader->CapsuleImageSize = CapSize;\r
\r
Index = 0;\r
FileSize = 0;\r
CapSize = CapsuleHeader->HeaderSize;\r
- while (CapInfo.CapFiles [Index][0] != '\0') {\r
- fpin = fopen (CapInfo.CapFiles[Index], "rb");\r
+ while (gCapDataInfo.CapFiles [Index][0] != '\0') {\r
+ fpin = fopen (gCapDataInfo.CapFiles[Index], "rb");\r
if (fpin == NULL) {\r
- Error (NULL, 0, 0001, "Error opening file", CapInfo.CapFiles[Index]);\r
+ Error (NULL, 0, 0001, "Error opening file", gCapDataInfo.CapFiles[Index]);\r
free (CapBuffer);\r
return EFI_ABORTED;\r
}\r