Page 1 of 1

How do I find the boot volume with UEFI?

Posted: Sun Sep 11, 2016 7:21 am
by Roman
Greetings, OSDev.org!

How do I get the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL for the boot partition? I tried getting it from EFI_LOADED_IMAGE->DeviceHandle, but it only supports EFI_DEVICE_PATH_PROTOCOL, EFI_FIRMWARE_VOLUME2_PROTOCOL and EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL.

Thanks in advance.

Re: How do I find the boot volume with UEFI?

Posted: Sun Sep 11, 2016 10:29 am
by Rusky
Hmm, what firmware are you on? OVMF supports what you're trying to do, at least when using HandleProtocol: https://github.com/rpjohnst/kernel/blob ... .c#L27-L33

Re: How do I find the boot volume with UEFI?

Posted: Sat Sep 17, 2016 9:14 am
by Roman
Rusky wrote:Hmm, what firmware are you on? OVMF supports what you're trying to do, at least when using HandleProtocol: https://github.com/rpjohnst/kernel/blob ... .c#L27-L33
Pretty odd, because the following prints "fail" for me:

Code: Select all

EFIAPI
EFI_STATUS Main(
	EFI_HANDLE        imageHandle,
	EFI_SYSTEM_TABLE *systemTable
) {
	void InitSystem(
		EFI_HANDLE imageHandle,
		EFI_SYSTEM_TABLE *systemTable
	);

	InitSystem(imageHandle, systemTable);

	EFI_GUID loadedImageProtoId = EFI_LOADED_IMAGE_PROTOCOL_GUID;

	EFI_LOADED_IMAGE *loadedImage;

	systemTable->BootServices->LocateProtocol(
		&loadedImageProtoId,
		NULL,
		(void **)&loadedImage
	);

	EFI_GUID fsProtoId = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;

	EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;

	if (systemTable->BootServices->HandleProtocol(
		loadedImage->ParentHandle,
		&fsProtoId,
		(void **)&fs
	) != EFI_SUCCESS) {
		puts(L"fail\n\r");
	} else {
		puts(L"ok\n\r");
	};

	puts(L"Finish.\n\r");

	for (;;);
}

Re: How do I find the boot volume with UEFI?

Posted: Sat Sep 17, 2016 9:17 am
by Roman
Thanks for the example! Changing LocateProtocol to HandleProtocol fixed the problem!