]> code.delx.au - refind/blob - refind/global.h
a07e0c90d74f4815e00dcecf942f8fdb77f49de7
[refind] / refind / global.h
1 /*
2 * refit/global.h
3 * Global header file
4 *
5 * Copyright (c) 2006-2009 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 /*
37 * Modifications copyright (c) 2012-2015 Roderick W. Smith
38 *
39 * Modifications distributed under the terms of the GNU General Public
40 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
41 * with this source code or binaries made from it.
42 *
43 */
44
45 #ifndef __GLOBAL_H_
46 #define __GLOBAL_H_
47
48 #ifdef __MAKEWITH_GNUEFI
49 #include <efi.h>
50 #include <efilib.h>
51 #else
52 #include "../include/tiano_includes.h"
53 #endif
54 #include "../EfiLib/GenericBdsLib.h"
55
56 #include "libeg.h"
57
58 #define REFIT_DEBUG (0)
59
60 // Tag classifications; used in various ways.
61 #define TAG_ABOUT (1)
62 #define TAG_REBOOT (2)
63 #define TAG_SHUTDOWN (3)
64 #define TAG_TOOL (4)
65 #define TAG_LOADER (5)
66 #define TAG_LEGACY (6)
67 #define TAG_EXIT (7)
68 #define TAG_SHELL (8)
69 #define TAG_GPTSYNC (9)
70 #define TAG_LEGACY_UEFI (10)
71 #define TAG_APPLE_RECOVERY (11)
72 #define TAG_WINDOWS_RECOVERY (12)
73 #define TAG_MOK_TOOL (13)
74 #define TAG_FIRMWARE (14)
75 #define TAG_MEMTEST (15)
76 #define TAG_GDISK (16)
77 #define TAG_NETBOOT (17)
78 #define TAG_CSR_ROTATE (18)
79 #define NUM_TOOLS (19)
80
81 #define NUM_SCAN_OPTIONS 10
82
83 #define DEFAULT_ICONS_DIR L"icons"
84
85 // OS bit codes; used in GlobalConfig.GraphicsOn
86 #define GRAPHICS_FOR_OSX 1
87 #define GRAPHICS_FOR_LINUX 2
88 #define GRAPHICS_FOR_ELILO 4
89 #define GRAPHICS_FOR_GRUB 8
90 #define GRAPHICS_FOR_WINDOWS 16
91
92 // Load types
93 #define TYPE_EFI 1
94 #define TYPE_LEGACY 2
95
96 // Type of legacy (BIOS) boot support detected
97 #define LEGACY_TYPE_NONE 0
98 #define LEGACY_TYPE_MAC 1
99 #define LEGACY_TYPE_UEFI 2
100
101 #ifdef __MAKEWITH_GNUEFI
102 //
103 // define BBS Device Types
104 //
105 #define BBS_FLOPPY 0x01
106 #define BBS_HARDDISK 0x02
107 #define BBS_CDROM 0x03
108 #define BBS_PCMCIA 0x04
109 #define BBS_USB 0x05
110 #define BBS_EMBED_NETWORK 0x06
111 #define BBS_BEV_DEVICE 0x80
112 #define BBS_UNKNOWN 0xff
113 #endif
114
115 // BIOS Boot Specification (BBS) device types, as returned in DevicePath->Type field
116 #define DEVICE_TYPE_HW 0x01
117 #define DEVICE_TYPE_ACPI 0x02 /* returned by UEFI boot loader on USB */
118 #define DEVICE_TYPE_MESSAGING 0x03
119 #define DEVICE_TYPE_MEDIA 0x04 /* returned by EFI boot loaders on hard disk */
120 #define DEVICE_TYPE_BIOS 0x05 /* returned by legacy (BIOS) boot loaders */
121 #define DEVICE_TYPE_END 0x75 /* end of path */
122
123 // Filesystem type identifiers. Not all are yet used....
124 #define FS_TYPE_UNKNOWN 0
125 #define FS_TYPE_WHOLEDISK 1
126 #define FS_TYPE_FAT 2
127 #define FS_TYPE_EXFAT 3
128 #define FS_TYPE_NTFS 4
129 #define FS_TYPE_EXT2 5
130 #define FS_TYPE_EXT3 6
131 #define FS_TYPE_EXT4 7
132 #define FS_TYPE_HFSPLUS 8
133 #define FS_TYPE_REISERFS 9
134 #define FS_TYPE_BTRFS 10
135 #define FS_TYPE_XFS 11
136 #define FS_TYPE_ISO9660 12
137
138 // How to scale banner images
139 #define BANNER_NOSCALE 0
140 #define BANNER_FILLSCREEN 1
141
142 // Sizes of the default icons; badges are 1/4 the big icon size
143 #define DEFAULT_SMALL_ICON_SIZE 48
144 #define DEFAULT_BIG_ICON_SIZE 128
145
146 // Codes for types of icon sizes; used for indexing into GlobalConfig.IconSizes[]
147 #define ICON_SIZE_BADGE 0
148 #define ICON_SIZE_SMALL 1
149 #define ICON_SIZE_BIG 2
150
151 // The constants related to Apple's System Integrity Protection (SIP)....
152 #define CSR_GUID { 0x7c436110, 0xab2a, 0x4bbb, { 0xa8, 0x80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82 } };
153 // These codes are returned in the first byte of the csr-active-config variable
154 #define CSR_ALLOW_UNTRUSTED_KEXTS 0x01
155 #define CSR_ALLOW_UNRESTRICTED_FS 0x02
156 #define CSR_ALLOW_TASK_FOR_PID 0x04
157 #define CSR_ALLOW_KERNEL_DEBUGGER 0x08
158 #define CSR_ALLOW_APPLE_INTERNAL 0x10
159 #define CSR_ALLOW_UNRESTRICTED_DTRACE 0x20
160 #define CSR_ALLOW_UNRESTRICTED_NVRAM 0x40
161 // Some summaries....
162 #define SIP_ENABLED CSR_ALLOW_APPLE_INTERNAL
163 #define SIP_DISABLED (CSR_ALLOW_UNRESTRICTED_NVRAM | \
164 CSR_ALLOW_UNRESTRICTED_DTRACE | \
165 CSR_ALLOW_APPLE_INTERNAL | \
166 CSR_ALLOW_TASK_FOR_PID | \
167 CSR_ALLOW_UNRESTRICTED_FS | \
168 CSR_ALLOW_UNTRUSTED_KEXTS)
169
170 // Names of binaries that can manage MOKs....
171 #define MOK_NAMES L"MokManager.efi,HashTool.efi,HashTool-signed.efi,KeyTool.efi,KeyTool-signed.efi"
172 // Directories to search for these MOK-managing programs. Note that SelfDir is
173 // searched in addition to these locations....
174 #define MOK_LOCATIONS L"\\,EFI\\tools,EFI\\fedora,EFI\\redhat,EFI\\ubuntu,EFI\\suse,EFI\\opensuse,EFI\\altlinux"
175 // Directories to search for memtest86....
176 #define MEMTEST_LOCATIONS L"EFI\\tools,EFI\\tools\\memtest86,EFI\\tools\\memtest,EFI\\memtest86,EFI\\memtest"
177 // Files that may be Windows recovery files
178 #define WINDOWS_RECOVERY_FILES L"EFI\\Microsoft\\Boot\\LrsBootmgr.efi,Recovery:\\EFI\\BOOT\\bootx64.efi,Recovery:\\EFI\\BOOT\\bootia32.efi"
179
180 // Definitions for the "hideui" option in refind.conf
181 #define HIDEUI_FLAG_NONE (0x0000)
182 #define HIDEUI_FLAG_BANNER (0x0001)
183 #define HIDEUI_FLAG_LABEL (0x0002)
184 #define HIDEUI_FLAG_SINGLEUSER (0x0004)
185 #define HIDEUI_FLAG_HWTEST (0x0008)
186 #define HIDEUI_FLAG_ARROWS (0x0010)
187 #define HIDEUI_FLAG_HINTS (0x0020)
188 #define HIDEUI_FLAG_EDITOR (0x0040)
189 #define HIDEUI_FLAG_SAFEMODE (0x0080)
190 #define HIDEUI_FLAG_BADGES (0x0100)
191 #define HIDEUI_FLAG_ALL ((0xffff))
192
193 // Default hint text for program-launch submenus
194 #define SUBSCREEN_HINT1 L"Use arrow keys to move cursor; Enter to boot;"
195 #define SUBSCREEN_HINT2 L"Insert or F2 to edit options; Esc to return to main menu"
196 #define SUBSCREEN_HINT2_NO_EDITOR L"Esc to return to main menu"
197
198 #define NULL_GUID_VALUE { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
199 #define REFIND_GUID_VALUE { 0x36D08FA7, 0xCF0B, 0x42F5, {0x8F, 0x14, 0x68, 0xDF, 0x73, 0xED, 0x37, 0x40} };
200
201 //
202 // global definitions
203 //
204
205 // global types
206
207 typedef struct {
208 UINT8 Flags;
209 UINT8 StartCHS1;
210 UINT8 StartCHS2;
211 UINT8 StartCHS3;
212 UINT8 Type;
213 UINT8 EndCHS1;
214 UINT8 EndCHS2;
215 UINT8 EndCHS3;
216 UINT32 StartLBA;
217 UINT32 Size;
218 } MBR_PARTITION_INFO;
219
220 typedef struct {
221 EFI_DEVICE_PATH *DevicePath;
222 EFI_HANDLE DeviceHandle;
223 EFI_FILE *RootDir;
224 CHAR16 *VolName;
225 CHAR16 *PartName;
226 EFI_GUID VolUuid;
227 EFI_GUID PartGuid;
228 EFI_GUID PartTypeGuid;
229 BOOLEAN IsMarkedReadOnly;
230 UINTN VolNumber;
231 EG_IMAGE *VolIconImage;
232 EG_IMAGE *VolBadgeImage;
233 UINTN DiskKind;
234 BOOLEAN IsAppleLegacy;
235 BOOLEAN HasBootCode;
236 CHAR16 *OSIconName;
237 CHAR16 *OSName;
238 BOOLEAN IsMbrPartition;
239 UINTN MbrPartitionIndex;
240 EFI_BLOCK_IO *BlockIO;
241 UINT64 BlockIOOffset;
242 EFI_BLOCK_IO *WholeDiskBlockIO;
243 EFI_DEVICE_PATH *WholeDiskDevicePath;
244 MBR_PARTITION_INFO *MbrPartitionTable;
245 BOOLEAN IsReadable;
246 UINT32 FSType;
247 } REFIT_VOLUME;
248
249 typedef struct _refit_menu_entry {
250 CHAR16 *Title;
251 UINTN Tag;
252 UINTN Row;
253 CHAR16 ShortcutDigit;
254 CHAR16 ShortcutLetter;
255 EG_IMAGE *Image;
256 EG_IMAGE *BadgeImage;
257 struct _refit_menu_screen *SubScreen;
258 } REFIT_MENU_ENTRY;
259
260 typedef struct _refit_menu_screen {
261 CHAR16 *Title;
262 EG_IMAGE *TitleImage;
263 UINTN InfoLineCount;
264 CHAR16 **InfoLines;
265 UINTN EntryCount; // total number of entries registered
266 REFIT_MENU_ENTRY **Entries;
267 UINTN TimeoutSeconds;
268 CHAR16 *TimeoutText;
269 CHAR16 *Hint1;
270 CHAR16 *Hint2;
271 } REFIT_MENU_SCREEN;
272
273 typedef struct {
274 REFIT_MENU_ENTRY me;
275 CHAR16 *Title;
276 CHAR16 *LoaderPath;
277 CHAR16 *VolName;
278 EFI_DEVICE_PATH *DevicePath;
279 BOOLEAN UseGraphicsMode;
280 BOOLEAN Enabled;
281 CHAR16 *LoadOptions;
282 CHAR16 *InitrdPath; // Linux stub loader only
283 CHAR8 OSType;
284 } LOADER_ENTRY;
285
286 typedef struct {
287 REFIT_MENU_ENTRY me;
288 REFIT_VOLUME *Volume;
289 BDS_COMMON_OPTION *BdsOption;
290 CHAR16 *LoadOptions;
291 BOOLEAN Enabled;
292 } LEGACY_ENTRY;
293
294 typedef struct {
295 BOOLEAN TextOnly;
296 BOOLEAN ScanAllLinux;
297 BOOLEAN DeepLegacyScan;
298 BOOLEAN EnableAndLockVMX;
299 BOOLEAN FoldLinuxKernels;
300 UINTN RequestedScreenWidth;
301 UINTN RequestedScreenHeight;
302 UINTN BannerBottomEdge;
303 UINTN RequestedTextMode;
304 UINTN Timeout;
305 UINTN HideUIFlags;
306 UINTN MaxTags; // max. number of OS entries to show simultaneously in graphics mode
307 UINTN GraphicsFor;
308 UINTN LegacyType;
309 UINTN ScanDelay;
310 UINTN ScreensaverTime;
311 UINTN IconSizes[3];
312 UINTN BannerScale;
313 REFIT_VOLUME *DiscoveredRoot;
314 EFI_DEVICE_PATH *SelfDevicePath;
315 CHAR16 *BannerFileName;
316 EG_IMAGE *ScreenBackground;
317 CHAR16 *ConfigFilename;
318 CHAR16 *SelectionSmallFileName;
319 CHAR16 *SelectionBigFileName;
320 CHAR16 *DefaultSelection;
321 CHAR16 *AlsoScan;
322 CHAR16 *DontScanVolumes;
323 CHAR16 *DontScanDirs;
324 CHAR16 *DontScanFiles;
325 CHAR16 *WindowsRecoveryFiles;
326 CHAR16 *DriverDirs;
327 CHAR16 *IconsDir;
328 CHAR16 *SpoofOSXVersion;
329 CHAR16 *CsrValues;
330 UINTN ShowTools[NUM_TOOLS];
331 CHAR8 ScanFor[NUM_SCAN_OPTIONS]; // codes of types of loaders for which to scan
332 } REFIT_CONFIG;
333
334 // Global variables
335
336 extern EFI_HANDLE SelfImageHandle;
337 extern EFI_LOADED_IMAGE *SelfLoadedImage;
338 extern EFI_FILE *SelfRootDir;
339 extern EFI_FILE *SelfDir;
340 extern CHAR16 *SelfDirPath;
341
342 extern REFIT_VOLUME *SelfVolume;
343 extern REFIT_VOLUME **Volumes;
344 extern UINTN VolumesCount;
345
346 extern REFIT_CONFIG GlobalConfig;
347
348 extern EFI_GUID gEfiLegacyBootProtocolGuid;
349 extern EFI_GUID gEfiGlobalVariableGuid;
350
351 EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
352 IN CHAR16 *LoadOptions, IN UINTN LoaderType,
353 IN CHAR16 *ImageTitle, IN CHAR8 OSType,
354 OUT UINTN *ErrorInStep,
355 IN BOOLEAN Verbose,
356 IN BOOLEAN IsDriver);
357 LOADER_ENTRY *InitializeLoaderEntry(IN LOADER_ENTRY *Entry);
358 REFIT_MENU_SCREEN *InitializeSubScreen(IN LOADER_ENTRY *Entry);
359 VOID GenerateSubScreen(LOADER_ENTRY *Entry, IN REFIT_VOLUME *Volume, IN BOOLEAN GenerateReturn);
360 EG_IMAGE * GetDiskBadge(IN UINTN DiskType);
361 LOADER_ENTRY * MakeGenericLoaderEntry(VOID);
362 VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME *Volume);
363 LOADER_ENTRY * AddPreparedLoaderEntry(LOADER_ENTRY *Entry);
364 VOID StoreLoaderName(IN CHAR16 *Name);
365
366 #endif
367
368 /* EOF */