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 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_MOK_TOOL (12)
73 #define TAG_FIRMWARE (13)
74 #define NUM_TOOLS (13)
76 #define NUM_SCAN_OPTIONS 10
78 #define DEFAULT_ICONS_DIR L"icons"
80 // OS bit codes; used in GlobalConfig.GraphicsOn
81 #define GRAPHICS_FOR_OSX 1
82 #define GRAPHICS_FOR_LINUX 2
83 #define GRAPHICS_FOR_ELILO 4
84 #define GRAPHICS_FOR_GRUB 8
85 #define GRAPHICS_FOR_WINDOWS 16
87 // Type of legacy (BIOS) boot support detected
88 #define LEGACY_TYPE_NONE 0
89 #define LEGACY_TYPE_MAC 1
90 #define LEGACY_TYPE_UEFI 2
92 #ifdef __MAKEWITH_GNUEFI
94 // define BBS Device Types
96 #define BBS_FLOPPY 0x01
97 #define BBS_HARDDISK 0x02
98 #define BBS_CDROM 0x03
99 #define BBS_PCMCIA 0x04
101 #define BBS_EMBED_NETWORK 0x06
102 #define BBS_BEV_DEVICE 0x80
103 #define BBS_UNKNOWN 0xff
106 // BIOS Boot Specification (BBS) device types, as returned in DevicePath->Type field
107 #define DEVICE_TYPE_HW 0x01
108 #define DEVICE_TYPE_ACPI 0x02 /* returned by UEFI boot loader on USB */
109 #define DEVICE_TYPE_MESSAGING 0x03
110 #define DEVICE_TYPE_MEDIA 0x04 /* returned by EFI boot loaders on hard disk */
111 #define DEVICE_TYPE_BIOS 0x05 /* returned by legacy (BIOS) boot loaders */
112 #define DEVICE_TYPE_END 0x75 /* end of path */
114 // Filesystem type identifiers. Not all are yet used....
115 #define FS_TYPE_UNKNOWN 0
116 #define FS_TYPE_FAT 1
117 #define FS_TYPE_EXT2 2
118 #define FS_TYPE_EXT3 3
119 #define FS_TYPE_EXT4 4
120 #define FS_TYPE_HFSPLUS 5
121 #define FS_TYPE_REISERFS 6
122 #define FS_TYPE_ISO9660 7
124 // Names of binaries that can manage MOKs....
125 #define MOK_NAMES L"MokManager.efi,HashTool.efi,HashTool-signed.efi"
126 // Directories to search for these MOK-managing programs. Note that SelfDir is
127 // searched in addition to these locations....
128 #define MOK_LOCATIONS L"\\,EFI\\tools,EFI\\fedora,EFI\\redhat,EFI\\ubuntu,EFI\\suse,EFI\\altlinux"
131 // global definitions
147 } MBR_PARTITION_INFO
;
150 EFI_DEVICE_PATH
*DevicePath
;
151 EFI_HANDLE DeviceHandle
;
155 EG_IMAGE
*VolIconImage
;
156 EG_IMAGE
*VolBadgeImage
;
158 BOOLEAN IsAppleLegacy
;
162 BOOLEAN IsMbrPartition
;
163 UINTN MbrPartitionIndex
;
164 EFI_BLOCK_IO
*BlockIO
;
165 UINT64 BlockIOOffset
;
166 EFI_BLOCK_IO
*WholeDiskBlockIO
;
167 EFI_DEVICE_PATH
*WholeDiskDevicePath
;
168 MBR_PARTITION_INFO
*MbrPartitionTable
;
173 typedef struct _refit_menu_entry
{
177 CHAR16 ShortcutDigit
;
178 CHAR16 ShortcutLetter
;
180 EG_IMAGE
*BadgeImage
;
181 struct _refit_menu_screen
*SubScreen
;
184 typedef struct _refit_menu_screen
{
186 EG_IMAGE
*TitleImage
;
189 UINTN EntryCount
; // total number of entries registered
190 REFIT_MENU_ENTRY
**Entries
;
191 UINTN TimeoutSeconds
;
202 EFI_DEVICE_PATH
*DevicePath
;
203 BOOLEAN UseGraphicsMode
;
206 CHAR16
*InitrdPath
; // Linux stub loader only
212 REFIT_VOLUME
*Volume
;
213 #ifndef __MAKEWITH_GNUEFI
214 BDS_COMMON_OPTION
*BdsOption
;
222 BOOLEAN ScanAllLinux
;
223 UINTN RequestedScreenWidth
;
224 UINTN RequestedScreenHeight
;
225 UINTN BannerBottomEdge
;
226 UINTN RequestedTextMode
;
229 UINTN MaxTags
; // max. number of OS entries to show simultaneously in graphics mode
233 UINTN ScreensaverTime
;
234 CHAR16
*BannerFileName
;
235 EG_IMAGE
*ScreenBackground
;
236 CHAR16
*SelectionSmallFileName
;
237 CHAR16
*SelectionBigFileName
;
238 CHAR16
*DefaultSelection
;
240 CHAR16
*DontScanVolumes
;
241 CHAR16
*DontScanDirs
;
242 CHAR16
*DontScanFiles
;
245 UINTN ShowTools
[NUM_TOOLS
];
246 CHAR8 ScanFor
[NUM_SCAN_OPTIONS
]; // codes of types of loaders for which to scan
251 extern EFI_HANDLE SelfImageHandle
;
252 extern EFI_LOADED_IMAGE
*SelfLoadedImage
;
253 extern EFI_FILE
*SelfRootDir
;
254 extern EFI_FILE
*SelfDir
;
255 extern CHAR16
*SelfDirPath
;
257 extern REFIT_VOLUME
*SelfVolume
;
258 extern REFIT_VOLUME
**Volumes
;
259 extern UINTN VolumesCount
;
261 extern REFIT_CONFIG GlobalConfig
;
263 extern EFI_GUID gEfiLegacyBootProtocolGuid
;
264 extern EFI_GUID gEfiGlobalVariableGuid
;
266 LOADER_ENTRY
*InitializeLoaderEntry(IN LOADER_ENTRY
*Entry
);
267 REFIT_MENU_SCREEN
*InitializeSubScreen(IN LOADER_ENTRY
*Entry
);
268 VOID
GenerateSubScreen(LOADER_ENTRY
*Entry
, IN REFIT_VOLUME
*Volume
);
269 LOADER_ENTRY
* MakeGenericLoaderEntry(VOID
);
270 LOADER_ENTRY
* AddLoaderEntry(IN CHAR16
*LoaderPath
, IN CHAR16
*LoaderTitle
, IN REFIT_VOLUME
*Volume
);
271 VOID
SetLoaderDefaults(LOADER_ENTRY
*Entry
, CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
);
272 LOADER_ENTRY
* AddPreparedLoaderEntry(LOADER_ENTRY
*Entry
);