5 * Copyright (c) 2006-2009 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
37 * Modifications copyright (c) 2012-2013 Roderick W. Smith
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.
48 #ifdef __MAKEWITH_GNUEFI
52 #include "../include/tiano_includes.h"
53 #include "../EfiLib/GenericBdsLib.h"
58 #define REFIT_DEBUG (0)
60 // Tag classifications; used in various ways.
62 #define TAG_REBOOT (2)
63 #define TAG_SHUTDOWN (3)
65 #define TAG_LOADER (5)
66 #define TAG_LEGACY (6)
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 NUM_TOOLS (16)
78 #define NUM_SCAN_OPTIONS 10
80 #define DEFAULT_ICONS_DIR L"icons"
82 // OS bit codes; used in GlobalConfig.GraphicsOn
83 #define GRAPHICS_FOR_OSX 1
84 #define GRAPHICS_FOR_LINUX 2
85 #define GRAPHICS_FOR_ELILO 4
86 #define GRAPHICS_FOR_GRUB 8
87 #define GRAPHICS_FOR_WINDOWS 16
89 // Type of legacy (BIOS) boot support detected
90 #define LEGACY_TYPE_NONE 0
91 #define LEGACY_TYPE_MAC 1
92 #define LEGACY_TYPE_UEFI 2
94 #ifdef __MAKEWITH_GNUEFI
96 // define BBS Device Types
98 #define BBS_FLOPPY 0x01
99 #define BBS_HARDDISK 0x02
100 #define BBS_CDROM 0x03
101 #define BBS_PCMCIA 0x04
103 #define BBS_EMBED_NETWORK 0x06
104 #define BBS_BEV_DEVICE 0x80
105 #define BBS_UNKNOWN 0xff
108 // BIOS Boot Specification (BBS) device types, as returned in DevicePath->Type field
109 #define DEVICE_TYPE_HW 0x01
110 #define DEVICE_TYPE_ACPI 0x02 /* returned by UEFI boot loader on USB */
111 #define DEVICE_TYPE_MESSAGING 0x03
112 #define DEVICE_TYPE_MEDIA 0x04 /* returned by EFI boot loaders on hard disk */
113 #define DEVICE_TYPE_BIOS 0x05 /* returned by legacy (BIOS) boot loaders */
114 #define DEVICE_TYPE_END 0x75 /* end of path */
116 // Filesystem type identifiers. Not all are yet used....
117 #define FS_TYPE_UNKNOWN 0
118 #define FS_TYPE_FAT 1
119 #define FS_TYPE_EXT2 2
120 #define FS_TYPE_EXT3 3
121 #define FS_TYPE_EXT4 4
122 #define FS_TYPE_HFSPLUS 5
123 #define FS_TYPE_REISERFS 6
124 #define FS_TYPE_BTRFS 7
125 #define FS_TYPE_ISO9660 8
127 // How to scale banner images
128 #define BANNER_NOSCALE 0
129 #define BANNER_FILLSCREEN 1
131 // Names of binaries that can manage MOKs....
132 #define MOK_NAMES L"MokManager.efi,HashTool.efi,HashTool-signed.efi"
133 // Directories to search for these MOK-managing programs. Note that SelfDir is
134 // searched in addition to these locations....
135 #define MOK_LOCATIONS L"\\,EFI\\tools,EFI\\fedora,EFI\\redhat,EFI\\ubuntu,EFI\\suse,EFI\\opensuse,EFI\\altlinux"
136 // Directories to search for memtest86....
137 #define MEMTEST_LOCATIONS L"EFI\\tools,EFI\\tools\\memtest86,EFI\\tools\\memtest,EFI\\memtest86,EFI\\memtest"
138 // Files that may be Windows recovery files
139 #define WINDOWS_RECOVERY_FILES L"EFI\\Microsoft\\Boot\\LrsBootmgr.efi"
142 // global definitions
158 } MBR_PARTITION_INFO
;
161 EFI_DEVICE_PATH
*DevicePath
;
162 EFI_HANDLE DeviceHandle
;
167 EG_IMAGE
*VolIconImage
;
168 EG_IMAGE
*VolBadgeImage
;
170 BOOLEAN IsAppleLegacy
;
174 BOOLEAN IsMbrPartition
;
175 UINTN MbrPartitionIndex
;
176 EFI_BLOCK_IO
*BlockIO
;
177 UINT64 BlockIOOffset
;
178 EFI_BLOCK_IO
*WholeDiskBlockIO
;
179 EFI_DEVICE_PATH
*WholeDiskDevicePath
;
180 MBR_PARTITION_INFO
*MbrPartitionTable
;
185 typedef struct _refit_menu_entry
{
189 CHAR16 ShortcutDigit
;
190 CHAR16 ShortcutLetter
;
192 EG_IMAGE
*BadgeImage
;
193 struct _refit_menu_screen
*SubScreen
;
196 typedef struct _refit_menu_screen
{
198 EG_IMAGE
*TitleImage
;
201 UINTN EntryCount
; // total number of entries registered
202 REFIT_MENU_ENTRY
**Entries
;
203 UINTN TimeoutSeconds
;
214 EFI_DEVICE_PATH
*DevicePath
;
215 BOOLEAN UseGraphicsMode
;
218 CHAR16
*InitrdPath
; // Linux stub loader only
224 REFIT_VOLUME
*Volume
;
225 #ifndef __MAKEWITH_GNUEFI
226 BDS_COMMON_OPTION
*BdsOption
;
234 BOOLEAN ScanAllLinux
;
235 UINTN RequestedScreenWidth
;
236 UINTN RequestedScreenHeight
;
237 UINTN BannerBottomEdge
;
238 UINTN RequestedTextMode
;
241 UINTN MaxTags
; // max. number of OS entries to show simultaneously in graphics mode
245 UINTN ScreensaverTime
;
247 CHAR16
*BannerFileName
;
248 EG_IMAGE
*ScreenBackground
;
249 CHAR16
*ConfigFilename
;
250 CHAR16
*SelectionSmallFileName
;
251 CHAR16
*SelectionBigFileName
;
252 CHAR16
*DefaultSelection
;
254 CHAR16
*DontScanVolumes
;
255 CHAR16
*DontScanDirs
;
256 CHAR16
*DontScanFiles
;
257 CHAR16
*WindowsRecoveryFiles
;
260 UINTN ShowTools
[NUM_TOOLS
];
261 CHAR8 ScanFor
[NUM_SCAN_OPTIONS
]; // codes of types of loaders for which to scan
266 extern EFI_HANDLE SelfImageHandle
;
267 extern EFI_LOADED_IMAGE
*SelfLoadedImage
;
268 extern EFI_FILE
*SelfRootDir
;
269 extern EFI_FILE
*SelfDir
;
270 extern CHAR16
*SelfDirPath
;
272 extern REFIT_VOLUME
*SelfVolume
;
273 extern REFIT_VOLUME
**Volumes
;
274 extern UINTN VolumesCount
;
276 extern REFIT_CONFIG GlobalConfig
;
278 extern EFI_GUID gEfiLegacyBootProtocolGuid
;
279 extern EFI_GUID gEfiGlobalVariableGuid
;
281 LOADER_ENTRY
*InitializeLoaderEntry(IN LOADER_ENTRY
*Entry
);
282 REFIT_MENU_SCREEN
*InitializeSubScreen(IN LOADER_ENTRY
*Entry
);
283 VOID
GenerateSubScreen(LOADER_ENTRY
*Entry
, IN REFIT_VOLUME
*Volume
);
284 LOADER_ENTRY
* MakeGenericLoaderEntry(VOID
);
285 LOADER_ENTRY
* AddLoaderEntry(IN CHAR16
*LoaderPath
, IN CHAR16
*LoaderTitle
, IN REFIT_VOLUME
*Volume
);
286 VOID
SetLoaderDefaults(LOADER_ENTRY
*Entry
, CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
);
287 LOADER_ENTRY
* AddPreparedLoaderEntry(LOADER_ENTRY
*Entry
);