OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 3:51 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Using UEFI LoadImage
PostPosted: Tue Sep 15, 2020 2:25 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
Hello,
I am making an EFI bootloader, and ran into a problem. I am calling LoadImage to test chainloading, but it doesn't work. Here is how I call it:
Code:
BS->LoadImage(FALSE, ImageHandle, loader->FilePath, buffer, size, &handle);
BS->StartImage(handle, 0, 0)

The Image starts fine, but then it runs the following code:
Code:
EFI_GUID imageGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
status = BS->HandleProtocol(ImageHandle, &imageGuid, (VOID**)&loader);
EFI_GUID fsProt = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
status = BS->HandleProtocol(loader->DeviceHandle, &fsProt, (VOID**)&fileSys);

And the second call fails with EFI_ERROR_INVALID_PARAMETER.
Also, I am using the file handle obtained from the images structure.
Any suggestions?
Thanks,
nexos

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Using UEFI LoadImage
PostPosted: Tue Sep 15, 2020 4:52 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
Quote:
Code:
BS->LoadImage(FALSE, ImageHandle, loader->FilePath, buffer, size, &handle);


uhm, do you start the image recursively? because loader->FilePath points to the file part of the of the device path of the image, whose Loaded Image Protocol instance is pointed to by the "loader" variable.

Also, use OpenProtocol() instead of HandleProtocol() for obtaining a protocol instance from the handle, the latter is deprecated. I do like this and it works:
Code:
   Status = pbs->OpenProtocol(
         gpLoadedImageProtocol->DeviceHandle,
         &gEfiSimpleFileSystemGuid,
         &gpSfspHomeDrive,
         ImageHandle,
         NULL,
         EFI_OPEN_PROTOCOL_GET_PROTOCOL
      );

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
 Post subject: Re: Using UEFI LoadImage
PostPosted: Tue Sep 15, 2020 6:58 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
I changed it to use OpenProtocol, and I also changed the LoadImage call to look like
Code:
EFI_MEMORY_MAPPED_DEVICE* memDev = (EFI_MEMORY_MAPPED_DEVICE*)AllocMem(sizeof(EFI_MEMORY_MAPPED_DEVICE) * 2);
    memDev[0].Type = 1;
    memDev[0].subType = 3;
    memDev[0].len = 24;
    memDev[0].type = EfiLoaderData;
    memDev[0].startAddr = (UINT64)buffer;
    memDev[0].endAddr = (UINT64)buffer + size;
    memDev[1].Type = 0x7F;
    memDev[1].subType = 0xFF;
    memDev[1].len = 4;
    EFI_STATUS status = BS->LoadImage(FALSE, ImageHandle, (EFI_DEVICE_PATH_PROTOCOL*)memDev, buffer, size, &handle);

It does the same thing still.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Using UEFI LoadImage
PostPosted: Tue Sep 15, 2020 7:14 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
It appears I found something interesting. When I chainload the app, the DeviceHandle of that app is 0 for some reason. Will have to look into.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Using UEFI LoadImage
PostPosted: Wed Sep 16, 2020 2:21 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
when you LoadImage() something, it means, you have 2 images - one, that is started by the FW (let it be Img0) and the other (Img1), you start through LoadImage()/StartImage(). you should provide Device Path to Img1, when doing LoadImage() for it. So the Device Path would be something like [storage-device-part]\efi\nexos\Img1.efi. If Img1 resides on the same volume as Img0, [storage-device-part] is the same as for Img0. The idea is you should know the Device Path of this image (generally speaking, your chainloading system should have it written somewhere in its configuration). what do you try to accomplish with feeding LoadImage() with memory mapped device path? it won't let you grab Img1 from its storage. and btw, why do you start UEFI with such an unnecessary and useless thing like "chainloading"?

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group