TianoCore on FreeBSD/amd64

I’m attempting to build the TianoCore code base on FreeBSD/amd64. Here’s what I did so far.

  • In order to be able to check out the EDK2 sources, I installed the devel/subversion port. To check out the source tree, I did this in my home directory:

    $ svn co https://edk2.tianocore.org/svn/edk2/trunk/edk2 edk2
    
  • I installed the java/diablo-jdk15 port.
  • Downloaded Apache Ant 1.6.5. I didn’t install it through the port but instead downloaded the binary distribution and extracted the archive under /opt since the EDK2 build framework requires very specific versions of the tools.
  • Did the same thing with Ant-Contrib 1.0b3, XMLBeans 2.1.0 and Saxon 8.1.1.
  • I created a symbolic link at /opt/xmlbeans-2.1.0/lib to /opt/saxon-8.1.1/saxon8.jar. The build notes for the EDK said a copy was needed, but a symbolic link works just as good. I guess they were running Windows or didn’t know about links. Whatever.
  • Then I set up the environment for the build process as described in the build notes. This is what I did (note that my shell is bash):

    $ export WORKSPACE=/home/phs/edk2
    $ export JAVA_HOME=/usr/local/diablo-jdk1.5.0
    $ export ANT_HOME=/opt/apache-ant-1.6.5
    $ export XMLBEANS_HOME=/opt/xmlbeans-2.1.0
    $ export PATH=$PATH:$ANT_HOME/bin:$XMLBEANS_HOME/bin
    
  • I kicked off the build process with this command:

    $ bash edksetup.sh newbuild
    

    Unfortunately, the build fails with an error:

    BUILD FAILED
    /usr/home/phs/edk2/Tools/build.xml:22: The following error occurred while executing this line:
    /usr/home/phs/edk2/Tools/CCode/Source/build.xml:247: The following error occurred while executing this line:
    /usr/home/phs/edk2/Tools/CCode/Source/PeCoffLoader/build.xml:68: ar failed with return code 139
    /phs/edk2/Tools/CCode/Source/PeCoffLoader/build.xml:68: ar failed with return code 139
    

    This error can be solved by using a GCC that produces PE/COFF binaries instead of the default ELF images.

Qemu and Coreboot on FreeBSD/amd64

Today I tried to boot FreeBSD inside Qemu, using coreboot. I already wrote a short guide on how to do this, but I only tested it on a FreeBSD/i386 host. Now I’m trying to do the same thing, except this time the host is a FreeBSD/amd64 system.

I encountered several problems and I’m going to describe them along with the workarounds here.

First, the devel/dev86 port I created was marked as running on i386 only. I initially did this because I wasn’t sure if the software would run on amd64, but after testing it I can say that it does work. So the port needs a little tweaking, namely this line

ONLY_FOR_ARCHS= i386

needs to be extended to

ONLY_FOR_ARCHS= i386 amd64

or maybe even removed completely.

Second, the RomCC utility used in the coreboot build process crashes, apparently due to a change in GCC 4 as opposed to GCC 3.4 used in older versions on FreeBSD. It crashes in a function called “free_basic_block” and the workaround is this:

Index: util/romcc/romcc.c
===================================================================
--- util/romcc/romcc.c  (revision 3088)
+++ util/romcc/romcc.c  (working copy)
@@ -15083,6 +15083,8 @@

static void free_basic_block(struct compile_state *state, struct block *block)
{
+       return;
+
      struct block_set *edge, *entry;
      struct block *child;
      if (!block) {

Third, the linker on FreeBSD/amd64 does not understand the -m32 flag. So I needed a cross compiler for i386. Warner Losh has an entry in his blog that describes how to cross build FreeBSD. I don’t need all of FreeBSD but only the compiler, so I use this:

$ cd /usr/src
$ export TARGET=i386
$ export TARGET_ARCH=i386
$ make toolchain

This gives me an i386 cross compiler in /usr/obj/i386/usr/src/tmp/usr/bin that I need to use to compile coreboot. I did this to tell the GNU make utility to use the cross compiler:


gmake CC=/usr/obj/i386/usr/src/tmp/usr/bin/gcc


There is one outstanding problem: Qemu crashes when I try to use coreboot as a BIOS replacement. It may have to do with the version of Qemu I’m using right now. I’ll try to use an older version later this afternoon to see if it solves the problem.

Using Qemu 0.9.0 with the required patches (see the Qemu Build Tutorial) made the problem go away and I’m now able to boot FreeBSD/i386 8-CURRENT inside Qemu, using coreboot and ADLO. I’ve uploaded a complete archive of the port files to the coreboot wiki, see this link.