20

I followed this guide to emulate RPI on OSX via VirtualBox and it works. Now I'd like to simplify things a bit since this solution involves running debian in a virtual machine just to run qemu on top of.

I googled for guides on how to setup qemu straight on osx and found Matthew Yee-King's guide. I followed the instructions and all seems fine until the last part. When I launch qemu-system-arm I see the QEMU window appear but the application seems to freeze. After a while it appears as Not Responding in Activity Manager.

What am I missing ? How do I emulate RPI on OSX with QEMU ?

  • 2
    What do you want to emulate? Actually RPi's Raspbian is just Debian Linux for ARM architecture plus RPi's specific drivers/libraries and pre-installed software. QEMU doesn't emulate RPi's GPIO or GPU, it's just generic ARM-based computer which allows you to start Raspbian. So if you want to play with XBMC, file server and so on, just install Debian Wheezy x86 on VirtualBox and have fun. You can also install Scratch, PyGame etc – kolontsov Apr 17 '13 at 23:21
  • I'm not sure I thinking this through correctly, but I'd like try OpenCV and maybe OpenNI for ARM on the PI and thought about doing some tests first using an emulator first( so I can workout how much space I need for all that, play with that on the go, etc.) Is the VirtualBox option the simpler solution ? – George Profenza Apr 17 '13 at 23:29
  • 1
    Yes, VirtualBox is simpler/faster than ARM emulation with QEMU. By the way, you can compile OpenCV for OS X (opencv.org) or download it in Linux in VirtualBox. It's the same across all platforms. I tried to use OpenCV on RPi for face recognition, it was very slow. Can't recommened anything on OpenNI, sorry (but I don't think that QEMU emulates camera and RPi's speed correctly). – kolontsov Apr 18 '13 at 5:39
  • @vk2 although off topic to the main question, but related to my purpose, I've recently released an OpenCV wrapper for the Pi Camera module: PiCapture, also available as an OpenFrameworks addon. Speed is pretty decent, especially compared to using a USB camera – George Profenza Apr 12 '14 at 18:11
16

To set up an emulated environment of the Raspberry Pi software on OSX one will need:

  • A Cross-Compiling Tool for the CPU architecture of RPi. ( eg. ARM EABI Toolchain )
  • The RPi Kernel.
  • The RPi root filesystem.
  • The Emulator (QEMU).
  • The Cross-Compiling Tool for the ARM architecture.

Assuming one already have the latest Xcode and command line tools from Apple Developer and homebrew installed, then should install the dependencies:

brew install mpfr gmp libmpc libelf texinfo

Grab and compile the tool:

mkdir ~/rpi
mkdir ~/rpi/arm-cs-tools
git clone https://github.com/jsnyder/arm-eabi-toolchain.git
cd arm-eabi-toolchain
PREFIX=$HOME/rpi/arm-cs-tools make install-cross
make clean
echo “export PATH=$HOME/rpi/arm-cs-tools/bin:$PATH” » ~/.bash_profile

The RPi Kernel Compilation

mkdir ~/rpi/kernel
cd ~/rpi/kernel
git clone --depth=1 https://github.com/raspberrypi/linux.git
cd linux

Grab the config file and configure the kernel:

cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
make ARCH=arm CROSS_COMPILE=~/rpi/arm-cs-tools/bin/arm-none-eabi- menuconfig

Save the configuration and let’s build the kernel afterwards. Note that the compilation should fail and complain about an inclusion in scripts/mod/mk_elfconfig. If it does, one must create the file:

sudo touch /usr/local/include/elf.h

Edit it and write the following:

#include <libelf.h>

#define R_386_NONE 0
#define R_386_32 1
#define R_386_PC32 2
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_MIPS_NONE 0
#define R_MIPS_16 1
#define R_MIPS_32 2
#define R_MIPS_REL32 3
#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6

and follow through the building process:

make ARCH=arm CROSS_COMPILE=~/rpi/arm-cs-tools/bin/arm-none-eabi- -k

The image file is created and located as arch/arm/boot/zImage.

The Emulator

Due to a bug of a white screen hanging QEMU if compiled with llvm one must install the package apple-gcc42 from the homebrew’s dupes repository.

brew install homebrew/dupes/apple-gcc42

And then compile and install qemu like:

brew install qemu —use-gcc

Now we’re left with all we need to start the RPi distribution so let’s start it like:

qemu-system-arm -M versatilepb -cpu arm1176 -hda debian6-19-04-2012.img -kernel zImage -append “root=/dev/sda2” -serial stdio -usbdevice tablet

As refered on mluis's website.

  • Answered the question with essential parts. – mluis Jul 1 '14 at 13:01
  • 1
    As a sugestion from @user1104942, one might have to change the following in order to work in Yosemite. #include <libelf/libelf.h> #define R_386_NONE 0 #define R_386_32 1 #define R_386_PC32 2 #define R_ARM_NONE 0 #define R_ARM_PC24 1 #define R_ARM_ABS32 2 #define R_MIPS_NONE 0 #define R_MIPS_16 1 #define R_MIPS_32 2 #define R_MIPS_REL32 3 #define R_MIPS_26 4 #define R_MIPS_HI16 5 #define R_MIPS_LO16 6 #define R_IA64_IMM64 7 #define R_PPC_ADDR32 8 #define R_PPC64_ADDR64 9 #define R_SH_DIR32 10 #define R_SPARC_64 11 #define R_X86_64_64 12 #define R_390_64 13 #define R_MIPS_64 14 – mluis Dec 11 '15 at 11:06
  • Wouldn't installing this tap: github.com/nitsky/homebrew-stm32 do the same as github.com/jsnyder/arm-eabi-toolchain.git? – andsens Feb 13 '16 at 13:33
  • after all emulated and developed, can i just store this .img in a SD card and input in raspberrypi? – mariomol Feb 13 '16 at 16:15
  • Tried this on macOS 10.13.4 and only got as far as make install-cross before hitting issues. Also, I learned from Homebrew apple-gcc42 "does not compile or function as expected on macOS versions newer than Mavericks due to an upstream incompatibility." – Josh Habdas Jun 19 '18 at 9:42
3

There is a ready to run paid option that runs over QEMU: https://snorfi.us/raspiemu/

If you don't want to pay for it you can also download the alpha version in https://sourceforge.net/projects/raspberrypiemulator/

0

It looks like the 'configure the kernel' step needs a bit more. Note that

make ARCH=arm CROSS_COMPILE=~/rpi/arm-cs-tools/bin/arm-none-eabi- menuconfig 

should be one of the files in that directory like arm-none-eabi-ar or arm-none-eabi-as etc...

protected by Darth Vader Aug 2 at 8:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.