Qemu/Junos on OSX 10.7.3

This is an old post and I would like to share it with you. It's about Qemu/Junos with GNS3 v0.8.2 Beta2 over OSX 10.7.3. 
Recent updates : it works also with Qemu1.2.0

I used GNS3 v0.8.2 with Qemu-0.11.0 patched. Unfortunately, my Qemu crashed when I launched Junos OS. Maybe because of OSX's 64 bit implementation... So I decided to dig it the issue and understand why it didn't work on Mac OSX Lion. Everyone can do that. I'm not a developer. 

Now, it works and I want to share everything with you. Take your day to do all this stuff. 
First, here are some requirements on OSX 10.7.3 : 
  • Xcode 4.1 
  • MacPorts 2.0.3 
  • GNS3 v0.8.2 Beta2 
  • Qemuwrapper from the GNS3 v0.8.2 Beta2 zip archive
You need a non-LLVM (Low Level Virtual Machine) version of GCC, which is no longer available on Xcode 4. So you have to compile yourself this famous "non-LLVM" GCC. 
 For that, go on this site : http://read.seas.harvard.edu/cs261/2011/tools.html and do all steps in the "Building your own Toolchain" part. Don't install the suggested Qemu simulator 0.15.0-jos (I had some issues with the following files : slirp.c and pcap.h) 
Then, download Qemu 0.14.1 from this page : http://download.savannah.gnu.org/releases/qemu/ and patch it with 0.14.1 patches on this link http://forum.gns3.net/download/file.php?id=859
sudo tar xjf qemu-0.14.1.tar.gz 
sudo rm xjf qemu-0.14.1-gns3_patches.tgz 

sudo mv qemu-0.14.1_* qemu-0.14.1 cd qemu-0.14.1 
sudo patch -p1 -i qemu-0.14.1_hw_e1000_c.patch 
sudo patch -p1 -i qemu-0.14.1_block_raw-win32_c.patch 
sudo patch -p1 -i qemu-0.14.1_Makefile_objs.patch 
sudo patch -p1 -i qemu-0.14.1_net_c.patch 
sudo patch -p1 -i qemu-0.14.1_net_h.patch 
sudo patch -p1 -i qemu-0.14.1_net_udp_c.patch 
sudo patch -p1 -i qemu-0.14.1_net_udp_h.patch

You have also to copy the "gnutls" folder in your Qemu folder :

cp /opt/local/include/gnutls .

Now, configure Qemu with the following options :

sudo ./configure --prefix=/usr/local --disable-sdl --enable-cocoa --disable-docs --target-list="i386-softmmu x86_64-softmmu" --cc=/usr/bin/gcc-4.2 --host-cc=/usr/bin/gcc-4.2

Compile and Install :  

sudo make 
sudo make install

After that, you can check that Qemu works and loads a Junos image :  

sudo qemu -L . -m 512 -hda junos.img -serial \ telnet:,server,nowait,nodelay -localtime

Open your GNS3 and load a Junos image. In my case, the Qemu window stayed open (no crash, good news !). But I've got a error message during the boot : dog: ERROR - reset of uninitialized watchdog 
Qemu version above 12.0 contains a bug in bios which causes some troubles during the boot of Junos image. You need to add your own modified version of bios.bin with the CONFIG_SMBIOS parameter to 0. 
Go to this site for that : 

So to solve this issue, copy the modified "bios.bin" image to /usr/local/share/qemu/ directory.

sudo cp bios.bin /usr/local/share/qemu

Now you can run a Juniper router with your GNS3 :) 
Have fun !