How do you rewrite the kernel if you chose use UEFI to start

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: How do you rewrite the kernel if you chose use UEFI to s

Post by bzt »

Hi,
ajxs wrote:
benji wrote:The kernel may not be the kernel.bin, The kernel became kernel.efi???? I really want to know those basic problem. Thank you so much!
Apologies for resurrecting a dead thread, I figure it's worth a reply in case this helps someone.
No one has addressed the fact that you shouldn't be compiling your kernel into the UEFI bootloader. This statement suggests that OP is a little confused regarding the bootloader's purpose and how it differs from the kernel itself. UEFI is not for writing a kernel, it's for writing a bootloader to load the kernel. The bootloader's job is to set up the initial environment for loading and executing the kernel. While the kernel is highly coupled to the bootloader, they are separate programs entirely. The UEFI bootloader should be compiled as an EFI executable, which then loads the separate kernel executable in whatever binary format it is in.
Regarding OP's original question of what you need to rewrite in your kernel: This is a really pedantic answer, but... nothing. Maybe. Most online tutorials suggest using GRUB and writing your kernel to adhere to the Multiboot standard. An advantage of doing this is that it would theoretically be compatible with any bootloader implementing this standard. If you roll your own bootloader you're going to need to decide for yourself what state your kernel expects the environment to be in.
If you're having trouble with writing your kernel, UEFI won't offer you much help. Writing your own bootloader in UEFI will not simplify any part of the kernel development process.
Basically you're right. However it is not impossible nor uncommon to write the kernel as an UEFI binary. For example the Linux kernel has manually hardcoded bytes in it so that the UEFI firmware sees it as an UEFI executable and it can load it directly.

But this is a hack. You should separate your kernel from the bootloader (probably using a standard interface with which you'll be able to load your kernel on non-UEFI machines too, either Multiboot, BOOTBOOT, whatever), and you're right writing your own bootloader in UEFI won't simplify anything.

Cheers,
bzt
Post Reply