How to build OpenBIOS on Mac OS X

From OpenBIOS
Revision as of 16:13, 18 December 2012 by Programmingkid (talk | contribs)
Jump to navigation Jump to search


Apple’s supplied GCC on Mac OS X does not support the elf binary format. So compiling OpenBIOS on Mac OS X is not easy. Thankfully someone has already made a PowerPC cross compiler for Mac OS X that can compile OpenBIOS. Note: this tutorial was made with Mac OS 10.6. I suggest you use Mac OS 10.5 or higher when trying to build OpenBIOS.

Disclaimer: You assume all risk involved when following this tutorial.


Part 1: Installing the cross compiler on Mac OS X

1). Download the AWOS cross compiler: http://awos.wilcox-tech.com/downloads/AWOS-CC.bz2

2) Expand this bz2 file by double clicking on it.

3) Rename the file AWOS-CC to AWOS-CC.img.

4) Open the image file.

5) Open the “AWOS Cross-Compiler for OS X” file on the newly mounted disk.

6) Select the “PowerPC Support” check box only when given the option.

7) Continue with the installation until it is finished.

8) Add the new compiler's folder to the PATH variable. This is the command you use if you are in the Bash shell: export PATH=:/usr/local/ppcelfgcc/bin.

Note: the above step will probably need to be repeated with each new session of the shell you start. It can be made permanent by altering the .bashrc file for the Bash shell. Check your shell's documentation for more information.


This should conclude installing the compiler.


Next the switch-arch configuration script needs to be altered so it can work on Mac OS X.

Part 2: Required changes to OpenBIOS source code


1) Open the Terminal application.

2) Change the current directory to the inside of the openbios-devel folder.

3) Copy this patch and place it into a file. Call the file mac.patch.

Index: config/scripts/switch-arch
===================================================================
--- config/scripts/switch-arch	(revision 1080)
+++ config/scripts/switch-arch	(working copy)
@@ -89,16 +89,27 @@
 
 archname()
 {
-    HOSTARCH=`uname -m | sed -e s/i.86/x86/ -e s/i86pc/x86/ \
-	-e s/sun4u/sparc64/ -e s/sparc$/sparc32/ \
-	-e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
-	-e "s/Power Macintosh/ppc/"`
+	OS_NAME=`uname`
+	if test "$OS_NAME" = "Darwin"; then     # Can't depend on uname -m on Mac OS X
+		IS_64BIT=`sysctl hw.cpu64bit_capable`
+		if test "$IS_64BIT" = "hw.cpu64bit_capable: 1"; then
+			HOSTARCH="amd64"
+		else
+			HOSTARCH="x86"
+		fi
+	else
+		 HOSTARCH=`uname -m | sed -e s/i.86/x86/ -e s/i86pc/x86/ \
+		-e s/sun4u/sparc64/ -e s/sparc$/sparc32/ \
+		-e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
+		-e "s/Power Macintosh/ppc/"`
+	fi
 }
 
 select_prefix()
 {
-    for TARGET in ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi-
+    for TARGET in ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi- ppc-elf-
     do
+        echo "Trying ${TARGET}gcc"
         if type ${TARGET}gcc > /dev/null 2>&1
         then
             return


4) Apply the patch to your OpenBIOS source code using the patch command.
Example: patch -p0 < ~/Desktop/mac.patch

If everything went to plan, you would see something like this: patching file config/scripts/switch-arch.
If an error message was displayed instead, try changing the p0 argument to p1 or p2. If this doesn't help, verify you are in the openbios-devel directory. If you are still stuck, applying this patch by hand is an option.



That is all the changes that are needed. By this point, you should be able to configure and build OpenBIOS. Just type this command in the terminal and watch the show:

./config/scripts/switch-arch cross-pcc && make build-verbose

To test out your newly created binary in qemu, use the -bios option:
qemu-system-ppc -bios <path to binary>/openbios-qemu.elf.nostrip



This tutorial was made using information available on 12/17/12. It is possible things have changed since that time. If you encounter any problems, please report it to the openbios developer list: openbios@openbios.org.