FreeBSD EFI bootloader concerns

Hello everyone. While I am exploring the possibility of EFI (Extensible Firmware Interface) bootstrapping of FreeBSD to allow it to boot natively on my MacBook Pro without BIOS-emulation provided by Boot Camp, I am interested in knowing whether the i386/amd64 versions of FreeBSD rely on BIOS runtime services, so that FreeBSD will work as usual without BIOS.

I found out that modern Linux implements its own low-level I/O without the BIOS facility. Could someone please tell me if FreeBSD does the same?

Thank you.
 
As far as I know, the FreeBSD kernel does rely on some BIOS calls during the early boot phase. The standard i386/amd64 loader certainly needs a BIOS, even though there apparently is an EFI version of it.
 
Thank you phs.
I am aware of the fact that FreeBSD/i386 relies on BIOS during bootstrapping. I am more interested in knowing if the current FreeBSD/i386 kernel is compiled with references to BIOS (I am sure FreeBSD/ia64 kernel must not be), so that the kernel will not break on BIOS-less systems once it starts up.
 
Once the operating system is up and running, you really don't want any interaction with the platform firmware for performance reasons. However, there are certain functions that rely on firmware, e.g. rebooting or powering off a system. I think on i386/amd64 this is abstracted through ACPI which is partially available in UEFI as well.

In other words: If you get the kernel to boot on a UEFI system, you have done significant amount of the work required to "run" on a UEFI system.
 
Thank you very much.
So can I say that the work required to boot FreeBSD/i386 on EFI already includes that to run FreeBSD on EFI?
 
I have planned to write an EFI bootloader for FreeBSD/i386. I recently submitted my proposal to apply for this project as my Google Summer of Code 2011 participation.

My approach was to implement the following three components:
1) an EFI application that loads 2);
2) a patched /boot/loader that utilizes EFI instead of BIOS and loads 3);
3) a custom compiled FreeBSD/i386 kernel without dependency on BIOS.

Based on what we have discussed so far, does it mean that 3) is not really necessary, since FreeBSD kernel avoids BIOS and instead uses higher level facilities like ACPI?

Thank you so much.
 
Hi,

I think you may want to look at the boot code and dig around a bit. Here's what I know.

In sys/boot, there's a lot of code already that makes up the loader. As the loader used to be able to boot an ia64 aka Itanium which exclusively has EFI and no BIOS, there's some EFI code available already. This may give a good starting point for 1) and 2).

In my opinion, the real challenge lies in 3). Have a look at sys/i386/i386/locore.s which is the kernel's entry point. The code goes on to init386() in sys/i386/i386/machdep.c and then calls into mi_startup() in sys/kern/init_main.c. The former is the machine dependent (MD) start-up code while the latter is the machine independent (MI) code.

As the name implies, the MD code is i386 specific and I wouldn't be surprised if there were a BIOS dependency in there. In fact, it seems init386() calls getmemsize() from sys/i386/i386/machdep.c which looks to me as if it went for the BIOS to query the system's memory size.

Also, mi_startup() is the core of the SYSINIT framework which orders and runs the constructors of various kernel subsystems. One of those subsystems is "bios32", declared in sys/i386/i386/bios.c. It looks like at least the APM functionality depends on that subsystem. I don't know if anything else depends on it.

Anyways, you shouldn't be discouraged by what I'm telling you. I'm merely trying to point you to the right places of the documentation which often times is in fact the code itself.
 
Thank you phs for your advice. I will surely not be discouraged by the challenges. Actually I was prepared for the sheer difficulty that lies in the kernel initialization (e.g. init386() and mi_startup()). However I was surprised to know that even the machine-independent mi_startup() contains some BIOS-specific code. I will definitely look into this part and find out if the APM module can be dropped in favor of ACPI.

I shall also make good use of the existing EFI loader from FreeBSD/ia64 as well as linux's elilo as my reference.
 
Somewhat off-topic to the thread, but as regards UEFI what I read in another thread elsewhere, many/some/(all?) hardware raid cards currently do not support use in a UEFI motherboard. Unsure if that one instance can be extrapolated to all motherboards etc...
 
That is very likely true, considering Raid controllers generally have built-in BIOS that chained with motherboard BIOS.
Probably only a select Intel Raid controllers can work with EFI.

Thank you for your information though.
 
Did this project ever get approved as a Summer of Code project? I'm trying to get FreeBSD running on a MacBook Pro, so I'd like to see a proper EFI/GPT system as opposed to the current BIOS/MBR solution.
 
Hello emc2. Unfortunately my proposal was not accepted and neither was any other proposal on the same project.
 
Slightly off-topic, and can be risky to implement, but you have heard of coreboot I assume? AFAIK it should be able to build the BIOS for a large number of systems, including EFI running ones. If you prefer EFI to BIOS, that's different.
 
I read somewhere that EFI boot on i386/amd64 has apparently been restarted as part of 9-CURRENT development. According to Rui Paolo's blog, he apparently had developed an EFI loader at some point which can load an ELF kernel, but does not boot it.

In any case, FreeBSD on a MacBook has become a personal project of mine, so I would certainly like to work on getting an EFI boot process working, if anyone else is still interested.
 
Back
Top