Thursday, April 7, 2022

[SOLVED] Jumping back to Grub from the kernel in UEFI system

Issue

I am working on a tiny x86 64 bit kernel that is multiboot2 compliant, the kernel is loaded and launched by Grub. The requirement is that, once the kernel finishes its activity it needs to relaunch Grub. In non UEFI based systems, we used to achieve this by bringing the processor back to real mode jumping to address 0x7c00.

With UEFI systems, I am trying to understand if something similar is feasible, one possible approach in my mind is to reload Grub from the kernel using the EFI_IMAGE_LOAD and EFI_IMAGE_START routines in the EFI boot services table. My understanding of UEFI internals are very limited, it would be greatly helpful if someone can confirm if this approach will work or not.


Solution

Yes, that will work, assuming you can locate the Grub image. (It will be more difficult if Grub was loaded over the network, for example.)

You don’t need to understand UEFI internals to do this. An understanding of the UEFI interface specification is sufficient.

You must not call ExitBootServices from your kernel, so you are somewhat restricted in what your OS can do. You have to use UEFI for memory allocation, for example. You have to maintain 1 to 1 mapping of virtual to physical address space. Your ability to use multiprocessing may be somewhat constrained. See section 2.3.4 of the UEFI spec.



Answered By - prl
Answer Checked By - Gilberto Lyons (WPSolving Admin)