From 0d88d54f987fa0e464177febbc04c93257a17b40 Mon Sep 17 00:00:00 2001 From: kavsrf Date: Sat, 28 Jan 2017 14:12:08 +0300 Subject: full disk encryption support --- DcsBoot/DcsBoot.c | 38 +++++++++++++++++++++++++++++++++++--- DcsBoot/DcsBoot.inf | 1 + 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'DcsBoot') 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 #include #include +#include #include "DcsConfig.h" +#include 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 -- cgit v1.2.3