OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:31 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to programatically boot Linux with UEFI?
PostPosted: Tue Nov 16, 2021 2:04 pm 
Offline

Joined: Wed Aug 11, 2021 4:58 am
Posts: 6
I'm trying to boot into Linux using UEFI code.
I found that the kernel has an "EFI boot stub" which allows the kernel to be booted directly from the UEFI Shell with arguments but I can't figure out how to do the same in code.
I thought that maybe I could use StartImage() on it, but then how do I pass arguments to it? There must be a different solution.


Top
 Profile  
 
 Post subject: Re: How to programatically boot Linux with UEFI?
PostPosted: Mon Nov 22, 2021 3:41 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
You pass command-line arguments by setting LoadOptions (it's a void *, but you can set to a CHAR16 * representing a command line) in the EFI_LOADED_IMAGE_PROTOCOL, before calling StartImage.

Roughly (in C++, hence const_cast):

Code:
    chained_image_LIP->LoadOptions = const_cast<void *>((const void *)cmdline);
    chained_image_LIP->LoadOptionsSize = (string_length(cmdline) + 1) * sizeof(CHAR16);

    status = EBS->StartImage(loaded_handle, nullptr, nullptr);


Top
 Profile  
 
 Post subject: Re: How to programatically boot Linux with UEFI?
PostPosted: Mon Nov 22, 2021 11:46 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
davmac314 wrote:
Code:
    chained_image_LIP->LoadOptions = const_cast<void *>((const void *)cmdline);

If you are going to cast it to const just to remove the const in the same statement, why not just cast to non-const void?

Code:
    chained_image_LIP->LoadOptions = (void *)cmdline;

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: How to programatically boot Linux with UEFI?
PostPosted: Tue Nov 23, 2021 2:57 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
kzinti wrote:
If you are going to cast it to const just to remove the const in the same statement, why not just cast to non-const void?

Code:
    chained_image_LIP->LoadOptions = (void *)cmdline;


Indeed, that slipped in. You could cast using a c-style cast directly to void * like you suggest, or you could nest a static_cast<const void *> inside the const_cast if you preferred to use only C++-style casts, which is what I'd intended (though now I'm reconsidering).

However, the code as written does work even though it mixes casting styles.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 76 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