diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2018-04-23 00:02:34 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2018-04-24 06:46:26 +0200 |
commit | 1eff8b8b5e97a372473043fe3d83cef51d5c2b11 (patch) | |
tree | 02a57823758a3dfb42a71510b18338b8bac4ebce /DcsBoot | |
parent | a8357b34edb23aebdb84ec6c5b4e038b4920ec4a (diff) | |
download | VeraCrypt-DCS-1eff8b8b5e97a372473043fe3d83cef51d5c2b11.tar.gz VeraCrypt-DCS-1eff8b8b5e97a372473043fe3d83cef51d5c2b11.zip |
By default, use Bootmgfw_ms.vc as Windows bootloader since VeraCrypt now copies its bootloader to Bootmgfw.efi in order to be compatible with machines that always boot on Bootmgfw.efi.
Diffstat (limited to 'DcsBoot')
-rw-r--r-- | DcsBoot/DcsBoot.c | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/DcsBoot/DcsBoot.c b/DcsBoot/DcsBoot.c index 7eaf41b..664afaa 100644 --- a/DcsBoot/DcsBoot.c +++ b/DcsBoot/DcsBoot.c @@ -25,7 +25,8 @@ https://opensource.org/licenses/LGPL-3.0 EFI_GUID ImagePartGuid;
EFI_GUID *gEfiExecPartGuid = &ImagePartGuid;
-CHAR16 *gEfiExecCmdDefault = L"\\EFI\\Microsoft\\Boot\\Bootmgfw.efi";
+CHAR16 *gEfiExecCmdDefault = L"\\EFI\\Microsoft\\Boot\\Bootmgfw_ms.vc";
+CHAR16 *gEfiExecCmdMS = L"\\EFI\\Microsoft\\Boot\\Bootmgfw.efi";
CHAR16 *gEfiExecCmd = NULL;
CHAR8 gDoExecCmdMsg[256];
@@ -44,7 +45,10 @@ DoExecCmd() lockFlags = ConfigReadInt("DcsBmlLockFlags", BML_LOCK_SETVARIABLE | BML_SET_BOOTNEXT | BML_UPDATE_BOOTORDER);
BmlLock(lockFlags);
res = EfiExec(NULL, gEfiExecCmd);
- AsciiSPrint(gDoExecCmdMsg, sizeof(gDoExecCmdMsg), "\nCan't exec %s start partition %g\n", gEfiExecCmd, gEfiExecPartGuid);
+ if (EFI_ERROR(res))
+ AsciiSPrint(gDoExecCmdMsg, sizeof(gDoExecCmdMsg), "\nCan't exec %s start partition %g\n", gEfiExecCmd, gEfiExecPartGuid);
+ else
+ AsciiSPrint(gDoExecCmdMsg, sizeof(gDoExecCmdMsg), "\nDone exec %s start partition %g\n", gEfiExecCmd, gEfiExecPartGuid);
} else {
AsciiSPrint(gDoExecCmdMsg, sizeof(gDoExecCmdMsg), "\nCan't open start partition %g\n", gEfiExecPartGuid);
}
@@ -121,6 +125,8 @@ DcsBootMain( UINTN len;
UINT32 attr;
BOOLEAN searchOnESP = FALSE;
+ BOOLEAN searchMsOnESP = FALSE;
+ EFI_GUID *pEfiExecPartBackup = NULL;
// EFI_INPUT_KEY key;
InitBio();
@@ -169,6 +175,8 @@ DcsBootMain( if (EFI_ERROR(res)) {
gEfiExecPartGuid = &ImagePartGuid;
}
+
+ pEfiExecPartBackup = gEfiExecPartGuid;
res = EfiGetVar(L"DcsExecCmd", NULL, &gEfiExecCmd, &len, &attr);
if (EFI_ERROR(res)) {
@@ -177,6 +185,9 @@ DcsBootMain( searchOnESP = CompareGuid(gEfiExecPartGuid, &ImagePartGuid) &&
EFI_ERROR(FileExist(NULL, gEfiExecCmd));
+
+ searchMsOnESP = CompareGuid(gEfiExecPartGuid, &ImagePartGuid) &&
+ EFI_ERROR(FileExist(NULL, gEfiExecCmdMS));
// Clear DcsExecPartGuid before execute OS to avoid problem in VirtualBox with reboot.
EfiSetVar(L"DcsExecPartGuid", NULL, NULL, 0, EFI_VARIABLE_BOOTSERVICE_ACCESS);
@@ -187,34 +198,50 @@ DcsBootMain( InitBio();
res = InitFS();
- // Default load of bootmgfw?
- if (searchOnESP) {
- // gEfiExecCmd is not found on start partition. Try from ESP
- EFI_BLOCK_IO_PROTOCOL *bio = NULL;
- EFI_PARTITION_TABLE_HEADER *gptHdr = NULL;
- EFI_PARTITION_ENTRY *gptEntry = NULL;
- HARDDRIVE_DEVICE_PATH hdp;
- EFI_HANDLE disk;
- if (!EFI_ERROR(res = EfiGetPartDetails(gFileRootHandle, &hdp, &disk))) {
- if ((bio = EfiGetBlockIO(disk)) != NULL) {
- if (!EFI_ERROR(res = GptReadHeader(bio, 1, &gptHdr)) &&
- !EFI_ERROR(res = GptReadEntryArray(bio, gptHdr, &gptEntry))) {
- UINT32 i;
- for (i = 0; i < gptHdr->NumberOfPartitionEntries; ++i) {
- if (CompareGuid(&gptEntry[i].PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)) {
- // select ESP GUID
- CopyGuid(gEfiExecPartGuid, &gptEntry[i].UniquePartitionGUID);
- res = DoExecCmd();
- if(EFI_ERROR(res)) continue;
+ while (1)
+ {
+ // Default load of bootmgfw?
+ if (searchOnESP) {
+ // gEfiExecCmd is not found on start partition. Try from ESP
+ EFI_BLOCK_IO_PROTOCOL *bio = NULL;
+ EFI_PARTITION_TABLE_HEADER *gptHdr = NULL;
+ EFI_PARTITION_ENTRY *gptEntry = NULL;
+ HARDDRIVE_DEVICE_PATH hdp;
+ EFI_HANDLE disk;
+ if (!EFI_ERROR(res = EfiGetPartDetails(gFileRootHandle, &hdp, &disk))) {
+ if ((bio = EfiGetBlockIO(disk)) != NULL) {
+ if (!EFI_ERROR(res = GptReadHeader(bio, 1, &gptHdr)) &&
+ !EFI_ERROR(res = GptReadEntryArray(bio, gptHdr, &gptEntry))) {
+ UINT32 i;
+ for (i = 0; i < gptHdr->NumberOfPartitionEntries; ++i) {
+ if (CompareGuid(&gptEntry[i].PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)) {
+ // select ESP GUID
+ CopyGuid(gEfiExecPartGuid, &gptEntry[i].UniquePartitionGUID);
+ res = DoExecCmd();
+ if(EFI_ERROR(res)) continue;
+ }
}
}
}
}
+ } else {
+ res = DoExecCmd();
}
- } else {
- res = DoExecCmd();
+
+ if(EFI_ERROR(res))
+ {
+ if (0 == StrCmp (gEfiExecCmd, gEfiExecCmdDefault))
+ {
+ gEfiExecCmd = gEfiExecCmdMS;
+ searchOnESP = searchMsOnESP;
+ gEfiExecPartGuid = pEfiExecPartBackup;
+ }
+ else
+ break;
+ }
+ else
+ break;
}
-
ERR_PRINT(L"%a\nStatus - %r", gDoExecCmdMsg, res);
EfiCpuHalt();
return EFI_INVALID_PARAMETER;
|