+/*++\r
+\r
+Copyright (c) 1999 - 2007 Intel Corporation. All rights reserved\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name: \r
+\r
+ EfiRom.h\r
+\r
+Abstract:\r
+\r
+ This file contains the relevant declarations required\r
+ to generate Option Rom File\r
+\r
+--*/\r
+\r
+#ifndef __EFI_ROM_H__\r
+#define __EFI_ROM_H__\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+#include <IndustryStandard/PeImage.h> // for PE32 structure definitions\r
+\r
+#include <IndustryStandard/pci22.h> // for option ROM header structures\r
+#include <IndustryStandard/pci30.h>\r
+\r
+#include "Compress.h"\r
+#include "CommonLib.h"\r
+\r
+//\r
+// Version of this utility\r
+//\r
+#define UTILITY_NAME "EfiRom"\r
+#define UTILITY_MAJOR_VERSION 0\r
+#define UTILITY_MINOR_VERSION 1\r
+\r
+//\r
+// Define some status return values\r
+//\r
+#define STATUS_SUCCESS 0\r
+#define STATUS_WARNING 1\r
+#define STATUS_ERROR 2\r
+\r
+//\r
+// Define the max length of a filename\r
+//\r
+#define MAX_PATH 200\r
+\r
+//\r
+// Define the default file extension name\r
+//\r
+#define DEFAULT_OUTPUT_EXTENSION ".rom"\r
+\r
+//\r
+// Max size for an option ROM image\r
+//\r
+#define MAX_OPTION_ROM_SIZE (1024 * 1024 * 16) // 16MB\r
+\r
+//\r
+// Values for the indicator field in the PCI data structure\r
+//\r
+#define INDICATOR_LAST 0x80 // last file in series of files\r
+\r
+//\r
+// Masks for the FILE_LIST.FileFlags field\r
+//\r
+#define FILE_FLAG_BINARY 0x01\r
+#define FILE_FLAG_EFI 0x02\r
+#define FILE_FLAG_COMPRESS 0x04\r
+\r
+//\r
+// global variables\r
+//\r
+UINTN DebugLevel = 0;\r
+BOOLEAN DebugMode = FALSE;\r
+BOOLEAN QuietMode = FALSE;\r
+\r
+//\r
+// Use this linked list structure to keep track of all the filenames\r
+// specified on the command line.\r
+//\r
+typedef struct _FILE_LIST {\r
+ struct _FILE_LIST *Next;\r
+ INT8 *FileName;\r
+ UINT32 FileFlags;\r
+ UINT32 ClassCode;\r
+ UINT16 CodeRevision;\r
+} FILE_LIST;\r
+\r
+//\r
+// Use this to track our command-line options\r
+//\r
+typedef struct {\r
+ INT8 OutFileName[MAX_PATH];\r
+ INT8 *EfiFileName;\r
+ INT8 *BinFileName;\r
+ INT8 Compress;\r
+ INT8 NoLast;\r
+ UINT16 ClassCode;\r
+ UINT16 PciRevision;\r
+ UINT16 VendId;\r
+ UINT16 DevId;\r
+ UINT8 VendIdValid;\r
+ UINT8 DevIdValid;\r
+ INT8 Verbose;\r
+ INT8 Quiet;\r
+ INT8 Debug;\r
+ INT8 Pci23;\r
+ INT8 Pci30;\r
+ INT8 DumpOption;\r
+// INT8 Help;\r
+// INT8 Version; \r
+ FILE_LIST *FileList;\r
+} OPTIONS;\r
+\r
+//\r
+// Make a global structure to keep track of command-line options\r
+//\r
+static OPTIONS mOptions;\r
+\r
+//\r
+// Use these to convert from machine type value to a named type\r
+//\r
+typedef struct {\r
+ UINT16 Value;\r
+ char *Name;\r
+} STRING_LOOKUP;\r
+\r
+//\r
+// Machine Types\r
+//\r
+static STRING_LOOKUP mMachineTypes[] = {\r
+ EFI_IMAGE_MACHINE_IA32,\r
+ "IA32",\r
+ EFI_IMAGE_MACHINE_IA64,\r
+ "IA64",\r
+ EFI_IMAGE_MACHINE_EBC,\r
+ "EBC",\r
+ 0,\r
+ NULL\r
+};\r
+\r
+//\r
+// Subsystem Types\r
+//\r
+static STRING_LOOKUP mSubsystemTypes[] = {\r
+ EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION,\r
+ "EFI application",\r
+ EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER,\r
+ "EFI boot service driver",\r
+ EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER,\r
+ "EFI runtime driver",\r
+ 0,\r
+ NULL\r
+};\r
+\r
+//\r
+// Function prototypes\r
+//\r
+static\r
+void\r
+Version (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Displays the utility version to STDOUT\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+;\r
+\r
+static\r
+void\r
+Usage (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Displays the utility usage syntax to STDOUT\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/ \r
+;\r
+\r
+static\r
+int\r
+ParseCommandLine (\r
+ int Argc,\r
+ char *Argv[],\r
+ OPTIONS *Options\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Given the Argc/Argv program arguments, and a pointer to an options structure,\r
+ parse the command-line options and check their validity.\r
+\r
+Arguments:\r
+\r
+ Argc - standard C main() argument count\r
+ Argv[] - standard C main() argument list\r
+ Options - pointer to a structure to store the options in\r
+\r
+Returns:\r
+\r
+ STATUS_SUCCESS success\r
+ non-zero otherwise\r
+\r
+--*/\r
+;\r
+\r
+static\r
+int\r
+CheckPE32File (\r
+ FILE *Fptr,\r
+ UINT16 *MachineType,\r
+ UINT16 *SubSystem\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Given the Argc/Argv program arguments, and a pointer to an options structure,\r
+ parse the command-line options and check their validity.\r
+\r
+Arguments:\r
+\r
+ Argc - standard C main() argument count\r
+ Argv[] - standard C main() argument list\r
+ Options - pointer to a structure to store the options in\r
+\r
+Returns:\r
+\r
+ STATUS_SUCCESS success\r
+ non-zero otherwise\r
+\r
+--*/ \r
+;\r
+\r
+static\r
+int\r
+ProcessEfiFile (\r
+ FILE *OutFptr,\r
+ FILE_LIST *InFile,\r
+ UINT16 VendId,\r
+ UINT16 DevId,\r
+ UINT32 *Size\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Process a PE32 EFI file.\r
+\r
+Arguments:\r
+\r
+ OutFptr - file pointer to output binary ROM image file we're creating\r
+ InFile - structure contains information on the PE32 file to process\r
+ VendId - vendor ID as required in the option ROM header\r
+ DevId - device ID as required in the option ROM header\r
+ Size - pointer to where to return the size added to the output file\r
+\r
+Returns:\r
+\r
+ 0 - successful\r
+\r
+--*/\r
+;\r
+\r
+static\r
+int\r
+ProcessBinFile (\r
+ FILE *OutFptr,\r
+ FILE_LIST *InFile,\r
+ UINT32 *Size\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Process a binary input file.\r
+\r
+Arguments:\r
+\r
+ OutFptr - file pointer to output binary ROM image file we're creating\r
+ InFile - structure contains information on the binary file to process\r
+ Size - pointer to where to return the size added to the output file\r
+\r
+Returns:\r
+\r
+ 0 - successful\r
+\r
+--*/ \r
+;\r
+\r
+static\r
+void\r
+DumpImage (\r
+ FILE_LIST *InFile\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Dump the headers of an existing option ROM image\r
+\r
+Arguments:\r
+\r
+ InFile - the file name of an existing option ROM image\r
+\r
+Returns:\r
+\r
+ none\r
+\r
+--*/\r
+;\r
+\r
+char *\r
+GetMachineTypeStr (\r
+ UINT16 MachineType\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ MachineType - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+static\r
+char *\r
+GetSubsystemTypeStr (\r
+ UINT16 SubsystemType\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ SubsystemType - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r