bconf.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. bconf.h
  9. Abstract:
  10. This header contains definitions for the Boot Configuration Library.
  11. Author:
  12. Evan Green 20-Feb-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // Define the size of the disk and partition identifiers in a boot entry.
  22. //
  23. #define BOOT_DISK_ID_SIZE 16
  24. #define BOOT_PARTITION_ID_SIZE 16
  25. //
  26. // Define boot entry flags.
  27. //
  28. //
  29. // Set this flag to enable kernel debugging in the entry.
  30. //
  31. #define BOOT_ENTRY_FLAG_DEBUG 0x0000000000000001ULL
  32. //
  33. // Set this flag to enable boot debugging in the entry (debugging of the OS
  34. // loader.
  35. //
  36. #define BOOT_ENTRY_FLAG_BOOT_DEBUG 0x0000000000000002ULL
  37. //
  38. // Define the name of the boot configuration file.
  39. //
  40. #define BOOT_CONFIGURATION_FILE_NAME "bootconf"
  41. //
  42. // Define the path of the boot configuration file.
  43. //
  44. #define BOOT_CONFIGURATION_FILE_PATH "/EFI/MINOCA/"
  45. //
  46. // Define the absolute path to the boot configuration file.
  47. //
  48. #define BOOT_CONFIGURATION_ABSOLUTE_PATH \
  49. BOOT_CONFIGURATION_FILE_PATH BOOT_CONFIGURATION_FILE_NAME
  50. //
  51. // Define the default boot entry name.
  52. //
  53. #define BOOT_DEFAULT_NAME "Minoca OS"
  54. //
  55. // Define the default boot entry timeout value, in milliseconds.
  56. //
  57. #define BOOT_DEFAULT_TIMEOUT 0
  58. //
  59. // Define the default loader path, relative to the system root.
  60. //
  61. #define BOOT_DEFAULT_LOADER_PATH "system/loadefi"
  62. //
  63. // Define the default kernel path, relative to the system root.
  64. //
  65. #define BOOT_DEFAULT_KERNEL_PATH "system/kernel"
  66. //
  67. // Define the default system root, relative to the root file system on the
  68. // specified partition.
  69. //
  70. #define BOOT_DEFAULT_SYSTEM_PATH "minoca"
  71. //
  72. // ------------------------------------------------------ Data Type Definitions
  73. //
  74. //
  75. // Define functions called by the partition library.
  76. //
  77. typedef
  78. PVOID
  79. (*PBOOT_CONFIGURATION_ALLOCATE) (
  80. UINTN Size
  81. );
  82. /*++
  83. Routine Description:
  84. This routine is called when the boot configuration library needs to
  85. allocate memory.
  86. Arguments:
  87. Size - Supplies the size of the allocation request, in bytes.
  88. Return Value:
  89. Returns a pointer to the allocation if successful, or NULL if the
  90. allocation failed.
  91. --*/
  92. typedef
  93. VOID
  94. (*PBOOT_CONFIGURATION_FREE) (
  95. PVOID Memory
  96. );
  97. /*++
  98. Routine Description:
  99. This routine is called when the boot configuration library needs to free
  100. allocated memory.
  101. Arguments:
  102. Memory - Supplies the allocation returned by the allocation routine.
  103. Return Value:
  104. None.
  105. --*/
  106. /*++
  107. Structure Description:
  108. This structure stores information about a bootable entry in the
  109. configuration.
  110. Members:
  111. Id - Stores the ID of this boot entry. The boot configuration library
  112. numbers boot entries when they're written, so this value may change
  113. across a write of the boot configuration file.
  114. DiskId - Stores the identifier of the disk this boot entry lives on.
  115. PartitionId - Stores the identifier of the partition this boot entry lives
  116. on.
  117. Name - Stores a pointer to a string containing the descriptive name for
  118. this boot entry.
  119. LoaderArguments - Stores a pointer to a string containing the arguments to
  120. pass to the loader.
  121. KernelArguments - Stores a pointer to a string containing the arguments to
  122. pass to the kernel.
  123. LoaderPath - Stores a pointer to a string containing the path to the loader,
  124. relative to the system path.
  125. KernelPath - Stores a pointer to a string containing the path to the kernel,
  126. relative to the system path.
  127. SystemPath - Stores a pointer to a string containing the OS root directory.
  128. Flags - Stores a bitfield of flags. See BOOT_ENTRY_FLAG_* definitions.
  129. DebugDevice - Stores the zero-based index of the debug device to use. This
  130. is an index into the array of successfully enumerated debug interfaces.
  131. --*/
  132. typedef struct _BOOT_ENTRY {
  133. ULONG Id;
  134. UCHAR DiskId[BOOT_DISK_ID_SIZE];
  135. UCHAR PartitionId[BOOT_PARTITION_ID_SIZE];
  136. PCSTR Name;
  137. PCSTR LoaderArguments;
  138. PCSTR KernelArguments;
  139. PCSTR LoaderPath;
  140. PCSTR KernelPath;
  141. PCSTR SystemPath;
  142. ULONGLONG Flags;
  143. ULONG DebugDevice;
  144. } BOOT_ENTRY, *PBOOT_ENTRY;
  145. /*++
  146. Structure Description:
  147. This structure stores information about global boot configuration.
  148. Members:
  149. Key - Stores the previous configuration key. This value is incremented
  150. before being written to the file.
  151. DefaultBootEntry - Stores a pointer to the default boot entry.
  152. BootOnce - Stores a pointer to a boot entry to run once on the next boot.
  153. On subsequent boots the default switches back to the default boot entry.
  154. Timeout - Stores the boot menu timeout, in milliseconds. Set this to 0 to
  155. pick the default entry automatically. Set this to -1 to never time out
  156. and force the user to choose.
  157. --*/
  158. typedef struct _BOOT_CONFIGURATION_GLOBAL {
  159. ULONG Key;
  160. PBOOT_ENTRY DefaultBootEntry;
  161. PBOOT_ENTRY BootOnce;
  162. ULONG Timeout;
  163. } BOOT_CONFIGURATION_GLOBAL, *PBOOT_CONFIGURATION_GLOBAL;
  164. /*++
  165. Structure Description:
  166. This structure stores information about a boot configuration context.
  167. Members:
  168. AllocateFunction - Stores a pointer to a function the library uses to
  169. allocate memory.
  170. FreeFunction - Stores a pointer to a function the library uses to free
  171. previously allocated memory.
  172. FileData - Stores a pointer to the raw file data. This memory must be
  173. initialized by the consumer of the library. The library will use the
  174. free routine to free it upon changing the boot configuration file.
  175. FileDataSize - Stores the size of the raw file data in bytes. This value
  176. must be initialized by the consumer of the library. The library will
  177. update this value if new configuration data is written out.
  178. BootEntries - Stores an array of pointers to boot entries.
  179. BootEntryCount - Stores the number of entries in the boot entry array.
  180. --*/
  181. typedef struct _BOOT_CONFIGURATION_CONTEXT {
  182. PBOOT_CONFIGURATION_ALLOCATE AllocateFunction;
  183. PBOOT_CONFIGURATION_FREE FreeFunction;
  184. PVOID FileData;
  185. ULONG FileDataSize;
  186. BOOT_CONFIGURATION_GLOBAL GlobalConfiguration;
  187. PBOOT_ENTRY *BootEntries;
  188. ULONG BootEntryCount;
  189. } BOOT_CONFIGURATION_CONTEXT, *PBOOT_CONFIGURATION_CONTEXT;
  190. //
  191. // -------------------------------------------------------------------- Globals
  192. //
  193. //
  194. // -------------------------------------------------------- Function Prototypes
  195. //
  196. KSTATUS
  197. BcInitializeContext (
  198. PBOOT_CONFIGURATION_CONTEXT Context
  199. );
  200. /*++
  201. Routine Description:
  202. This routine initializes the given boot configuration context.
  203. Arguments:
  204. Context - Supplies a pointer to the context to initialize. The caller must
  205. have filled in the allocate and free functions, optionally filled in
  206. the file data, and zeroed the rest of the structure.
  207. Return Value:
  208. Status code.
  209. --*/
  210. VOID
  211. BcDestroyContext (
  212. PBOOT_CONFIGURATION_CONTEXT Context
  213. );
  214. /*++
  215. Routine Description:
  216. This routine destroys the given boot configuration context. It will free
  217. all resources contained in the structure, including the file data.
  218. Arguments:
  219. Context - Supplies a pointer to the context to destroy.
  220. Return Value:
  221. None.
  222. --*/
  223. VOID
  224. BcDestroyBootEntry (
  225. PBOOT_CONFIGURATION_CONTEXT Context,
  226. PBOOT_ENTRY Entry
  227. );
  228. /*++
  229. Routine Description:
  230. This routine destroys the given boot entry, freeing all its resources.
  231. Arguments:
  232. Context - Supplies a pointer to the context containing the entry.
  233. Entry - Supplies a pointer to the entry to destroy.
  234. Return Value:
  235. None.
  236. --*/
  237. KSTATUS
  238. BcReadBootConfigurationFile (
  239. PBOOT_CONFIGURATION_CONTEXT Context
  240. );
  241. /*++
  242. Routine Description:
  243. This routine parses the boot configuration file out into boot entries that
  244. can be manipulated by consumers of this library.
  245. Arguments:
  246. Context - Supplies a pointer to the context. The file data and file data
  247. size must have been filled in by the caller.
  248. Return Value:
  249. Status code.
  250. --*/
  251. KSTATUS
  252. BcWriteBootConfigurationFile (
  253. PBOOT_CONFIGURATION_CONTEXT Context
  254. );
  255. /*++
  256. Routine Description:
  257. This routine writes the boot entries into the file buffer.
  258. Arguments:
  259. Context - Supplies a pointer to the context. If there is existing file
  260. data it will be freed, and new file data will be allocated.
  261. Return Value:
  262. Status code.
  263. --*/
  264. KSTATUS
  265. BcCreateDefaultBootConfiguration (
  266. PBOOT_CONFIGURATION_CONTEXT Context,
  267. UCHAR DiskId[BOOT_DISK_ID_SIZE],
  268. UCHAR PartitionId[BOOT_PARTITION_ID_SIZE]
  269. );
  270. /*++
  271. Routine Description:
  272. This routine sets up the boot configuration data, creating a single default
  273. entry.
  274. Arguments:
  275. Context - Supplies a pointer to the boot configuration context.
  276. DiskId - Supplies the disk ID of the boot entry.
  277. PartitionId - Supplies the partition ID of the boot entry.
  278. Return Value:
  279. Returns a pointer to the new boot entry on success.
  280. NULL on allocation failure.
  281. --*/
  282. PBOOT_ENTRY
  283. BcCreateDefaultBootEntry (
  284. PBOOT_CONFIGURATION_CONTEXT Context,
  285. PSTR Name,
  286. UCHAR DiskId[BOOT_DISK_ID_SIZE],
  287. UCHAR PartitionId[BOOT_PARTITION_ID_SIZE]
  288. );
  289. /*++
  290. Routine Description:
  291. This routine creates a new boot entry with the default values.
  292. Arguments:
  293. Context - Supplies a pointer to the boot configuration context.
  294. Name - Supplies an optional pointer to a string containing the name of the
  295. entry. A copy of this string will be made. If no name is supplied, a
  296. default name will be used.
  297. DiskId - Supplies the disk ID of the boot entry.
  298. PartitionId - Supplies the partition ID of the boot entry.
  299. Return Value:
  300. Returns a pointer to the new boot entry on success.
  301. NULL on allocation failure.
  302. --*/
  303. PBOOT_ENTRY
  304. BcCopyBootEntry (
  305. PBOOT_CONFIGURATION_CONTEXT Context,
  306. PBOOT_ENTRY Source
  307. );
  308. /*++
  309. Routine Description:
  310. This routine creates a new boot entry based on an existing one.
  311. Arguments:
  312. Context - Supplies a pointer to the boot configuration context.
  313. Source - Supplies a pointer to the boot entry to copy.
  314. Return Value:
  315. Returns a pointer to the new boot entry on success.
  316. NULL on allocation failure.
  317. --*/