bds.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. bds.h
  5. Abstract:
  6. This header contains internal definitions for the Boot Device Selection
  7. module.
  8. Author:
  9. Evan Green 17-Mar-2014
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. #include "peimage.h"
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. #define EFI_BDS_COMMON_OPTION_MAGIC 0x4F736442 // 'OsdB'
  19. //
  20. // ACPI boot type. For ACPI devices, using sub-types to distinguish devices is
  21. // not allowed, so hardcode their values.
  22. //
  23. #define BDS_EFI_ACPI_FLOPPY_BOOT 0x0201
  24. //
  25. // Message boot type
  26. // If a device path of boot option only points to a message node, the boot
  27. // option is a message boot type.
  28. //
  29. #define BDS_EFI_MESSAGE_ATAPI_BOOT 0x0301
  30. #define BDS_EFI_MESSAGE_SCSI_BOOT 0x0302
  31. #define BDS_EFI_MESSAGE_USB_DEVICE_BOOT 0x0305
  32. #define BDS_EFI_MESSAGE_SATA_BOOT 0x0312
  33. #define BDS_EFI_MESSAGE_MAC_BOOT 0x030b
  34. #define BDS_EFI_MESSAGE_MISC_BOOT 0x03FF
  35. //
  36. // Media boot type. If a device path of boot option contains a media node, the
  37. // boot option is media boot type.
  38. //
  39. #define BDS_EFI_MEDIA_HD_BOOT 0x0401
  40. #define BDS_EFI_MEDIA_CDROM_BOOT 0x0402
  41. //
  42. // BBS boot type. If a device path of boot option contains a BBS node, the boot
  43. // option is BBS boot type.
  44. //
  45. #define BDS_LEGACY_BBS_BOOT 0x0501
  46. #define BDS_EFI_UNSUPPORTED 0xFFFF
  47. #define EFI_BOOT_OPTION_MAX_CHAR 10
  48. //
  49. // This GUID is used for an EFI Variable that stores the front device pathes
  50. // for a partial device path that starts with the HD node.
  51. //
  52. #define EFI_HD_BOOT_DEVICE_PATH_VARIABLE_GUID \
  53. { \
  54. 0xFAB7E9E1, 0x39DD, 0x4F2B, \
  55. {0x84, 0x08, 0xE2, 0x0E, 0x90, 0x6C, 0xB6, 0xDE} \
  56. }
  57. #define EFI_HD_BOOT_DEVICE_PATH_VARIABLE_NAME L"HDDP"
  58. #define EFI_MAX_HD_DEVICE_PATH_CACHE_SIZE 12
  59. //
  60. // ------------------------------------------------------ Data Type Definitions
  61. //
  62. typedef struct _EFI_BDS_COMMON_OPTION {
  63. UINTN Magic;
  64. LIST_ENTRY ListEntry;
  65. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  66. CHAR16 *OptionName;
  67. UINTN OptionNumber;
  68. UINT16 BootCurrent;
  69. UINT32 Attribute;
  70. CHAR16 *Description;
  71. VOID *LoadOptions;
  72. UINT32 LoadOptionsSize;
  73. CHAR16 *StatusString;
  74. } EFI_BDS_COMMON_OPTION, *PEFI_BDS_COMMON_OPTION;
  75. //
  76. // -------------------------------------------------------------------- Globals
  77. //
  78. //
  79. // -------------------------------------------------------- Function Prototypes
  80. //
  81. //
  82. // BDS boot functions
  83. //
  84. EFI_STATUS
  85. EfipBdsBootViaBootOption (
  86. PEFI_BDS_COMMON_OPTION Option,
  87. EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  88. UINTN *ExitDataSize,
  89. CHAR16 **ExitData
  90. );
  91. /*++
  92. Routine Description:
  93. This routine attempts to boot the given boot option.
  94. Arguments:
  95. Option - Supplies a pointer to the option to boot.
  96. DevicePath - Supplies a pointer to the device path describing where to
  97. load the boot image or legacy BBS device path.
  98. ExitDataSize - Supplies a pointer where the exit data size will be returned.
  99. ExitData - Supplies a pointer where a pointer to the exit data will be
  100. returned.
  101. Return Value:
  102. EFI status code.
  103. --*/
  104. EFI_STATUS
  105. EfipBdsEnumerateAllBootOptions (
  106. PLIST_ENTRY OptionList
  107. );
  108. /*++
  109. Routine Description:
  110. This routine enumerates all possible boot devices in the system, and
  111. creates boot options for them. There are six types of automatic boot
  112. options:
  113. 1. Network - Creates boot options on any load file protocol instances.
  114. 2. Shell - Creates boot options for any firmware volumes that contain a
  115. specific path on them.
  116. 3. Removable Block I/O - Creates a boot option for any removable block I/O
  117. device.
  118. 4. Fixed Block I/O - Does not create a boot option for fixed drives.
  119. 5. Non-Block I/O Simple File Systems - Creates a boot option for
  120. \EFI\BOOT\boot{machine}.EFI using the Simple File System Protocol.
  121. 6. File - Does not create, modify, or delete a boot option pointing at a
  122. file.
  123. Arguments:
  124. OptionList - Supplies a pointer to the head of the boot option list.
  125. Return Value:
  126. EFI status code.
  127. --*/
  128. //
  129. // BDS console functions
  130. //
  131. EFI_STATUS
  132. EfipBdsConnectAllDefaultConsoles (
  133. VOID
  134. );
  135. /*++
  136. Routine Description:
  137. This routine connects the console device based on the console variables.
  138. Arguments:
  139. None.
  140. Return Value:
  141. None.
  142. --*/
  143. //
  144. // BDS utility functions
  145. //
  146. VOID
  147. EfipBdsConnectAll (
  148. VOID
  149. );
  150. /*++
  151. Routine Description:
  152. This routine connects all system drivers to controllers first, then
  153. specially connect the default console. This ensures all system controllers
  154. are available and the platform default console is connected.
  155. Arguments:
  156. None.
  157. Return Value:
  158. None.
  159. --*/
  160. VOID
  161. EfipBdsConnectAllDriversToAllControllers (
  162. VOID
  163. );
  164. /*++
  165. Routine Description:
  166. This routine connects all system drivers to controllers.
  167. Arguments:
  168. None.
  169. Return Value:
  170. None.
  171. --*/
  172. VOID
  173. EfipBdsLoadDrivers (
  174. PLIST_ENTRY DriverList
  175. );
  176. /*++
  177. Routine Description:
  178. This routine loads and starts every driver on the given load list.
  179. Arguments:
  180. DriverList - Supplies a pointer to the head of the list of boot options
  181. describing the drivers to load.
  182. Return Value:
  183. None.
  184. --*/
  185. EFI_STATUS
  186. EfipBdsBuildOptionFromVariable (
  187. PLIST_ENTRY OptionList,
  188. CHAR16 *VariableName
  189. );
  190. /*++
  191. Routine Description:
  192. This routine processes BootOrder or DriverOrder variables.
  193. Arguments:
  194. OptionList - Supplies a pointer to the head of the list of boot or
  195. driver options.
  196. VariableName - Supplies a pointer to the variable name indicating the boot
  197. order or driver order. Typically this should be BootOrder or
  198. DriverOrder.
  199. Return Value:
  200. EFI status code.
  201. --*/
  202. PEFI_BDS_COMMON_OPTION
  203. EfipBdsConvertVariableToOption (
  204. PLIST_ENTRY OptionList,
  205. CHAR16 *VariableName
  206. );
  207. /*++
  208. Routine Description:
  209. This routine builds a Boot#### or Driver#### option from the given variable
  210. name. The new option will also be linked into the given list.
  211. Arguments:
  212. OptionList - Supplies a pointer to the list to link the option into upon
  213. success.
  214. VariableName - Supplies a pointer to the variable name, which is typically
  215. in the form Boot#### or Driver####.
  216. Return Value:
  217. Returns a pointer to the option on success.
  218. NULL on failure.
  219. --*/
  220. VOID *
  221. EfipBdsGetVariable (
  222. CHAR16 *Name,
  223. EFI_GUID *VendorGuid,
  224. UINTN *VariableSize
  225. );
  226. /*++
  227. Routine Description:
  228. This routine reads the given EFI variable and returns a buffer allocated
  229. from pool containing its contents.
  230. Arguments:
  231. Name - Supplies a pointer to the name of the variable to get.
  232. VendorGuid - Supplies the GUID part of the variable name.
  233. VariableSize - Supplies a pointer where the size of the variable contents
  234. will be returned on success.
  235. Return Value:
  236. Returns a pointer to the variable contents allocated from pool on success.
  237. The caller is responsible for freeing this memory.
  238. NULL on failure.
  239. --*/
  240. EFI_DEVICE_PATH_PROTOCOL *
  241. EfipBdsDeletePartialMatchInstance (
  242. EFI_DEVICE_PATH_PROTOCOL *MultiInstancePath,
  243. EFI_DEVICE_PATH_PROTOCOL *SingleInstance
  244. );
  245. /*++
  246. Routine Description:
  247. This routine deletes the instance in the given multi-instance device path
  248. that matches partly with the given instance.
  249. Arguments:
  250. MultiInstancePath - Supplies a pointer to the multi-instance device path.
  251. SingleInstance - Supplies a pointer to the single-instance device path.
  252. Return Value:
  253. Returns the modified multi-instance path on success.
  254. NULL on failure.
  255. --*/
  256. BOOLEAN
  257. EfipBdsMatchDevicePaths (
  258. EFI_DEVICE_PATH_PROTOCOL *MultiInstancePath,
  259. EFI_DEVICE_PATH_PROTOCOL *SingleInstance
  260. );
  261. /*++
  262. Routine Description:
  263. This routine compares a device path structure to that of all nodes of a
  264. second device path instance.
  265. Arguments:
  266. MultiInstancePath - Supplies a pointer to the multi-instance device path to
  267. search through.
  268. SingleInstance - Supplies a pointer to the single-instance device path to
  269. search for.
  270. Return Value:
  271. TRUE if the single instance path exists somewhere in the multi-instance
  272. path.
  273. FALSE if th single instance path is not found anywhere in the
  274. multi-instance path.
  275. --*/
  276. EFI_STATUS
  277. EfipBdsRegisterNewOption (
  278. EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  279. CHAR16 *String,
  280. CHAR16 *VariableName
  281. );
  282. /*++
  283. Routine Description:
  284. This routine registers a new Boot#### or Driver#### option base on the
  285. given variable name. The BootOrder or DriverOrder will also be updated.
  286. Arguments:
  287. DevicePath - Supplies a pointer to the device path of the option.
  288. String - Supplies a pointer to a string describing the option.
  289. VariableName - Supplies a pointer to the string BootOrder or DriverOrder
  290. to update.
  291. Return Value:
  292. EFI status code.
  293. --*/
  294. EFI_STATUS
  295. EfipBdsGetImageHeader (
  296. EFI_HANDLE Device,
  297. CHAR16 *FileName,
  298. EFI_IMAGE_DOS_HEADER *DosHeader,
  299. EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Header
  300. );
  301. /*++
  302. Routine Description:
  303. This routine gets the image headers from an image.
  304. Arguments:
  305. Device - Supplies the simple file system handle.
  306. FileName - Supplies the path to the file to get the headers for.
  307. DosHeader - Supplies a pointer where the DOS header will be returned.
  308. Header - Supplies a pointer (union) where the PE headers will be returned.
  309. Return Value:
  310. EFI_SUCCESS on success.
  311. EFI_NOT_FOUND if the file was not found.
  312. EFI_LOAD_ERROR if the file is not a valid image.
  313. --*/
  314. EFI_STATUS
  315. EfipBdsConnectDevicePath (
  316. EFI_DEVICE_PATH_PROTOCOL *Path
  317. );
  318. /*++
  319. Routine Description:
  320. This routine creates all handles associated with every device path node.
  321. Arguments:
  322. Path - Supplies a pointer to the device path to connect.
  323. Return Value:
  324. EFI Status code.
  325. --*/
  326. BOOLEAN
  327. EfipBdsValidateOption (
  328. UINT8 *Variable,
  329. UINTN VariableSize
  330. );
  331. /*++
  332. Routine Description:
  333. This routine validates the contents of a Boot#### option variable.
  334. Arguments:
  335. Variable - Supplies a pointer to the variable contents.
  336. VariableSize - Supplies the size of the variable contents buffer in bytes.
  337. Return Value:
  338. TRUE if the variable data is correct.
  339. FALSE if the variable data is not correct.
  340. --*/
  341. VOID
  342. EfipBdsCreateHexCodeString (
  343. CHAR16 *String,
  344. UINT16 HexInteger,
  345. CHAR16 *Destination,
  346. UINTN DestinationSize
  347. );
  348. /*++
  349. Routine Description:
  350. This routine appends a four-digit hex code to a string. For example,
  351. Boot####.
  352. Arguments:
  353. String - Supplies a pointer to the string to prepend to the destination
  354. string.
  355. HexInteger - Supplies the four digit hex integer to append.
  356. Destination - Supplies a pointer to the destination string buffer.
  357. DestinationSize - Supplies the size of the destination string in bytes.
  358. Return Value:
  359. None.
  360. --*/