FreeBSD EFI bootloader concerns

Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

FreeBSD EFI bootloader concerns

Postby jasonnfls » 30 Mar 2011, 07:32

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.
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby phs » 07 Apr 2011, 19:10

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.
phs
Junior Member
 
Posts: 7
Joined: 16 Nov 2008, 20:48

Postby jasonnfls » 08 Apr 2011, 05:16

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.
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby phs » 08 Apr 2011, 20:51

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.
phs
Junior Member
 
Posts: 7
Joined: 16 Nov 2008, 20:48

Postby jasonnfls » 11 Apr 2011, 07:06

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?
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby phs » 11 Apr 2011, 13:40

Yes, but you may or may not be able to use features like rebooting or powering off.
phs
Junior Member
 
Posts: 7
Joined: 16 Nov 2008, 20:48

Postby jasonnfls » 11 Apr 2011, 16:54

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:
[FILE]1) [/FILE]an EFI application that loads 2);
[FILE]2) [/FILE]a patched [FILE]/boot/loader[/FILE] that utilizes EFI instead of BIOS and loads 3);
[FILE]3) [/FILE]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.
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby phs » 11 Apr 2011, 18:36

Hi,

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

In [FILE]sys/boot[/FILE], 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 [FILE]sys/i386/i386/locore.s[/FILE] which is the kernel's entry point. The code goes on to [FILE]init386()[/FILE] in [FILE]sys/i386/i386/machdep.c[/FILE] and then calls into [FILE]mi_startup()[/FILE] in [FILE]sys/kern/init_main.c[/FILE]. 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 [FILE]init386()[/FILE] calls [FILE]getmemsize()[/FILE] from [FILE]sys/i386/i386/machdep.c[/FILE] which looks to me as if it went for the BIOS to query the system's memory size.

Also, [FILE]mi_startup()[/FILE] 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 [FILE]sys/i386/i386/bios.c[/FILE]. 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.
phs
Junior Member
 
Posts: 7
Joined: 16 Nov 2008, 20:48

Postby jasonnfls » 12 Apr 2011, 01:58

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. [FILE]init386()[/FILE] and [FILE]mi_startup()[/FILE]). However I was surprised to know that even the machine-independent [FILE]mi_startup()[/FILE] 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 [FILE]elilo[/FILE] as my reference.
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby jb_fvwm2 » 13 Apr 2011, 03:18

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...
jb_fvwm2
Senior Member
 
Posts: 1503
Joined: 16 Nov 2008, 19:19

Postby jasonnfls » 13 Apr 2011, 03:32

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.
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby emc2 » 12 May 2011, 19:13

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.
emc2
Junior Member
 
Posts: 17
Joined: 05 May 2011, 15:09

Postby jasonnfls » 13 May 2011, 11:21

Hello emc2. Unfortunately my proposal was not accepted and neither was any other proposal on the same project.
jasonnfls
Junior Member
 
Posts: 7
Joined: 30 Mar 2011, 07:05

Postby Beeblebrox » 06 Jun 2011, 09:02

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.
11-CURRENT_amd64_root-on-zfs_RadeonKMS
User avatar
Beeblebrox
Member
 
Posts: 838
Joined: 03 Sep 2010, 04:45

Postby emc2 » 28 Jul 2011, 12:05

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.
emc2
Junior Member
 
Posts: 17
Joined: 05 May 2011, 15:09


Return to FreeBSD Development

Who is online

Users browsing this forum: No registered users and 0 guests