Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UEFI compatibility #18

Closed
IanSeyler opened this issue Jan 7, 2014 · 10 comments · Fixed by #76
Closed

UEFI compatibility #18

IanSeyler opened this issue Jan 7, 2014 · 10 comments · Fixed by #76

Comments

@IanSeyler
Copy link
Member

IanSeyler commented Jan 7, 2014

Need to investigate what is required to boot with UEFI.

How to get the memory map?
Is a GPT (instead of MBR) partition format needed?
Where are the ACPI tables?

Easiest method is to use GRUB and load a multiboot file.

There is no text mode in UEFI! Graphics are required.

@IanSeyler IanSeyler changed the title Feature: UEFI compatibility UEFI compatibility Dec 28, 2016
@ghost ghost added Eventually This feature will be added at some point, but not the next release. and removed Feature labels Apr 4, 2018
@ghost
Copy link

ghost commented Apr 4, 2018

GPT is added, now. Memory map and system information will be passed to the kernel by either a register or the stack.

@ohnx
Copy link

ohnx commented Apr 5, 2018

Booting from UEFI is an interesting task.

First off, an EFI application (e.g. bootloader) is stored in the PE format and uses Microsoft's C calling conventions.

An EFI application is called with two parameters, the "image handle" and the system table. The system table is where there are interesting things; the ConfigurationTable variable is where the list of ACPI tables are stored following this format. Also of note in the configuration table are the Boot Services function table and the Runtime Services function table; these function tables are very useful for bootloaders. After the bootloader exits, only the Runtime Services functions are still safe to call, though. The function table is typically represented as a struct and the C headers required to do so are pretty common (e.g. a stripped-down version can be found here).

To get a memory map, call a function at an offset into the Boot Services function table. The returned memory map is not E820 and will need to be converted for use in Pure64 (if we want to keep backwards compatibility).

IIRC, in proper UEFI, MBR and GPT partition tables should both be supported. However, I'm not sure if this is the case in the wild.

There is text mode in UEFI! Actually, graphics mode can be a pain since we will need to embed our own font into the application if we want to print text during the bootup process. Not sure if we want to offload this to the OS, or keep it with Pure64.

Note that I have linked sources that are not the actual 2000+ page PDF put out by the UEFI Forum, since I doubt that many people have the time to read through all of the specification... The latest specification can be found on the UEFI Forum website.

@ghost
Copy link

ghost commented Apr 5, 2018

@ohnx Supporting UEFI will likely require many changes in the BareMetal-kernel. That's okay. It should not be that hard to go from E820 to a different structure.

Currently, text is printed out through a serial port that we can view through QEMU.

I'm hesitant to make a solution for printing text to the screen. If anything, I would send it to a file, so that it has a tangible form on disk. But I'm open to suggestions.

@ghost
Copy link

ghost commented Apr 21, 2018

I think my project could help you with this:
https://github.com/KNNSpeed/Simple-UEFI-Bootloader

Looks like you guys might be trying to do a similar thing.

Bear in mind UEFI compatibility can be pretty nasty when dealing with earlier (c. ~2011-2012) systems, as vendors didn't really like to follow spec back then. E.g. 0-byte reads fail on Intel boards, RAM "pollution" on startup, etc. Newer machines tend to be better about all this, except Macs whose wireless cards randomly DMA into your RAM (see https://mjg59.dreamwidth.org/11235.html).

@ghost
Copy link

ghost commented Apr 21, 2018

@KNNSpeed I like the project you linked.

I was not aware how bad the adoption of UEFI was in that time period, that's pretty funny.

I'm not sure if we can use the GNU EFI implementation, it's incompatible with our BSD license the way I understand it.

The hurdle we're facing now is creating FAT file systems on the image. While there are tools that exist for this, they're mainly for Linux. We need to have a FAT library in house so that we can not only create the file system, but also read to and write from it in the file system loader. Once we get to that point, then we'll be able to reference bootloaders like yours to get an idea of what a working implementation looks like.

Thanks for the link!

@ghost
Copy link

ghost commented Apr 21, 2018

No problem!
I guess libraries like FATFs (http://elm-chan.org/fsw/ff/00index_e.html) are out of the question, then?

Technically if you stayed in UEFI without calling ExitBootServices() you would have access to all the FAT functions already there, but I have a feeling you guys want to get out of boot land as fast as possible. A nice thing about UEFI is that it already does all of this for you, and you can actually use UEFI functions to set up a system how you like and then pass whatever you want to a kernel. ...Unless you're [eventually] trying to write your own UEFI firmware?

@ghost
Copy link

ghost commented Apr 21, 2018

@knn I've thought about Pure64 as a UEFI firmware but for now that's more of an "eventually" kind of thing.

That file system library looks useful. Although I don't particularly like libraries that use global variables, it's small enough that it's easy to patch. The license looks like it's compatible.

@IanSeyler what do you think about importing FatFS source code into the Pure64 project?

@IanSeyler
Copy link
Member Author

@tay10r If it will help with UEFI then sure.

@ghost
Copy link

ghost commented Apr 23, 2018

@IanSeyler It will help with UEFI, yes. I'm working on porting the library now to see if it will work. We might not need to use the code in the actual bootloader. Mainly we need it in the utility program to create the filesystem and put the files into it.

@ghost
Copy link

ghost commented Oct 13, 2018

Just to update everyone, I've began refactoring the FAT library that @KNNSpeed mentioned and you can see the progress in the new libfat repository.

Once that's done, I would like to make a way for users to put their kernels onto the disk file without having to compile them with the monolithic bundle of software that is mingw (since Microsoft's ABI is used in the UEFI standard.)

@IanSeyler IanSeyler added In-progress and removed Eventually This feature will be added at some point, but not the next release. labels Mar 8, 2024
@IanSeyler IanSeyler mentioned this issue Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants