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.
How to programatically boot Linux with UEFI?
Re: How to programatically boot Linux with UEFI?
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):
Roughly (in C++, hence const_cast):
Code: Select all
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);
Re: How to programatically boot Linux with UEFI?
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?davmac314 wrote:Code: Select all
chained_image_LIP->LoadOptions = const_cast<void *>((const void *)cmdline);
Code: Select all
chained_image_LIP->LoadOptions = (void *)cmdline;
Re: How to programatically boot Linux with UEFI?
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).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: Select all
chained_image_LIP->LoadOptions = (void *)cmdline;
However, the code as written does work even though it mixes casting styles.