OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 5:54 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: UEFI Loading a File
PostPosted: Fri Mar 24, 2017 7:04 am 
Offline

Joined: Thu Mar 23, 2017 1:14 pm
Posts: 2
Hi, I am new here and have been searching the internet high and low for an answer to this question and I am unable to find it. How do I load a file off of my boot disk using UEFI? I have a file called "kernel.elf" and I want to load it into memory address 0x100000. From there I know how to read the elf file and execute it. I am using GNU-EFI.


Top
 Profile  
 
 Post subject: Re: UEFI Loading a File
PostPosted: Fri Mar 24, 2017 9:07 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
shipsimfan wrote:
Hi, I am new here and have been searching the internet high and low for an answer to this question and I am unable to find it. How do I load a file off of my boot disk using UEFI? I have a file called "kernel.elf" and I want to load it into memory address 0x100000. From there I know how to read the elf file and execute it. I am using GNU-EFI.

That's awesome. But have you tried to read the UEFI specification? Particularly - section 6.4? I'd recommend to read the whole section 2 at least.
Finally, as the name implies, that is your kernel, right? that means you are at the stage where your OS loader took control of the UEFI and it's up to you how you are going to load your file. Before you call ExitBootServices() function you can rely on the FW Boot services in its entirity. LoadImage() function is of particular interest for you. Read its description carefully. But I think you need to read much more than that in the specification.

_________________
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: UEFI Loading a File
PostPosted: Fri Mar 24, 2017 10:11 am 
Offline

Joined: Thu Mar 23, 2017 1:14 pm
Posts: 2
One issue I have with using the LoadImage function is that I am unable to specify a specific memory location for the file to be loaded to and I am also unable to get a pointer to where the file was loaded. One other question is how the Device Path type works and how to specify one.


Top
 Profile  
 
 Post subject: Re: UEFI Loading a File
PostPosted: Fri Mar 24, 2017 12:52 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 06, 2010 7:07 pm
Posts: 792
Instead of LoadImage, you can use SimpleFileSystemProtocol- lets you traverse the file system, open files, and read their contents into arbitrary buffers.

However, be careful just flinging data at arbitrary memory addresses- you need to make sure the firmware didn't already put something there. You can, however, request a particular address from BootServices->AllocatePages, if that makes things easier to get up and running.

Here is a simple ELF loader I use: https://github.com/rpjohnst/kernel/blob ... src/boot.c

_________________
[www.abubalay.com]


Top
 Profile  
 
 Post subject: Re: UEFI Loading a File
PostPosted: Sun Mar 26, 2017 1:01 pm 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
You can use the simple file system protocol. If you want to access the ESP, then see this.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: UEFI Loading a File
PostPosted: Mon Mar 27, 2017 6:28 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
Quote:
One issue I have with using the LoadImage function is that I am unable to specify a specific memory location for the file to be loaded to and I am also unable to get a pointer to where the file was loaded. One other question is how the Device Path type works and how to specify one.

In fact, if you want to control a location where to load your image you need 1) to allocate the buffer at that location (AllocatePages()), and only after successful allocation, load there your image. This is done by EFI_FILE_PROTOCOL. First you obtain instance of EFI_FILE_PROTOCOL for the root directory of the volume where your image resides (through the volume's instance EFI_SIMPLE_FILE SYSTEM_PROTOCOL OpenVolume() function), the volume should be a FAT partition. then find your file, using EFI_FILE_PROTOCOL functions. Then read your file, using them as well. Read EFI_FILE_PROTOCOL.
But it's not that easy. You should behave as a proper OSLoader - taking over the control of the FW, calling GetMemoryMap() and ExitBootServices(). This phase is not as easy as just loading the file and jumping at it. For example, if you won't take control over, calling ExitBootServices(), FW still will run (the timer ISR, also watchdog, which might reset the board).

_________________
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  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 165 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