1/** @file 2This file contains the relevant declarations required to generate Option Rom File 3 4Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR> 5This program and the accompanying materials are licensed and made available 6under the terms and conditions of the BSD License which accompanies this 7distribution. The full text of the license may be found at 8http://opensource.org/licenses/bsd-license.php 9 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13**/ 14 15#ifndef __EFI_ROM_H__ 16#define __EFI_ROM_H__ 17 18#include <stdio.h> 19#include <string.h> 20#include <stdlib.h> 21 22#include <Common/UefiBaseTypes.h> 23#include <IndustryStandard/PeImage.h> // for PE32 structure definitions 24 25#include <IndustryStandard/pci22.h> // for option ROM header structures 26#include <IndustryStandard/pci30.h> 27 28#include "Compress.h" 29#include "CommonLib.h" 30 31// 32// Version of this utility 33// 34#define UTILITY_NAME "EfiRom" 35#define UTILITY_MAJOR_VERSION 0 36#define UTILITY_MINOR_VERSION 1 37 38// 39// Define the max length of a filename 40// 41#define MAX_PATH 200 42 43// 44// Define the default file extension name 45// 46#define DEFAULT_OUTPUT_EXTENSION ".rom" 47 48// 49// Max size for an option ROM image 50// 51#define MAX_OPTION_ROM_SIZE (1024 * 1024 * 16) // 16MB 52 53// 54// Values for the indicator field in the PCI data structure 55// 56#define INDICATOR_LAST 0x80 // last file in series of files 57 58// 59// Masks for the FILE_LIST.FileFlags field 60// 61#define FILE_FLAG_BINARY 0x01 62#define FILE_FLAG_EFI 0x02 63#define FILE_FLAG_COMPRESS 0x04 64 65// 66// Use this linked list structure to keep track of all the filenames 67// specified on the command line. 68// 69typedef struct _FILE_LIST { 70 struct _FILE_LIST *Next; 71 CHAR8 *FileName; 72 UINT32 FileFlags; 73 UINT32 ClassCode; 74 UINT16 CodeRevision; 75} FILE_LIST; 76 77// 78// Use this to track our command-line options 79// 80typedef struct { 81 CHAR8 OutFileName[MAX_PATH]; 82 INT8 NoLast; 83 UINT16 ClassCode; 84 UINT16 PciRevision; 85 UINT16 VendId; 86 UINT16 DevId; 87 UINT8 VendIdValid; 88 UINT8 DevIdValid; 89 INT8 Verbose; 90 INT8 Quiet; 91 INT8 Debug; 92 INT8 Pci23; 93 INT8 Pci30; 94 INT8 DumpOption; 95// INT8 Help; 96// INT8 Version; 97 FILE_LIST *FileList; 98} OPTIONS; 99 100// 101// Make a global structure to keep track of command-line options 102// 103static OPTIONS mOptions; 104 105// 106// Use these to convert from machine type value to a named type 107// 108typedef struct { 109 UINT16 Value; 110 CHAR8 *Name; 111} STRING_LOOKUP; 112 113// 114// Machine Types 115// 116static STRING_LOOKUP mMachineTypes[] = { 117 { EFI_IMAGE_MACHINE_IA32, "IA32" }, 118 { EFI_IMAGE_MACHINE_IA64, "IA64" }, 119 { EFI_IMAGE_MACHINE_EBC, "EBC" }, 120 { 0, NULL } 121}; 122 123// 124// Subsystem Types 125// 126static STRING_LOOKUP mSubsystemTypes[] = { 127 { EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION, "EFI application" }, 128 { EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, "EFI boot service driver" }, 129 { EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER, "EFI runtime driver" }, 130 { 0, NULL } 131}; 132 133// 134// Function prototypes 135// 136static 137void 138Version ( 139 VOID 140 ) 141/*++ 142 143Routine Description: 144 145 Displays the utility version to STDOUT 146 147Arguments: 148 149 None 150 151Returns: 152 153 None 154 155--*/ 156; 157 158static 159void 160Usage ( 161 VOID 162 ) 163/*++ 164 165Routine Description: 166 167 Displays the utility usage syntax to STDOUT 168 169Arguments: 170 171 None 172 173Returns: 174 175 None 176 177--*/ 178; 179 180static 181int 182ParseCommandLine ( 183 int Argc, 184 char *Argv[], 185 OPTIONS *Options 186 ) 187/*++ 188 189Routine Description: 190 191 Given the Argc/Argv program arguments, and a pointer to an options structure, 192 parse the command-line options and check their validity. 193 194Arguments: 195 196 Argc - standard C main() argument count 197 Argv[] - standard C main() argument list 198 Options - pointer to a structure to store the options in 199 200Returns: 201 202 STATUS_SUCCESS success 203 non-zero otherwise 204 205--*/ 206; 207 208static 209int 210CheckPE32File ( 211 FILE *Fptr, 212 UINT16 *MachineType, 213 UINT16 *SubSystem 214 ) 215/*++ 216 217Routine Description: 218 219 Given the Argc/Argv program arguments, and a pointer to an options structure, 220 parse the command-line options and check their validity. 221 222Arguments: 223 224 Argc - standard C main() argument count 225 Argv[] - standard C main() argument list 226 Options - pointer to a structure to store the options in 227 228Returns: 229 230 STATUS_SUCCESS success 231 non-zero otherwise 232 233--*/ 234; 235 236static 237int 238ProcessEfiFile ( 239 FILE *OutFptr, 240 FILE_LIST *InFile, 241 UINT16 VendId, 242 UINT16 DevId, 243 UINT32 *Size 244 ) 245/*++ 246 247Routine Description: 248 249 Process a PE32 EFI file. 250 251Arguments: 252 253 OutFptr - file pointer to output binary ROM image file we're creating 254 InFile - structure contains information on the PE32 file to process 255 VendId - vendor ID as required in the option ROM header 256 DevId - device ID as required in the option ROM header 257 Size - pointer to where to return the size added to the output file 258 259Returns: 260 261 0 - successful 262 263--*/ 264; 265 266static 267int 268ProcessBinFile ( 269 FILE *OutFptr, 270 FILE_LIST *InFile, 271 UINT32 *Size 272 ) 273/*++ 274 275Routine Description: 276 277 Process a binary input file. 278 279Arguments: 280 281 OutFptr - file pointer to output binary ROM image file we're creating 282 InFile - structure contains information on the binary file to process 283 Size - pointer to where to return the size added to the output file 284 285Returns: 286 287 0 - successful 288 289--*/ 290; 291 292static 293void 294DumpImage ( 295 FILE_LIST *InFile 296 ) 297/*++ 298 299Routine Description: 300 301 Dump the headers of an existing option ROM image 302 303Arguments: 304 305 InFile - the file name of an existing option ROM image 306 307Returns: 308 309 none 310 311--*/ 312; 313 314char * 315GetMachineTypeStr ( 316 UINT16 MachineType 317 ) 318/*++ 319 320Routine Description: 321 322 GC_TODO: Add function description 323 324Arguments: 325 326 MachineType - GC_TODO: add argument description 327 328Returns: 329 330 GC_TODO: add return values 331 332--*/ 333; 334 335static 336char * 337GetSubsystemTypeStr ( 338 UINT16 SubsystemType 339 ) 340/*++ 341 342Routine Description: 343 344 GC_TODO: Add function description 345 346Arguments: 347 348 SubsystemType - GC_TODO: add argument description 349 350Returns: 351 352 GC_TODO: add return values 353 354--*/ 355; 356 357#endif 358