VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/DcsBoot
diff options
context:
space:
mode:
Diffstat (limited to 'DcsBoot')
-rw-r--r--DcsBoot/DcsBoot.c38
-rw-r--r--DcsBoot/DcsBoot.inf1
2 files changed, 36 insertions, 3 deletions
diff --git a/DcsBoot/DcsBoot.c b/DcsBoot/DcsBoot.c
index 60c8eed..108da0c 100644
--- a/DcsBoot/DcsBoot.c
+++ b/DcsBoot/DcsBoot.c
@@ -16,7 +16,9 @@ https://opensource.org/licenses/LGPL-3.0
#include <Library/CommonLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
+#include <Library/BaseMemoryLib.h>
#include "DcsConfig.h"
+#include <Guid/Gpt.h>
EFI_GUID ImagePartGuid;
EFI_GUID *gEfiExecPartGuid = &ImagePartGuid;
@@ -43,6 +45,7 @@ DcsBootMain(
UINTN len;
UINT32 attr;
int drvInst;
+ BOOLEAN searchOnESP = FALSE;
InitBio();
res = InitFS();
if (EFI_ERROR(res)) {
@@ -51,8 +54,8 @@ DcsBootMain(
drvInst = ConfigReadInt("DcsDriver", 0);
- if (!FileExist(NULL, L"\\EFI\\VeraCrypt\\PlatformInfo") &&
- !FileExist(NULL, L"\\EFI\\VeraCrypt\\DcsInfo.dcs")) {
+ if (EFI_ERROR(FileExist(NULL, L"\\EFI\\VeraCrypt\\PlatformInfo")) &&
+ !EFI_ERROR(FileExist(NULL, L"\\EFI\\VeraCrypt\\DcsInfo.dcs"))) {
res = EfiExec(NULL, L"\\EFI\\VeraCrypt\\DcsInfo.dcs");
}
// Load all drivers
@@ -83,11 +86,40 @@ DcsBootMain(
gEfiExecCmd = gEfiExecCmdDefault;
}
+ searchOnESP = CompareGuid(gEfiExecPartGuid, &ImagePartGuid) &&
+ EFI_ERROR(FileExist(NULL, gEfiExecCmd));
+
// Find new start partition
ConnectAllEfi();
InitBio();
res = InitFS();
-// OUT_PRINT(L".");
+
+ // 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);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // OUT_PRINT(L".");
res = EfiFindPartByGUID(gEfiExecPartGuid, &gFileRootHandle);
if (EFI_ERROR(res)) {
ERR_PRINT(L"\nCan't find start partition %g\n", gEfiExecPartGuid);
diff --git a/DcsBoot/DcsBoot.inf b/DcsBoot/DcsBoot.inf
index 14d8d0d..34c78f3 100644
--- a/DcsBoot/DcsBoot.inf
+++ b/DcsBoot/DcsBoot.inf
@@ -47,6 +47,7 @@
gEfiGlobalVariableGuid
gEfiDcsVariableGuid
gEfiFileInfoGuid
+ gEfiPartTypeSystemPartGuid
[Protocols]
gEfiBlockIoProtocolGuid