From 269858f5a1ba5750d54dd45b87313440a6f80914 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Tue, 23 Jan 2024 20:56:58 +0100 Subject: [PATCH] Implement and use BlGetEfiPath() routine to get valid EFI path --- sdk/xtdk/bltypes.h | 1 + xtldr/includes/xtldr.h | 5 +++++ xtldr/volume.c | 50 ++++++++++++++++++++++++++++++++++++++++++ xtldr/xtldr.c | 9 ++++++++ 4 files changed, 65 insertions(+) diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index f64eedb..85ea5e3 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -105,6 +105,7 @@ typedef struct _XTBL_BOOT_PARAMETERS { PEFI_DEVICE_PATH_PROTOCOL DevicePath; PWCHAR ArcName; + PWCHAR EfiPath; PWCHAR SystemPath; PWCHAR SystemType; PWCHAR KernelFile; diff --git a/xtldr/includes/xtldr.h b/xtldr/includes/xtldr.h index 14c7586..5e3315a 100644 --- a/xtldr/includes/xtldr.h +++ b/xtldr/includes/xtldr.h @@ -130,6 +130,11 @@ XTCDECL PWCHAR BlGetConfigValue(IN CONST PWCHAR ConfigName); +XTCDECL +EFI_STATUS +BlGetEfiPath(IN PWCHAR SystemPath, + OUT PWCHAR *EfiPath); + XTCDECL EFI_STATUS BlGetMemoryMap(OUT PEFI_MEMORY_MAP MemoryMap); diff --git a/xtldr/volume.c b/xtldr/volume.c index 6b84833..3692c00 100644 --- a/xtldr/volume.c +++ b/xtldr/volume.c @@ -276,6 +276,56 @@ BlFindVolumeDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL FsHandle, return STATUS_EFI_SUCCESS; } +/** + * Creates a copy of the system path with EFI standard directory separators. + * + * @param SystemPath + * Supplies a pointer to the system path. + * + * @param EfiPath + * Supplies a pointer to the memory area, where EFI path will be stored. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlGetEfiPath(IN PWCHAR SystemPath, + OUT PWCHAR *EfiPath) +{ + SIZE_T Index, PathLength; + EFI_STATUS Status; + + /* Get system path length */ + PathLength = RtlWideStringLength(SystemPath, 0); + + /* Allocate memory for storing EFI path */ + Status = BlAllocateMemoryPool(sizeof(WCHAR) * (PathLength + 1), (PVOID *)EfiPath); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to allocate memory, print error message and return status code */ + BlDebugPrint(L"ERROR: Memory allocation failure (Status Code: 0x%lx)\n", Status); + return STATUS_EFI_OUT_OF_RESOURCES; + } + + /* Make a copy of SystemPath string */ + RtlCopyMemory(*EfiPath, SystemPath, sizeof(WCHAR) * (PathLength + 1)); + + /* Replace directory separator if needed to comply with EFI standard */ + for(Index = 0; Index < PathLength; Index++) + { + if((*EfiPath)[Index] == L'/') + { + /* Replace '/' with '\' */ + (*EfiPath)[Index] = L'\\'; + } + } + + /* Return success */ + return STATUS_EFI_SUCCESS; +} + /** * Finds a volume device path based on the specified ARC name or UUID. * diff --git a/xtldr/xtldr.c b/xtldr/xtldr.c index 87a99f8..8e311cb 100644 --- a/xtldr/xtldr.c +++ b/xtldr/xtldr.c @@ -227,6 +227,15 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList) BlDebugPrint(L"ERROR: Failed to find volume device path (Status Code: 0x%lx)\n", Status); return Status; } + + /* Get EFI compatible system path */ + Status = BlGetEfiPath(BootParameters.SystemPath, &BootParameters.EfiPath); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to get EFI path */ + BlDebugPrint(L"ERROR: Failed to get EFI path (Status Code: 0x%lx)\n", Status); + return Status; + } } else if(RtlCompareWideStringInsensitive(Option->Name, L"KERNELFILE", 0) == 0) {