OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
LinuxBootInternal.h
Go to the documentation of this file.
1
6#ifndef LINUX_BOOT_INTERNAL_H
7#define LINUX_BOOT_INTERNAL_H
8
9/*
10 Standard attached drives on OVMF appear as MBR, so it can be convenient when
11 debugging to allow entries with incorrect (i.e. specifies no/every drive)
12 root=... .
13*/
14// #define LINUX_ALLOW_MBR
15
16#include <Uefi.h>
18#include <Library/OcMiscLib.h>
19
20#define IS_DIGIT(c) ((c) >= '0' && (c) <= '9')
21#define IS_ALPHA(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
22
23/*
24 Allow scan of ESP.
25*/
26#define LINUX_BOOT_SCAN_ESP BIT0
27
28/*
29 Allow scan of XBOOTLDR.
30*/
31#define LINUX_BOOT_SCAN_XBOOTLDR BIT1
32
33/*
34 Allow scan of Linux Root filesystems.
35*/
36#define LINUX_BOOT_SCAN_LINUX_ROOT BIT2
37
38/*
39 Allow scan of Linux Data filesystems.
40*/
41#define LINUX_BOOT_SCAN_LINUX_DATA BIT3
42
43/*
44 Some space for additional file systems.
45*/
46/*
47 Allow scan of any filesystem not explicitly mentioned
48 (including but not limited FAT other than ESP, and NTFS).
49*/
50#define LINUX_BOOT_SCAN_OTHER BIT7
51
52/*
53 Allow autodetect of vmlinuz-{version} and matching init*-{version},
54 if scan for usable /loader/entries fails.
55*/
56#define LINUX_BOOT_ALLOW_AUTODETECT BIT8
57
58/*
59 Define entry id by the first part (to dash) of the filename
60 from which it was created. Results in the first matching entry (after sorting)
61 always being the default entry, which results in updated Linux becoming the
62 new default automatically.
63*/
64#define LINUX_BOOT_USE_LATEST BIT9
65
66/*
67 If set, add "ro" as initial option to all distros. Can be specified per
68 FS by using argument autoopts:{partuuid}+=ro instead.
69*/
70#define LINUX_BOOT_ADD_RO BIT10
71
72/*
73 If set, add "rw" as initial option to all distros. Can be specified per
74 FS by using argument autoopts:{partuuid}+=rw instead.
75*/
76#define LINUX_BOOT_ADD_RW BIT11
77
78/*
79 TODO: (?) Both blspec-style and autodetect can make use of grub.cfg info if this flag is set.
80 These are currently parsed when needed for GRUB2+blscfg, i.e. if we find /loader/entries and /grub2/grub.cfg.
81*/
82// #define LINUX_BOOT_ALLOW_PARSE_GRUB BIT12
83
84/*
85 Add root= option if missing in loader/entries *.conf options.
86*/
87#define LINUX_BOOT_ALLOW_CONF_AUTO_ROOT BIT13
88
89/*
90 Add some additional log info.
91*/
92#define LINUX_BOOT_LOG_VERBOSE BIT14
93
94/*
95 Prepend filesystem type and first 8 hex digits of PARTUUID to discovered
96 entry titles, to help in debugging where entries came from.
97*/
98#define LINUX_BOOT_ADD_DEBUG_INFO BIT15
99
100/*
101 Trace grub var processing.
102*/
103#define LINUX_BOOT_LOG_GRUB_VARS BIT16
104
105/*
106 Fix TuneD processing by initialising its grub variables if they are not present.
107*/
108#define LINUX_BOOT_FIX_TUNED BIT17
109
110#define LINUX_BOOT_ALL ( \
111 LINUX_BOOT_SCAN_ESP | \
112 LINUX_BOOT_SCAN_XBOOTLDR | \
113 LINUX_BOOT_SCAN_LINUX_ROOT | \
114 LINUX_BOOT_SCAN_LINUX_DATA | \
115 LINUX_BOOT_SCAN_OTHER | \
116 LINUX_BOOT_ALLOW_AUTODETECT | \
117 LINUX_BOOT_USE_LATEST | \
118 LINUX_BOOT_ADD_RO | \
119 LINUX_BOOT_ADD_RW | \
120 LINUX_BOOT_ALLOW_CONF_AUTO_ROOT | \
121 LINUX_BOOT_LOG_VERBOSE | \
122 LINUX_BOOT_ADD_DEBUG_INFO | \
123 LINUX_BOOT_LOG_GRUB_VARS | \
124 LINUX_BOOT_FIX_TUNED \
125 )
126
127/*
128 GRUB var error codes.
129*/
130#define VAR_ERR_NONE (0)
131#define VAR_ERR_INDENTED BIT0 // Naive detection of GRUB conditional logic
132#define VAR_ERR_HAS_VARS BIT1 // We do not support nested vars (in name or value), even though GRUB does
133
134/*
135 Global flags for this instance of OpenLinuxBoot.efi.
136*/
137extern UINTN gLinuxBootFlags;
138
139/*
140 Boot picker context.
141*/
143
144/*
145 The array of loader entries, either really from *.conf files or generated by autodetect.
146*/
148
149/*
150 The current partuuid.
151*/
152extern EFI_GUID gPartuuid;
153
154/*
155 Human readable ascii name of current file system type.
156*/
157extern CHAR8 *gFileSystemType;
158
159// TODO: Are all of the below types used outside a single file?
160// TODO: Is this file sensibly ordered?
161
162/*
163 Forward declaration of GRUB_VAR structure.
164*/
165typedef struct GRUB_VAR_ GRUB_VAR;
166
167/*
168 Forward declaration of LOADER_ENTRY structure.
169*/
171
172/*
173 GRUB vars.
174*/
175EFI_STATUS
177 VOID
178 );
179
180VOID
182 VOID
183 );
184
185EFI_STATUS
187 CHAR8 *Key,
188 CHAR8 *Value,
189 UINTN Errors
190 );
191
192BOOLEAN
194 CHAR8 *Options
195 );
196
197GRUB_VAR *
199 IN CONST CHAR8 *Key
200 );
201
202EFI_STATUS
204 IN OUT OC_FLEX_ARRAY *Options
205 );
206
207EFI_STATUS
209 IN CONST CHAR8 *Options,
210 IN OUT CHAR8 **Result
211 );
212
213/*
214 Process grubenv file.
215*/
216EFI_STATUS
218 IN OUT CHAR8 *Content,
219 IN CONST UINTN Length
220 );
221
222/*
223 Process grub.cfg file.
224*/
225EFI_STATUS
227 IN OUT CHAR8 *Content
228 );
229
232 VOID
233 );
234
235VOID
237 LOADER_ENTRY *Entry
238 );
239
240EFI_STATUS
242 IN CONST CHAR16 *FileName,
243 IN OUT CHAR8 *Content,
244 OUT LOADER_ENTRY *Entry,
245 IN CONST BOOLEAN Grub2
246 );
247
248/*
249 GRUB variable.
250*/
251struct GRUB_VAR_ {
252 //
253 // Points within loaded file memory.
254 //
255 CHAR8 *Key;
256 //
257 // Points within loaded file memory, may be empty string.
258 //
259 CHAR8 *Value;
260 //
261 // GRUB var error code flags.
262 //
263 UINTN Errors;
264};
265
266/*
267 Loader entries.
268*/
269
270VOID
272 IN OC_PICKER_ENTRY *Entry
273 );
274
275EFI_STATUS
277 IN EFI_FILE_PROTOCOL *RootDirectory,
278 OUT OC_PICKER_ENTRY **Entries,
279 OUT UINTN *NumEntries
280 );
281
282EFI_STATUS
284 IN EFI_FILE_PROTOCOL *RootDirectory,
285 OUT OC_PICKER_ENTRY **Entries,
286 OUT UINTN *NumEntries
287 );
288
289EFI_STATUS
291 IN OUT LOADER_ENTRY *Entry,
292 IN CHAR16 *FileName
293 );
294
295/*
296 BLSpec / blscfg loader entry.
297 Some items within here probably don't need to be allocated and could stay
298 pointing within the source file as long as that is in memory (specifically
299 Version and Linux, which are probably never going to be modified), but to
300 keep things sane everything is (re)allocated.
301*/
303 //
304 // Version.
305 // Must come first since used for sorting.
306 //
307 CHAR8 *Version;
308 //
309 // Title.
310 //
311 CHAR8 *Title;
312 //
313 // Linux kernel filename.
314 //
315 CHAR8 *Linux;
316 //
317 // Options.
318 //
320 //
321 // Initrds.
322 //
324 //
325 // OpenCore entry id.
326 // 'id' line is not read from .conf files even if present.
327 //
328 CHAR8 *OcId;
329 //
330 // Flavour.
331 //
332 CHAR8 *OcFlavour;
333 //
334 // Is this an auxiliary entry for OpenCore?
335 //
336 BOOLEAN OcAuxiliary;
337 //
338 // Has this already been scanned whilst assigned main and auxiliary entries?
339 //
341};
342
343typedef struct VMLINUZ_FILE_ {
344 CHAR16 *FileName;
345 CHAR16 *Version;
346 UINTN StrLen;
348
349/*
350 Autodetect options.
351*/
352typedef struct AUTOOPTS_ {
353 EFI_GUID Guid;
354 CHAR16 *Opts;
355 BOOLEAN PlusOpts;
357
358/*
359 Load autoopts.
360*/
361EFI_STATUS
363 IN OC_FLEX_ARRAY *Options
364 );
365
366/*
367 Autodetect.
368*/
369EFI_STATUS
371 IN EFI_FILE_PROTOCOL *RootDirectory,
372 OUT OC_PICKER_ENTRY **Entries,
373 OUT UINTN *NumEntries
374 );
375
376/*
377 Insert root=PARTUUID=... option.
378*/
379EFI_STATUS
381 IN OC_FLEX_ARRAY *Options
382 );
383
384/*
385 Sorts versions low to high.
386*/
387INTN
388EFIAPI
390 IN CONST VOID *Version1,
391 IN CONST VOID *Version2
392 );
393
394/*
395 Sorts versions high to low.
396*/
397INTN
398EFIAPI
400 IN CONST VOID *Version1,
401 IN CONST VOID *Version2
402 );
403
404#endif // LINUX_BOOT_INTERNAL_H
UINT64 Length
INTN EFIAPI InternalVersionCompare(IN CONST VOID *Version1, IN CONST VOID *Version2)
struct AUTOOPTS_ AUTOOPTS
struct VMLINUZ_FILE_ VMLINUZ_FILE
EFI_STATUS InternalScanLoaderEntries(IN EFI_FILE_PROTOCOL *RootDirectory, OUT OC_PICKER_ENTRY **Entries, OUT UINTN *NumEntries)
EFI_STATUS InternalInitGrubVars(VOID)
Definition GrubVars.c:21
OC_FLEX_ARRAY * gLoaderEntries
EFI_GUID gPartuuid
VOID InternalFreePickerEntry(IN OC_PICKER_ENTRY *Entry)
EFI_STATUS InternalSetGrubVar(CHAR8 *Key, CHAR8 *Value, UINTN Errors)
Definition GrubVars.c:44
UINTN gLinuxBootFlags
EFI_STATUS InternalConvertLoaderEntriesToBootEntries(IN EFI_FILE_PROTOCOL *RootDirectory, OUT OC_PICKER_ENTRY **Entries, OUT UINTN *NumEntries)
EFI_STATUS InsertRootOption(IN OC_FLEX_ARRAY *Options)
Definition Autodetect.c:444
EFI_STATUS InternalProcessGrubEnv(IN OUT CHAR8 *Content, IN CONST UINTN Length)
Definition GrubEnv.c:23
EFI_STATUS InternalAutodetectLinux(IN EFI_FILE_PROTOCOL *RootDirectory, OUT OC_PICKER_ENTRY **Entries, OUT UINTN *NumEntries)
CHAR8 * gFileSystemType
VOID InternalFreeLoaderEntry(LOADER_ENTRY *Entry)
EFI_STATUS InternalExpandGrubVars(IN CONST CHAR8 *Options, IN OUT CHAR8 **Result)
Definition GrubVars.c:172
INTN EFIAPI InternalReverseVersionCompare(IN CONST VOID *Version1, IN CONST VOID *Version2)
OC_PICKER_CONTEXT * gPickerContext
VOID InternalFreeGrubVars(VOID)
Definition GrubVars.c:34
EFI_STATUS InternalPreloadAutoOpts(IN OC_FLEX_ARRAY *Options)
Definition Autodetect.c:489
LOADER_ENTRY * InternalAllocateLoaderEntry(VOID)
EFI_STATUS InternalProcessGrubCfg(IN OUT CHAR8 *Content)
Definition GrubCfg.c:398
EFI_STATUS InternalIdVersionFromFileName(IN OUT LOADER_ENTRY *Entry, IN CHAR16 *FileName)
GRUB_VAR * InternalGetGrubVar(IN CONST CHAR8 *Key)
Definition GrubVars.c:128
EFI_STATUS InternalExpandGrubVarsForArray(IN OUT OC_FLEX_ARRAY *Options)
Definition GrubVars.c:146
BOOLEAN InternalHasGrubVars(CHAR8 *Options)
Definition GrubVars.c:120
EFI_STATUS InternalProcessLoaderEntryFile(IN CONST CHAR16 *FileName, IN OUT CHAR8 *Content, OUT LOADER_ENTRY *Entry, IN CONST BOOLEAN Grub2)
OC_FLEX_ARRAY * Initrds
OC_FLEX_ARRAY * Options