AlanC5 / Zephyr

Smart Fan Prototype
0 stars 0 forks source link

Raspberry Pi Simulator #5

Open tzhao95 opened 7 years ago

tzhao95 commented 7 years ago

Develop or find a way to test code designed for a Raspberry Pi on a PC or Mac. This essentially will allow us to test our code without needing to plug it into the raspberry pi. Awkward thing about this is we are basically trying to use one computer to pretend to be a different computer.

AlanC5 commented 7 years ago

The Raspbian Image (ARM Processor) https://www.raspberrypi.org/downloads/raspbian/

AlanC5 commented 7 years ago

QEMU Solution https://gist.github.com/hfreire/5846b7aa4ac9209699ba https://www.qemu.org/download/#macos

AlanC5 commented 7 years ago

Alternative Debian Solution (Raspbian is based off of Debian), Not ideal as it does not emulate the processor. https://grantwinney.com/how-to-create-a-raspberry-pi-virtual-machine-vm-in-virtualbox/

AlanC5 commented 7 years ago

Beginning with QEMU Solution proposed by bainss commented on Apr 7

AlanC5 commented 7 years ago

Emulation is a success with the exception of the ssh. It seems others are experiencing a similar problem on the thread.

AlanC5 commented 7 years ago

DOES NOT WORK

Install QEMU OSX port with ARM support

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" && brew update && brew install qemu

export QEMU=$(which qemu-system-arm)

Dowload kernel and export location

curl -OL https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.4.34-jessie

export RPI_KERNEL=./kernel-qemu-4.4.34-jessie

Download filesystem and export location

curl -o 2017-03-02-raspbian-jessie.zip -L http://downloads.raspberrypi.org/raspbian/images/raspbian-2017-03-03/2017-03-02-raspbian-jessie.zip

unzip 2017-03-02-raspbian-jessie.zip

export RPI_FS=./2017-03-02-raspbian-jessie.zip

Tweak filesystem: start qemu with init flag, switch to guest window to execute tweak and close window afterwards

$QEMU -kernel $RPI_KERNEL -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -drive "file=2017-03-02-raspbian-jessie.img,index=0,media=disk,format=raw"

Enter these on the qemu terminal and exit after

sed -i -e 's/^/#/' /etc/ld.so.preload sed -i -e 's/^/#/' /etc/ld.so.conf sed -i -e 's/^/#/' /etc/fstab

Emulate Raspberry Pi

$QEMU -kernel $RPI_KERNEL -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -drive "file=2017-03-02-raspbian-jessie.img,index=0,media=disk,format=raw" -net user,hostfwd=tcp::5022-:22

Login to Raspberry Pi, note this fails

ssh -p 5022 pi@localhost

AlanC5 commented 7 years ago

It didn't work! Will try another method