/** @file
Copyright (c) 1999 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Abstract:
Utility program to create an EFI option ROM image from binary and
EFI PE32 files.
**/
#include "EfiUtilityMsgs.h"
#include "ParseInf.h"
#include "EfiRom.h"
int
main (
int Argc,
char *Argv[]
)
/*++
Routine Description:
Given an EFI image filename, create a ROM-able image by creating an option
ROM header and PCI data structure, filling them in, and then writing the
option ROM header + PCI data structure + EFI image out to the output file.
Arguments:
Argc - standard C main() argument count
Argv - standard C main() argument list
Returns:
0 success
non-zero otherwise
--*/
{
//
// Parse the command line arguments
//
return STATUS_ERROR;
}
SetPrintLevel(40);
SetPrintLevel(15);
}
}
//
// If dumping an image, then do that and quit
//
if ((Ptr0 = strstr ((CONST CHAR8 *) mOptions.FileList->FileName, DEFAULT_OUTPUT_EXTENSION)) != NULL) {
goto BailOut;
} else {
goto BailOut;
}
}
}
//
// Determine the output filename. Either what they specified on
// the command line, or the first input filename with a different extension.
//
if (!mOptions.OutFileName[0]) {
//
// Find the last . on the line and replace the filename extension with
// the default
//
Ext--
)
;
//
// If dot here, then insert extension here, otherwise append
//
if (*Ext != '.') {
}
}
//
// Make sure we don't have the same filename for input and output files
//
Error (NULL, 0, 1002, "Invalid input paramter", "Input and output file names must be different - %s = %s.", FList->FileName, mOptions.OutFileName);
goto BailOut;
}
}
//
// Now open our output file
//
goto BailOut;
}
//
// Process all our files
//
TotalSize = 0;
Size = 0;
}
}
} else {
Error (NULL, 0, 2000, "Invalid parameter", "File type not specified, it must be either an EFI or binary file: %s.", FList->FileName);
}
}
if (Status != STATUS_SUCCESS) {
break;
}
}
//
// Check total size
//
if (TotalSize > MAX_OPTION_ROM_SIZE) {
Error (NULL, 0, 2000, "Invalid paramter", "Option ROM image size exceeds limit of 0x%X bytes.", MAX_OPTION_ROM_SIZE);
}
if (Status == STATUS_SUCCESS) {
}
//
// Clean up our file list
//
}
}
}
return GetUtilityStatus ();
}
static
int
)
/*++
Routine Description:
Process a binary input file.
Arguments:
OutFptr - file pointer to output binary ROM image file we're creating
InFile - structure contains information on the binary file to process
Size - pointer to where to return the size added to the output file
Returns:
0 - successful
--*/
{
//
// Try to open the input file
//
return STATUS_ERROR;
}
//
// Seek to the end of the input file and get the file size. Then allocate
// a buffer to read it in to.
//
}
goto BailOut;
}
goto BailOut;
}
//
// Total size must be an even multiple of 512 bytes, and can't exceed
// the option ROM image size.
//
if (TotalSize & 0x1FF) {
}
if (TotalSize > MAX_OPTION_ROM_SIZE) {
Error (NULL, 0, 3001, "Invalid", "Option ROM image %s size exceeds limit of 0x%X bytes.", InFile->FileName, MAX_OPTION_ROM_SIZE);
goto BailOut;
}
//
// Return the size to the caller so they can keep track of the running total.
//
//
// Crude check to make sure it's a legitimate ROM image
//
goto BailOut;
}
//
// Make sure the pointer to the PCI data structure is within the size of the image.
// Then check it for valid signature.
//
goto BailOut;
}
//
// Check the header is conform to PCI2.3 or PCI3.0
//
goto BailOut;
}
} else {
//
// Default setting is PCI3.0 header
//
goto BailOut;
}
}
//
// ReSet Option Rom size
//
} else {
}
//
// If this is the last image, then set the LAST bit unless requested not
// to via the command-line -n argument. Otherwise, make sure you clear it.
//
} else {
}
} else {
} else {
}
}
ByteCheckSum = 0;
}
}
//
// Now copy the input file contents out to the output file
//
goto BailOut;
}
//
// Pad the rest of the image to make it a multiple of 512 bytes
//
while (TotalSize > 0) {
TotalSize--;
}
}
}
//
// Print the file name if errors occurred
//
if (Status != STATUS_SUCCESS) {
}
return Status;
}
static
int
)
/*++
Routine Description:
Process a PE32 EFI file.
Arguments:
OutFptr - file pointer to output binary ROM image file we're creating
InFile - structure contains information on the PE32 file to process
VendId - vendor ID as required in the option ROM header
DevId - device ID as required in the option ROM header
Size - pointer to where to return the size added to the output file
Returns:
0 - successful
--*/
{
//
// Try to open the input file
//
return STATUS_ERROR;
}
//
// Initialize our buffer pointers to null.
//
//
// Double-check the file to make sure it's what we expect it to be
//
if (Status != STATUS_SUCCESS) {
goto BailOut;
}
//
// Seek to the end of the input file and get the file size
//
//
// Get the size of the headers we're going to put in front of the image. The
// EFI header must be aligned on a 4-byte boundary, so pad accordingly.
//
if (sizeof (RomHdr) & 0x03) {
} else {
HeaderPadBytes = 0;
}
//
// For Pci3.0 to use the different data structure.
//
} else {
HeaderSize = sizeof (PCI_3_0_DATA_STRUCTURE) + HeaderPadBytes + sizeof (EFI_PCI_EXPANSION_ROM_HEADER);
}
}
//
// Allocate memory for the entire file (in case we have to compress), then
// seek back to the beginning of the file and read it into our buffer.
//
goto BailOut;
}
goto BailOut;
}
//
// Now determine the size of the final output file. It's either the header size
// plus the file's size, or the header size plus the compressed file size.
//
//
// Allocate a buffer into which we can compress the image, compress it,
// and use that size as the new size.
//
if (CompressedBuffer == NULL) {
goto BailOut;
}
if (Status != STATUS_SUCCESS) {
goto BailOut;
}
//
// Now compute the size, then swap buffer pointers.
//
}
} else {
}
//
// Total size must be an even multiple of 512 bytes
//
if (TotalSize & 0x1FF) {
}
//
// Check size
//
if (TotalSize > MAX_OPTION_ROM_SIZE) {
Error (NULL, 0, 2000, "Invalid", "Option ROM image %s size exceeds limit of 0x%X bytes.", InFile->FileName, MAX_OPTION_ROM_SIZE);
goto BailOut;
}
//
// Return the size to the caller so they can keep track of the running total.
//
//
// Now fill in the ROM header. These values come from chapter 18 of the
// EFI 1.02 specification.
//
//
// Set image as compressed or not
//
}
//
// Fill in the PCI data structure
//
} else {
}
//
// Class code and code revision from the command line (optional)
//
} else {
//
// Class code and code revision from the command line (optional)
//
}
//
// If this is the last image, then set the LAST bit unless requested not
// to via the command-line -n argument.
//
} else {
} else {
} else {
}
}
//
// Write the ROM header to the output file
//
goto BailOut;
}
//
// Write pad bytes to align the PciDs
//
while (HeaderPadBytes > 0) {
goto BailOut;
}
}
//
// Write the PCI data structure header to the output file
//
goto BailOut;
}
} else {
goto BailOut;
}
}
//
// Keep track of how many bytes left to write
//
TotalSize -= HeaderSize;
//
// Now dump the input file's contents to the output file
//
goto BailOut;
}
//
// Pad the rest of the image to make it a multiple of 512 bytes
//
while (TotalSize > 0) {
goto BailOut;
}
TotalSize--;
}
}
//
// Free up our buffers
//
}
if (CompressedBuffer != NULL) {
}
//
// Print the file name if errors occurred
//
if (Status != STATUS_SUCCESS) {
}
return Status;
}
static
int
)
/*++
Routine Description:
Given a file pointer to a supposed PE32 image file, verify that it is indeed a
PE32 image file, and then return the machine type in the supplied pointer.
Arguments:
Fptr File pointer to the already-opened PE32 file
MachineType Location to stuff the machine type of the PE32 file. This is needed
because the image may be Itanium-based, IA32, or EBC.
Returns:
0 success
non-zero otherwise
--*/
{
//
// Position to the start of the file
//
//
// Read the DOS header
//
return STATUS_ERROR;
}
//
// Check the magic number (0x5A4D)
//
Error (NULL, 0, 2000, "Invalid parameter", "Input file does not appear to be a PE32 image (magic number)!");
return STATUS_ERROR;
}
//
// Position into the file and check the PE signature
//
//
// Read PE headers
//
return STATUS_ERROR;
}
//
// Check the PE signature in the header "PE\0\0"
//
Error (NULL, 0, 2000, "Invalid parameter", "Input file does not appear to be a PE32 image (signature)!");
return STATUS_ERROR;
}
} else {
return STATUS_ERROR;
}
}
//
// File was successfully identified as a PE32
//
return STATUS_SUCCESS;
}
static
int
int Argc,
char *Argv[],
)
/*++
Routine Description:
parse the command-line options and check their validity.
Arguments:
Argc - standard C main() argument count
Argv[] - standard C main() argument list
Options - pointer to a structure to store the options in
Returns:
STATUS_SUCCESS success
non-zero otherwise
--*/
{
FileFlags = 0;
EfiRomFlag = FALSE;
//
// Clear out the options
//
//
// To avoid compile warnings
//
ClassCode = 0;
CodeRevision = 0;
//
// Skip over the program name
//
Argc--;
Argv++;
//
// If no arguments, assume they want usage info
//
if (Argc == 0) {
Usage ();
return STATUS_ERROR;
}
Usage();
return STATUS_ERROR;
}
Version();
return STATUS_ERROR;
}
//
// Process until no more arguments
//
while (Argc > 0) {
if (Argv[0][0] == '-') {
//
// Vendor ID specified with -f
//
//
// Make sure there's another parameter
//
return 1;
}
if (TempValue >= 0x10000) {
return 1;
}
Argv++;
Argc--;
//
// Device ID specified with -i
// Make sure there's another parameter
//
return 1;
}
if (TempValue >= 0x10000) {
return 1;
}
Argv++;
Argc--;
//
// Output filename specified with -o
// Make sure there's another parameter
//
return STATUS_ERROR;
}
Argv++;
Argc--;
//
// Help option
//
Usage ();
return STATUS_ERROR;
//
// Specify binary files with -b
//
//
// Specify EFI files with -e. Specify EFI-compressed with -c.
//
}
//
// Specify not to set the LAST bit in the last file with -n
//
//
// -v for verbose
//
return 1;
}
if (DebugLevel > 9) {
Error (NULL, 0, 2000, "Invalid option value", "Debug Level range is 0-9, current input level is %d", Argv[1]);
return 1;
}
} else {
}
Argv++;
Argc--;
//
// -dump for dumping a ROM image. In this case, say that the device id
// and vendor id are valid so we don't have to specify bogus ones on the
// command line.
//
//
// Class code value for the next file in the list.
// Make sure there's another parameter
//
return 1;
}
if (ClassCode & 0xFF000000) {
return STATUS_ERROR;
}
}
Argv++;
Argc--;
//
// Code revision in the PCI data structure. The value is for the next
// file in the list.
// Make sure there's another parameter
//
return 1;
}
if (CodeRevision & 0xFFFF0000) {
return STATUS_ERROR;
}
}
Argv++;
Argc--;
//
// Default layout meets PCI 3.0 specifications, specifying this flag will for a PCI 2.3 layout.
//
} else {
return STATUS_ERROR;
}
} else {
//
// Not a slash-option argument. Must be a file name. Make sure they've specified
// -e or -b already.
//
return STATUS_ERROR;
}
//
// Check Efi Option RomImage
//
EfiRomFlag = TRUE;
}
//
// Create a new file structure
//
return STATUS_ERROR;
}
//
// set flag and class code for this image.
//
ClassCode = 0;
CodeRevision = 0;
} else {
if (PrevFileList == NULL) {
} else {
}
}
}
//
// Next argument
//
Argv++;
Argc--;
}
//
// Must have specified some files
//
return STATUS_ERROR;
}
//
// For EFI OptionRom image, Make sure a device ID and vendor ID are both specified.
//
if (EfiRomFlag) {
if (!Options->VendIdValid) {
return STATUS_ERROR;
}
if (!Options->DevIdValid) {
return STATUS_ERROR;
}
}
return 0;
}
static
void
Version (
)
/*++
Routine Description:
Print version information for this utility.
Arguments:
None.
Returns:
Nothing.
--*/
{
fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
}
static
void
Usage (
)
/*++
Routine Description:
Print usage information for this utility.
Arguments:
None.
Returns:
Nothing.
--*/
{
//
// Summary usage
//
//
// Copyright declaration
//
//
// Details Option
//
File will be created to store the output content.\n");
EFI PE32 image files.\n");
EFI PE32 image files and will be compressed.\n");
Legacy binary files.\n");
Hex ClassCode in the PCI data structure header.\n");
Hex PCI Vendor ID for the device OpROM, must be specified\n");
Hex PCI Device ID for the device OpROM, must be specified\n");
Default layout meets PCI 3.0 specifications\n\
specifying this flag will for a PCI 2.3 layout.\n");
Dump the headers of an existing option ROM image.\n");
Turn on verbose output with informational messages.\n");
Show this help message and exit.\n");
Disable all messages except FATAL ERRORS.\n");
Enable debug messages at level #.\n");
}
static
void
)
/*++
Routine Description:
Dump the headers of an existing option ROM image
Arguments:
InFile - the file name of an existing option ROM image
Returns:
none
--*/
{
//
// Open the input file
//
return ;
}
//
// Go through the image and dump the header stuff for each
//
ImageCount = 0;
for (;;) {
//
// Save our postition in the file, since offsets in the headers
// are relative to the particular image.
//
ImageCount++;
//
// Read the option ROM header. Have to assume a raw binary image for now.
//
goto BailOut;
}
//
// Dump the contents of the header
//
//
// Find PCI data structure
//
goto BailOut;
}
//
// Read and dump the PCI data structure
//
Error (NULL, 0, 3001, "Not supported", "Failed to read PCI data structure from file %s!", InFile->FileName);
goto BailOut;
}
} else {
Error (NULL, 0, 3001, "Not supported", "Failed to read PCI data structure from file %s!", InFile->FileName);
goto BailOut;
}
}
}
//fprintf (stdout, " PCI Data Structure\n");
fprintf (
" Signature %c%c%c%c\n",
);
fprintf (
" Class Code 0x%06X\n",
);
} else {
fprintf (
" Signature %c%c%c%c\n",
);
fprintf (
" Class Code 0x%06X\n",
);
}
//
// Print the indicator, used to flag the last image
//
} else {
}
//
// Print the code type. If EFI code, then we can provide more info.
//
} else {
}
//
// Re-read the header as an EFI ROM header, then dump more info
//
goto BailOut;
}
goto BailOut;
}
//
// Now dump more info
//
fprintf (
" Compression Type 0x%04X ",
);
} else {
}
fprintf (
" Machine type 0x%04X (%s)\n",
);
fprintf (
" Subsystem 0x%04X (%s)\n",
);
fprintf (
" EFI image offset 0x%04X (@0x%X)\n",
);
} else {
//
// Not an EFI image
//
}
//
// If code type is EFI image, then dump it as well?
//
// if (PciDs.CodeType == PCI_CODE_TYPE_EFI_IMAGE) {
// }
//
// If last image, then we're done
//
goto BailOut;
}
//
// Seek to the start of the next image
//
goto BailOut;
}
} else {
goto BailOut;
}
}
}
}
char *
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
MachineType - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
int Index;
}
}
return "unknown";
}
static
char *
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
SubsystemType - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
{
int Index;
}
}
return "unknown";
}