EfiRom.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /** @file
  2. This file contains the relevant declarations required to generate Option Rom File
  3. Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_ROM_H__
  7. #define __EFI_ROM_H__
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <Common/UefiBaseTypes.h>
  12. #include <IndustryStandard/PeImage.h> // for PE32 structure definitions
  13. #include <IndustryStandard/pci22.h> // for option ROM header structures
  14. #include <IndustryStandard/pci30.h>
  15. #include "Compress.h"
  16. #include "CommonLib.h"
  17. //
  18. // Version of this utility
  19. //
  20. #define UTILITY_NAME "EfiRom"
  21. #define UTILITY_MAJOR_VERSION 0
  22. #define UTILITY_MINOR_VERSION 1
  23. //
  24. // Define the max length of a filename
  25. //
  26. #define MAX_PATH 200
  27. //
  28. // Define the default file extension name
  29. //
  30. #define DEFAULT_OUTPUT_EXTENSION ".rom"
  31. //
  32. // Max size for an option ROM image
  33. //
  34. #define MAX_OPTION_ROM_SIZE (1024 * 1024 * 16) // 16MB
  35. //
  36. // Values for the indicator field in the PCI data structure
  37. //
  38. #define INDICATOR_LAST 0x80 // last file in series of files
  39. //
  40. // Masks for the FILE_LIST.FileFlags field
  41. //
  42. #define FILE_FLAG_BINARY 0x01
  43. #define FILE_FLAG_EFI 0x02
  44. #define FILE_FLAG_COMPRESS 0x04
  45. //
  46. // Use this linked list structure to keep track of all the filenames
  47. // specified on the command line.
  48. //
  49. typedef struct _FILE_LIST {
  50. struct _FILE_LIST *Next;
  51. CHAR8 *FileName;
  52. UINT32 FileFlags;
  53. UINT32 ClassCode;
  54. UINT16 CodeRevision;
  55. } FILE_LIST;
  56. //
  57. // Use this to track our command-line options
  58. //
  59. typedef struct {
  60. CHAR8 OutFileName[MAX_PATH];
  61. INT8 NoLast;
  62. UINT16 ClassCode;
  63. UINT16 PciRevision;
  64. UINT16 VendId;
  65. UINT16 *DevIdList;
  66. UINT32 DevIdCount;
  67. UINT8 VendIdValid;
  68. INT8 Verbose;
  69. INT8 Quiet;
  70. INT8 Debug;
  71. INT8 Pci23;
  72. INT8 Pci30;
  73. INT8 DumpOption;
  74. // INT8 Help;
  75. // INT8 Version;
  76. FILE_LIST *FileList;
  77. } OPTIONS;
  78. //
  79. // Make a global structure to keep track of command-line options
  80. //
  81. static OPTIONS mOptions;
  82. //
  83. // Use these to convert from machine type value to a named type
  84. //
  85. typedef struct {
  86. UINT16 Value;
  87. CHAR8 *Name;
  88. } STRING_LOOKUP;
  89. //
  90. // Machine Types
  91. //
  92. static STRING_LOOKUP mMachineTypes[] = {
  93. { EFI_IMAGE_MACHINE_IA32, "IA32" },
  94. { EFI_IMAGE_MACHINE_X64, "X64" },
  95. { EFI_IMAGE_MACHINE_EBC, "EBC" },
  96. { EFI_IMAGE_MACHINE_ARMT, "ARM" },
  97. { EFI_IMAGE_MACHINE_AARCH64, "AA64" },
  98. { 0, NULL }
  99. };
  100. //
  101. // Subsystem Types
  102. //
  103. static STRING_LOOKUP mSubsystemTypes[] = {
  104. { EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION, "EFI application" },
  105. { EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, "EFI boot service driver" },
  106. { EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER, "EFI runtime driver" },
  107. { 0, NULL }
  108. };
  109. //
  110. // Function prototypes
  111. //
  112. static
  113. void
  114. Version (
  115. VOID
  116. )
  117. /*++
  118. Routine Description:
  119. Displays the utility version to STDOUT
  120. Arguments:
  121. None
  122. Returns:
  123. None
  124. --*/
  125. ;
  126. static
  127. void
  128. Usage (
  129. VOID
  130. )
  131. /*++
  132. Routine Description:
  133. Displays the utility usage syntax to STDOUT
  134. Arguments:
  135. None
  136. Returns:
  137. None
  138. --*/
  139. ;
  140. static
  141. int
  142. ParseCommandLine (
  143. int Argc,
  144. char *Argv[],
  145. OPTIONS *Options
  146. )
  147. /*++
  148. Routine Description:
  149. Given the Argc/Argv program arguments, and a pointer to an options structure,
  150. parse the command-line options and check their validity.
  151. Arguments:
  152. Argc - standard C main() argument count
  153. Argv[] - standard C main() argument list
  154. Options - pointer to a structure to store the options in
  155. Returns:
  156. STATUS_SUCCESS success
  157. non-zero otherwise
  158. --*/
  159. ;
  160. static
  161. int
  162. CheckPE32File (
  163. FILE *Fptr,
  164. UINT16 *MachineType,
  165. UINT16 *SubSystem
  166. )
  167. /*++
  168. Routine Description:
  169. Given the Argc/Argv program arguments, and a pointer to an options structure,
  170. parse the command-line options and check their validity.
  171. Arguments:
  172. Argc - standard C main() argument count
  173. Argv[] - standard C main() argument list
  174. Options - pointer to a structure to store the options in
  175. Returns:
  176. STATUS_SUCCESS success
  177. non-zero otherwise
  178. --*/
  179. ;
  180. static
  181. int
  182. ProcessEfiFile (
  183. FILE *OutFptr,
  184. FILE_LIST *InFile,
  185. UINT16 VendId,
  186. UINT16 DevId,
  187. UINT32 *Size
  188. )
  189. /*++
  190. Routine Description:
  191. Process a PE32 EFI file.
  192. Arguments:
  193. OutFptr - file pointer to output binary ROM image file we're creating
  194. InFile - structure contains information on the PE32 file to process
  195. VendId - vendor ID as required in the option ROM header
  196. DevId - device ID as required in the option ROM header
  197. Size - pointer to where to return the size added to the output file
  198. Returns:
  199. 0 - successful
  200. --*/
  201. ;
  202. static
  203. int
  204. ProcessBinFile (
  205. FILE *OutFptr,
  206. FILE_LIST *InFile,
  207. UINT32 *Size
  208. )
  209. /*++
  210. Routine Description:
  211. Process a binary input file.
  212. Arguments:
  213. OutFptr - file pointer to output binary ROM image file we're creating
  214. InFile - structure contains information on the binary file to process
  215. Size - pointer to where to return the size added to the output file
  216. Returns:
  217. 0 - successful
  218. --*/
  219. ;
  220. static
  221. void
  222. DumpImage (
  223. FILE_LIST *InFile
  224. )
  225. /*++
  226. Routine Description:
  227. Dump the headers of an existing option ROM image
  228. Arguments:
  229. InFile - the file name of an existing option ROM image
  230. Returns:
  231. none
  232. --*/
  233. ;
  234. char *
  235. GetMachineTypeStr (
  236. UINT16 MachineType
  237. )
  238. /*++
  239. Routine Description:
  240. GC_TODO: Add function description
  241. Arguments:
  242. MachineType - GC_TODO: add argument description
  243. Returns:
  244. GC_TODO: add return values
  245. --*/
  246. ;
  247. static
  248. char *
  249. GetSubsystemTypeStr (
  250. UINT16 SubsystemType
  251. )
  252. /*++
  253. Routine Description:
  254. GC_TODO: Add function description
  255. Arguments:
  256. SubsystemType - GC_TODO: add argument description
  257. Returns:
  258. GC_TODO: add return values
  259. --*/
  260. ;
  261. #endif