我正在编写自己的引导程序,我希望能够引导Windows (和Linux)。
bootmgfw.efi是windows引导加载程序,我试图使用UEFI函数LoadImage()和StartImage()加载并启动它,但在它上调用StartImage()之后,我得到了EFI_INVALID_PARAMETER错误,即使我检查了图像句柄是否有效并且LoadImage()没有返回错误状态。
我可以用相同的代码启动其他EFI应用程序,但bootmgfw.efi是唯一一个没有启动的应用程序,尽管我可以在UEFI Shell中启动它。
这里有一些上下文来展示我所做的事情。我正在使用POSIX-UEFI来编写代码。
// Opening the root volume
efi_handle_t device = LIP->DeviceHandle;
efi_simple_file_system_protocol_t* fsProtocol = NULL;
efi_guid_t fsGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
BS->OpenProtocol(device, &fsGuid, (void**)&fsProtocol, IM, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
efi_file_handle_t* rootDir = NULL;
fsProtocol->OpenVolume(fsProtocol, &rootDir);
// Opening the bootloader file
efi_file_handle_t* winBootMgrHandle = NULL;
uint16_t path[] = u"EFI\\Microsoft\\Boot\\bootmgfw.efi";
rootDir->Open(rootDir, &winBootMgrHandle, path, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
// Getting file info for the file size
efi_guid_t infoGuid = EFI_FILE_INFO_GUID;
efi_file_info_t fileInfo;
uintn_t infoSize = sizeof(fileInfo);
winBootMgrHandle->GetInfo(winBootMgrHandle, &infoGuid, &infoSize, &fileInfo);
// Reading the file into a buffer
uintn_t winBootMgrSize = fileInfo.FileSize;
char* winBootMgrData = (char*)malloc(winBootMgrSize + 1);
winBootMgrData[winBootMgrSize] = 0;
winBootMgrHandle->Read(winBootMgrHandle, &winBootMgrSize, winBootMgrData);
// Loading and starting the image
efi_handle_t imgHandle;
BS->LoadImage(0, IM, LIP->FilePath, winBootMgrData, winBootMgrSize, &imgHandle);
BS->StartImage(imgHandle, NULL, NULL); // returns -2: invalid parameter我不明白为什么我会得到这个错误,以及如何修复它。我想知道如何修复这个错误并启动这个windows引导程序。
发布于 2021-08-14 08:59:36
我在这里找到了解决方案。事实证明,我确实向LoadImage()传递了错误的设备路径。https://forum.osdev.org/viewtopic.php?f=1&t=50623
https://stackoverflow.com/questions/68761782
复制相似问题