How do I find the boot volume with UEFI?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

How do I find the boot volume with UEFI?

Post 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.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

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

Post 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
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

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

Post 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 (;;);
}
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

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

Post by Roman »

Thanks for the example! Changing LocateProtocol to HandleProtocol fixed the problem!
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Post Reply