#include <Ventoy.h>
BOOLEAN gDebugPrint = FALSE;
+BOOLEAN gLoadIsoEfi = FALSE;
ventoy_ram_disk g_ramdisk_param;
ventoy_chain_head *g_chain;
ventoy_img_chunk *g_chunk;
ventoy_grub_param_file_replace *g_file_replace_list = NULL;
ventoy_efi_file_replace g_efi_file_replace;
+CONST CHAR16 gIso9660EfiDriverPath[] = ISO9660_EFI_DRIVER_PATH;
+
BOOLEAN g_fix_windows_1st_cdrom_issue = FALSE;
STATIC BOOLEAN g_hook_keyboard = FALSE;
L"\\EFI\\BOOT\\GRUBX64.EFI",
L"\\EFI\\BOOT\\BOOTx64.EFI",
L"\\EFI\\BOOT\\bootx64.efi",
- L"\\efi\\boot\\bootx64.efi",
+ L"\\efi\\boot\\bootx64.efi"
};
VOID EFIAPI VtoyDebug(IN CONST CHAR8 *Format, ...)
}
}
+
+STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk_fs(IN EFI_HANDLE ImageHandle)
+{
+ UINTN i = 0;
+ UINTN Count = 0;
+ EFI_HANDLE Parent = NULL;
+ EFI_HANDLE *Handles = NULL;
+ EFI_STATUS Status = EFI_SUCCESS;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFile = NULL;
+ EFI_DEVICE_PATH_PROTOCOL *pDevPath = NULL;
+
+ Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid,
+ NULL, &Count, &Handles);
+ if (EFI_ERROR(Status))
+ {
+ return Status;
+ }
+
+ debug("ventoy_find_iso_disk_fs fs count:%u", Count);
+
+ for (i = 0; i < Count; i++)
+ {
+ Status = gBS->HandleProtocol(Handles[i], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&pFile);
+ if (EFI_ERROR(Status))
+ {
+ continue;
+ }
+
+ Status = gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
+ (VOID **)&pDevPath,
+ ImageHandle,
+ Handles[i],
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR(Status))
+ {
+ debug("Failed to open device path protocol %r", Status);
+ continue;
+ }
+
+ debug("Handle:%p FS DP: <%s>", Handles[i], ConvertDevicePathToText(pDevPath, FALSE, FALSE));
+ Parent = ventoy_get_parent_handle(pDevPath);
+
+ if (Parent == gBlockData.RawBlockIoHandle)
+ {
+ debug("Find ventoy disk fs");
+ gBlockData.DiskFsHandle = Handles[i];
+ gBlockData.pDiskFs = pFile;
+ gBlockData.pDiskFsDevPath = pDevPath;
+ break;
+ }
+ }
+
+ FreePool(Handles);
+
+ return EFI_SUCCESS;
+}
+
+STATIC EFI_STATUS EFIAPI ventoy_load_isoefi_driver(IN EFI_HANDLE ImageHandle)
+{
+ EFI_HANDLE Image = NULL;
+ EFI_STATUS Status = EFI_SUCCESS;
+ CHAR16 LogVar[4] = L"5";
+
+ Status = ventoy_load_image(ImageHandle, gBlockData.pDiskFsDevPath,
+ gIso9660EfiDriverPath,
+ sizeof(gIso9660EfiDriverPath),
+ &Image);
+ debug("load iso efi driver status:%r", Status);
+
+ if (gDebugPrint)
+ {
+ gRT->SetVariable(L"FS_LOGGING", &gShellVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof(LogVar), LogVar);
+ }
+
+ gRT->SetVariable(L"FS_NAME_NOCASE", &gShellVariableGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ sizeof(LogVar), LogVar);
+
+ gBlockData.IsoDriverImage = Image;
+ Status = gBS->StartImage(Image, NULL, NULL);
+ debug("Start iso efi driver status:%r", Status);
+
+ return EFI_SUCCESS;
+}
+
STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
{
UINT32 i = 0;
gDebugPrint = TRUE;
}
+ if (StrStr(pCmdLine, L"isoefi=on"))
+ {
+ gLoadIsoEfi = TRUE;
+ }
+
pPos = StrStr(pCmdLine, L"FirstTry=@");
if (pPos)
{
FreePool(g_sector_flag);
g_sector_flag_num = 0;
+ if (gLoadIsoEfi && gBlockData.IsoDriverImage)
+ {
+ gBS->UnloadImage(gBlockData.IsoDriverImage);
+ }
+
gBS->DisconnectController(gBlockData.Handle, NULL, NULL);
gBS->UninstallMultipleProtocolInterfaces(gBlockData.Handle,
ventoy_save_variable();
ventoy_find_iso_disk(ImageHandle);
+ if (gLoadIsoEfi)
+ {
+ ventoy_find_iso_disk_fs(ImageHandle);
+ ventoy_load_isoefi_driver(ImageHandle);
+ }
+
ventoy_debug_pause();
ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);