+// Add the second-row tags containing built-in and external tools (EFI shell,
+// reboot, etc.)
+static VOID ScanForTools(VOID) {
+ CHAR16 *FileName = NULL, Description[256];
+ REFIT_MENU_ENTRY *TempMenuEntry;
+ UINTN i, j, VolumeIndex;
+
+ for (i = 0; i < NUM_TOOLS; i++) {
+ switch(GlobalConfig.ShowTools[i]) {
+ case TAG_SHUTDOWN:
+ TempMenuEntry = CopyMenuEntry(&MenuEntryShutdown);
+ TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_SHUTDOWN);
+ AddMenuEntry(&MainMenu, TempMenuEntry);
+ break;
+ case TAG_REBOOT:
+ TempMenuEntry = CopyMenuEntry(&MenuEntryReset);
+ TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_RESET);
+ AddMenuEntry(&MainMenu, TempMenuEntry);
+ break;
+ case TAG_ABOUT:
+ TempMenuEntry = CopyMenuEntry(&MenuEntryAbout);
+ TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
+ AddMenuEntry(&MainMenu, TempMenuEntry);
+ break;
+ case TAG_EXIT:
+ TempMenuEntry = CopyMenuEntry(&MenuEntryExit);
+ TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_EXIT);
+ AddMenuEntry(&MainMenu, TempMenuEntry);
+ break;
+ case TAG_SHELL:
+ j = 0;
+ MyFreePool(FileName);
+ while ((FileName = FindCommaDelimited(SHELL_NAMES, j++)) != NULL) {
+ if (FileExists(SelfRootDir, FileName)) {
+ AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL),
+ 'S', FALSE);
+ }
+ } // while
+ break;
+ case TAG_GPTSYNC:
+ MyFreePool(FileName);
+ FileName = StrDuplicate(L"\\efi\\tools\\gptsync.efi");
+// MergeStrings(&FileName, L"\\efi\\tools\\gptsync.efi", 0);
+ if (FileExists(SelfRootDir, FileName)) {
+ AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, L"Make Hybrid MBR", BuiltinIcon(BUILTIN_ICON_TOOL_PART), 'P', FALSE);
+ }
+ break;
+ case TAG_APPLE_RECOVERY:
+ MyFreePool(FileName);
+ FileName = StrDuplicate(L"\\com.apple.recovery.boot\\boot.efi");
+// MergeStrings(&FileName, L"\\com.apple.recovery.boot\\boot.efi", 0);
+ for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+ if ((Volumes[VolumeIndex]->RootDir != NULL) && (FileExists(Volumes[VolumeIndex]->RootDir, FileName))) {
+ SPrint(Description, 255, L"Apple Recovery on %s", Volumes[VolumeIndex]->VolName);
+ AddToolEntry(Volumes[VolumeIndex]->DeviceHandle, FileName, Description,
+ BuiltinIcon(BUILTIN_ICON_TOOL_APPLE_RESCUE), 'R', TRUE);
+ }
+ } // for
+ break;
+ case TAG_MOK_TOOL:
+ j = 0;
+ MyFreePool(FileName);
+ while ((FileName = FindCommaDelimited(MOK_NAMES, j++)) != NULL) {
+ if (FileExists(SelfRootDir, FileName)) {
+ SPrint(Description, 255, L"MOK Key Manager at %s", FileName);
+ AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, Description,
+ BuiltinIcon(BUILTIN_ICON_TOOL_MOK_TOOL), 'S', FALSE);
+ }
+ } // while
+ if (FileExists(SelfDir, L"MokManager.efi")) {
+ MyFreePool(FileName);
+ FileName = StrDuplicate(SelfDirPath);
+ MergeStrings(&FileName, L"\\MokManager.efi", 0);
+ SPrint(Description, 255, L"MOK Key Manager at %s", FileName);
+ AddToolEntry(SelfLoadedImage->DeviceHandle, FileName, Description,
+ BuiltinIcon(BUILTIN_ICON_TOOL_MOK_TOOL), 'S', FALSE);
+ }
+ break;
+ } // switch()
+ MyFreePool(FileName);
+ FileName = NULL;
+ } // for
+} // static VOID ScanForTools
+
+// Rescan for boot loaders
+VOID RescanAll(VOID) {
+ EG_PIXEL BGColor;
+
+ BGColor.b = 255;
+ BGColor.g = 175;
+ BGColor.r = 100;
+ BGColor.a = 0;
+ egDisplayMessage(L"Scanning for new boot loaders; please wait....", &BGColor);
+ FreeList((VOID ***) &(MainMenu.Entries), &MainMenu.EntryCount);
+ MainMenu.Entries = NULL;
+ MainMenu.EntryCount = 0;
+ ReadConfig(CONFIG_FILE_NAME);
+ ConnectAllDriversToAllControllers();
+ ScanVolumes();
+ ScanForBootloaders();
+ ScanForTools();
+ SetupScreen();
+} // VOID RescanAll()
+
+#ifndef __MAKEWITH_GNUEFI
+
+// Minimal initialization function
+static VOID InitializeLib(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) {
+ gST = SystemTable;
+ // gImageHandle = ImageHandle;
+ gBS = SystemTable->BootServices;
+ // gRS = SystemTable->RuntimeServices;
+ gRT = SystemTable->RuntimeServices; // Some BDS functions need gRT to be set
+ EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);
+
+ InitializeConsoleSim();
+}
+
+#endif
+
+// Set up our own Secure Boot extensions....
+// Returns TRUE on success, FALSE otherwise
+static BOOLEAN SecureBootSetup(VOID) {
+ EFI_STATUS Status;
+ BOOLEAN Success = FALSE;
+
+ if (secure_mode()) {
+ Status = security_policy_install();
+ if (Status == EFI_SUCCESS) {
+ Success = TRUE;
+ } else {
+ Print(L"Failed to install MOK Secure Boot extensions");
+// PauseForKey();
+ }
+ }
+ return Success;
+} // VOID SecureBootSetup()
+
+// Remove our own Secure Boot extensions....
+// Returns TRUE on success, FALSE otherwise
+static BOOLEAN SecureBootUninstall(VOID) {
+ EFI_STATUS Status;
+ BOOLEAN Success = TRUE;
+
+ if (secure_mode()) {
+ Status = security_policy_uninstall();
+ if (Status != EFI_SUCCESS) {
+ Success = FALSE;
+ BeginTextScreen(L"Secure Boot Policy Failure");
+ Print(L"Failed to uninstall MOK Secure Boot extensions; forcing a reboot.");
+ PauseForKey();
+ refit_call4_wrapper(RT->ResetSystem, EfiResetCold, EFI_SUCCESS, 0, NULL);
+ }
+ }
+ return Success;
+} // VOID SecureBootUninstall
+