bootlib.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. bootlib.h
  5. Abstract:
  6. This header contains definitions for the Boot Library.
  7. Author:
  8. Evan Green 19-Feb-2014
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. //
  17. // ------------------------------------------------------ Data Type Definitions
  18. //
  19. /*++
  20. Structure Description:
  21. This structure defines an open volume in the boot environment.
  22. Members:
  23. Parameters - Stores the block device's settings.
  24. DiskHandle - Stores a handle to device provided by the firmware.
  25. FileSystemHandle - Stores the handle returned when the file system mounted
  26. the device.
  27. --*/
  28. typedef struct _BOOT_VOLUME {
  29. BLOCK_DEVICE_PARAMETERS Parameters;
  30. HANDLE DiskHandle;
  31. PVOID FileSystemHandle;
  32. } BOOT_VOLUME, *PBOOT_VOLUME;
  33. //
  34. // -------------------------------------------------------------------- Globals
  35. //
  36. extern MEMORY_DESCRIPTOR_LIST BoMemoryMap;
  37. extern ULONGLONG BoEncodedVersion;
  38. extern ULONGLONG BoVersionSerial;
  39. extern ULONGLONG BoBuildTime;
  40. extern PSTR BoBuildString;
  41. extern PSTR BoProductName;
  42. //
  43. // Store a pointer to an enumerated firmware debug device.
  44. //
  45. extern PDEBUG_DEVICE_DESCRIPTION BoFirmwareDebugDevice;
  46. //
  47. // -------------------------------------------------------- Function Prototypes
  48. //
  49. //
  50. // Functions implemented by the application called by the boot library
  51. //
  52. PVOID
  53. BoExpandHeap (
  54. PMEMORY_HEAP Heap,
  55. UINTN Size,
  56. UINTN Tag
  57. );
  58. /*++
  59. Routine Description:
  60. This routine is called when the heap wants to expand and get more space.
  61. Arguments:
  62. Heap - Supplies a pointer to the heap to allocate from.
  63. Size - Supplies the size of the allocation request, in bytes.
  64. Tag - Supplies a 32-bit tag to associate with this allocation for debugging
  65. purposes. These are usually four ASCII characters so as to stand out
  66. when a poor developer is looking at a raw memory dump. It could also be
  67. a return address.
  68. Return Value:
  69. Returns a pointer to the allocation if successful, or NULL if the
  70. allocation failed.
  71. --*/
  72. //
  73. // Initialization functions
  74. //
  75. VOID
  76. BoInitializeProcessor (
  77. VOID
  78. );
  79. /*++
  80. Routine Description:
  81. This routine performs very early architecture specific initialization. It
  82. runs before the debugger is online.
  83. Arguments:
  84. None.
  85. Return Value:
  86. None.
  87. --*/
  88. KSTATUS
  89. BoHlBootInitialize (
  90. PDEBUG_DEVICE_DESCRIPTION *DebugDevice,
  91. PHARDWARE_MODULE_GET_ACPI_TABLE GetAcpiTableFunction
  92. );
  93. /*++
  94. Routine Description:
  95. This routine initializes the boot hardware library.
  96. Arguments:
  97. DebugDevice - Supplies a pointer where a pointer to the debug device
  98. description will be returned on success.
  99. GetAcpiTableFunction - Supplies an optional pointer to a function used to
  100. get ACPI tables. If not supplied a default hardware module service
  101. will be used that always returns NULL.
  102. Return Value:
  103. Status code.
  104. --*/
  105. VOID
  106. BoHlTestUsbDebugInterface (
  107. VOID
  108. );
  109. /*++
  110. Routine Description:
  111. This routine runs the interface test on a USB debug interface if debugging
  112. the USB transport itself.
  113. Arguments:
  114. None.
  115. Return Value:
  116. None.
  117. --*/
  118. //
  119. // Memory Functions
  120. //
  121. PVOID
  122. BoAllocateMemory (
  123. UINTN Size
  124. );
  125. /*++
  126. Routine Description:
  127. This routine allocates memory in the loader. This memory is marked as
  128. loader temporary, meaning it will get unmapped and reclaimed during kernel
  129. initialization.
  130. Arguments:
  131. Size - Supplies the size of the desired allocation, in bytes.
  132. Return Value:
  133. Returns a physical pointer to the allocation on success, or NULL on failure.
  134. --*/
  135. VOID
  136. BoFreeMemory (
  137. PVOID Allocation
  138. );
  139. /*++
  140. Routine Description:
  141. This routine frees memory allocated in the boot environment.
  142. Arguments:
  143. Allocation - Supplies a pointer to the memory allocation being freed.
  144. Return Value:
  145. None.
  146. --*/
  147. //
  148. // File I/O functions
  149. //
  150. KSTATUS
  151. BoOpenBootVolume (
  152. ULONG BootDriveNumber,
  153. ULONGLONG PartitionOffset,
  154. PBOOT_ENTRY BootEntry,
  155. PBOOT_VOLUME *VolumeHandle
  156. );
  157. /*++
  158. Routine Description:
  159. This routine opens a handle to the boot volume device, which is the device
  160. this boot application was loaded from.
  161. Arguments:
  162. BootDriveNumber - Supplies the drive number of the boot device, for PC/AT
  163. systems.
  164. PartitionOffset - Supplies the offset in sectors to the start of the boot
  165. partition, for PC/AT systems.
  166. BootEntry - Supplies an optional pointer to the boot entry, for EFI systems.
  167. VolumeHandle - Supplies a pointer where a handle to the open volume will
  168. be returned on success.
  169. Return Value:
  170. Status code.
  171. --*/
  172. KSTATUS
  173. BoCloseVolume (
  174. PBOOT_VOLUME VolumeHandle
  175. );
  176. /*++
  177. Routine Description:
  178. This routine closes a disk handle.
  179. Arguments:
  180. VolumeHandle - Supplies the volume handle returned when the volume was
  181. opened.
  182. Return Value:
  183. Status code.
  184. --*/
  185. KSTATUS
  186. BoOpenVolume (
  187. UCHAR PartitionId[FIRMWARE_PARTITION_ID_SIZE],
  188. PBOOT_VOLUME *Volume
  189. );
  190. /*++
  191. Routine Description:
  192. This routine closes a disk handle.
  193. Arguments:
  194. PartitionId - Supplies the ID of the partition to open.
  195. Volume - Supplies a pointer where a handle to the open volume will
  196. be returned on success.
  197. Return Value:
  198. Status code.
  199. --*/
  200. KSTATUS
  201. BoLookupPath (
  202. PBOOT_VOLUME Volume,
  203. PFILE_ID StartingDirectory,
  204. PSTR Path,
  205. PFILE_PROPERTIES FileProperties
  206. );
  207. /*++
  208. Routine Description:
  209. This routine attempts to look up the given file path.
  210. Arguments:
  211. Volume - Supplies a pointer to the volume token.
  212. StartingDirectory - Supplies an optional pointer to a file ID containing
  213. the directory to start path traversal from. If NULL, path lookup will
  214. start with the root of the volume.
  215. Path - Supplies a pointer to the path string to look up.
  216. FileProperties - Supplies a pointer where the properties for the file will
  217. be returned on success.
  218. Return Value:
  219. STATUS_SUCCESS on success.
  220. STATUS_PATH_NOT_FOUND if the given file path does not exist.
  221. Other error codes on other failures.
  222. --*/
  223. KSTATUS
  224. BoLoadFile (
  225. PBOOT_VOLUME Volume,
  226. PFILE_ID Directory,
  227. PSTR FileName,
  228. PVOID *FilePhysical,
  229. PUINTN FileSize,
  230. PULONGLONG ModificationDate
  231. );
  232. /*++
  233. Routine Description:
  234. This routine loads a file from disk into memory.
  235. Arguments:
  236. Volume - Supplies a pointer to the mounted volume to read the file from.
  237. Directory - Supplies an optional pointer to the ID of the directory to
  238. start path traversal from. If NULL, the root of the volume will be used.
  239. FileName - Supplies the name of the file to load.
  240. FilePhysical - Supplies a pointer where the file buffer's physical address
  241. will be returned. This routine will allocate the buffer to hold the
  242. file. If this parameter is NULL, the status code will reflect whether
  243. or not the file could be opened, but the file contents will not be
  244. loaded.
  245. FileSize - Supplies a pointer where the size of the file in bytes will be
  246. returned.
  247. ModificationDate - Supplies an optional pointer where the modification
  248. date of the file will be returned on success.
  249. Return Value:
  250. Status code.
  251. --*/
  252. KSTATUS
  253. BoStoreFile (
  254. PBOOT_VOLUME Volume,
  255. FILE_ID Directory,
  256. PSTR FileName,
  257. ULONG FileNameLength,
  258. PVOID FilePhysical,
  259. UINTN FileSize,
  260. ULONGLONG ModificationDate
  261. );
  262. /*++
  263. Routine Description:
  264. This routine stores a file buffer to disk.
  265. Arguments:
  266. Volume - Supplies a pointer to the mounted volume to read the file from.
  267. Directory - Supplies the file ID of the directory the file resides in.
  268. FileName - Supplies the name of the file to store.
  269. FileNameLength - Supplies the length of the file name buffer in bytes,
  270. including the null terminator.
  271. FilePhysical - Supplies a pointer to the buffer containing the file
  272. contents.
  273. FileSize - Supplies the size of the file buffer in bytes. The file will be
  274. truncated to this size if it previously existed and was larger.
  275. ModificationDate - Supplies the modification date to set.
  276. Return Value:
  277. Status code.
  278. --*/