bruce.simonson
Posts: 5
Joined: Wed Apr 08, 2015 6:06 am

Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 12:01 am

Greetings,

POST DISCUSSION EDIT:

Although the subject line is about writing RPi IMG files from an emulator on a PC, my original need was to update Python code on an RPi, when an internet connection isn't available and monitor/keyboard/mouse on the RPi is not an option. That problem may be solvable with a CAT5 cable between my PC and the RPi.

Here's a fine writeup on using a PC's screen/keyboard/mouse for working with a RPi, without an internet connection:

https://pihw.wordpress.com/guides/direc ... onnection/

----

The original discussion, about RPi emulation, follows. Upshot is that it's probably not worth the effort, reading and writing images for the RPi. Read on, for why:

----

Not sure which forum is appropriate for this question, so I will try this general discussion forum; please suggest alternative forum if appropriate.

I am at the point where I can work with RPi 2, write Python code, run the camera, etc. I have even written code that runs the camera on bootup (with automated login), takes a specified number of pictures with the camera (custom python program using picamera), and automatic shutdown (with a call to "sudo shutdown -h now" as the last line in the python program). So, I'm feeling fairly secure with my intermediate skill level.

At this point, I would like to be able to work like this, on occasion:

1) set up a RPi emulation in Windows 8.1
2) write and debug python programs in the emulator
3) write the emulated RPi and its python code, and /etc/profile and so forth, as a recovery.img file
4) write the recovery.img in step 3 to an SD card
5) use the SD card in step 4 to boot a RPi

I am finding a few web sites on how to emulate RPi in Windows (using software called QEMU), but before I go deep, I'm wondering if steps 3 through 5 have been done? If not, then it's back to using a monitor and keyboard with my RPi, or going headless, with SSH and a VNC viewer.

I would prefer to do most, if not all work, on my PC, since I won't always have an internet connection while I do this work, and hanging a monitor and wireless keyboard/mouse is annoying for the kind of work I'm doing.

In short, I want to develop in an Windows emulator, write the resulting image to an SD card, which can be used to boot up a RPi. In practice, has anyone successfully done step 3?

Has this been solved?
Last edited by bruce.simonson on Sun Jun 28, 2015 10:51 pm, edited 2 times in total.

Heater
Posts: 15950
Joined: Tue Jul 17, 2012 3:02 pm

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 12:58 am

If you are programming in Python why do you need a Pi emulator? Things like the camera module and GPIO are not available to normal emulations like Qemu. Why not write and test and debug your Python on the PC and then download it to the Pi. This is how I generally work with JavaScript running under node.js.

In fact what I do is write the code on a PC. Maintain it in a git repository on github and then from there I can "git pull" it down to any Pi any where.

All that messing around with an emulation and moving images around will be very slow and tedious.
Memory in C++ is a leaky abstraction .

bruce.simonson
Posts: 5
Joined: Wed Apr 08, 2015 6:06 am

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 1:39 am

Heater: Good points, especially that the camera and GPIO aren't available in emulators. I didn't know that, but I'm not surprised.

Yes, what I'm considering is painful, I know -- reading and writing images to SD cards has been slow, in my experience.

However, for my application, the issue is getting new Python code to the RPi, without an internet hookup, and without hooking up a monitor to the PI and a keyboard and a mouse, and developing on the RPI. I just want to substitute new Python program that I wrote on my PC, into the bootup sequence that I've got going on the RPi, without having IO or internet on the RPi. Hence, seemed like substituting a new image might be the way to go, painful as it may be.

However, I can see writing my Python code on the PC, and then, somehow (?) taking that program file, and substituting it for the one on the RPi's SD card would be fine. But I don't see how to do that -- I can't read directories and files on the RPi's SD card (linux partition?) from the PC. And without seeing the directories and files on the RPi's SD card, I can't see how to directly copy my new PC Python file to the RPi card. I know I could use FTP for this, but remember, an internet hookup isn't available.

---

Is there a way to read an RPi's SD card (Debian) on a PC, and write files from the PC to the card? (A different question than the original, but this would solve my problem). I'll look for a thread on this, but please let me know, if you've got an answer already.

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 4:18 am

One option is to install a linux VM on your windows machine, it should e able to read the SD card without any problems (assuming you can hand the SD card to the VM).
(better yet, upgrade your PC to Linux and if you have to run Windows in a VM :-)

There are tools to let yo read ext partitions on windows but I've never used them so I can't recommend one.

You could hook up the serial console on the PI (IIRC windows has "hyperterminal", but PuTTY works fine too).

If you don't have network connectivity 'cos it's an A model then perhaps the easiest thing to do is get a B for development and then put the SD card back in the A for deployment. (note that you don't need "internet" connectivity, just a network cable from you PC to the Pi. Either enable IPv6 on the Pi or try "raspberrypi.local" to connect to it, lots of ways to skin that cat)

Heater
Posts: 15950
Joined: Tue Jul 17, 2012 3:02 pm

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 5:44 am

bruce.simonson,

Ah, "without an internet hookup, and without hooking up a monitor to the PI and a keyboard and a mouse" why didn't you spell out the problem in the opening post?

So often I forget that people using Pi are often using Windows on their PC. They have such difficulties and problems that I had long since forgotten about if I ever new them at all.

In this case for example I would just pop the SD card into the card reader on my PC and copy whenever files I like onto it. Put the SD back into the Pi and see how it runs.

You can do this too. Either run Debian on your PC, or run Debian inside a virtual machine on your PC, perhaps VirtualBox perhaps vmware. Or get yourself another Pi that you can connect to the PC over Ethernet or WiFi and put a USB SD card reader into that.
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 7:11 am

bruce.simonson wrote: In short, I want to develop in an Windows emulator, write the resulting image to an SD card, which can be used to boot up a RPi. In practice, has anyone successfully done step 3?

Has this been solved?
It's easier and cheaper and more sane to develop on a Raspberry Pi. You can set up a development system for $35 plus the cost of an 8GB microSD by buying a second RPi. It's not hard to connect that directly to a Windows system with a cat5 cable and share the RPi desktop using PuTTY, VNC and/or MobaXterm.

It's not been solved because nobody want's to emulate RPis on Windows, QEMU is a project that stalled as nobody is interested in keeping the QEMU kernel in step with the RPF kernel for the real hardware.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

bruce.simonson
Posts: 5
Joined: Wed Apr 08, 2015 6:06 am

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 10:13 pm

Greetings, and thanks.

Seems like I've picked the hard way to do this -- i.e., updating code on a RPi's SD card, without an internet connection to the RPi, or standing up a monitor and keyboard / mouse on the RPi.

A linux emulator from Windows would probably be all that is needed, so I can read the RPi's SD card from Windows, and drop in the new Python files as needed. Sure would beat moving images around.

I'll check the forums (and the net) for tools that will let me read/write from/to the RPi's SD card, from windows, and try that route. Unless any of you folks have a good suggestion on how to manage reading the RPi's linux partition from windows. Save me a trip to the internet?

Cheers.

bruce.simonson
Posts: 5
Joined: Wed Apr 08, 2015 6:06 am

Re: Emulate RPi in windows; write resulting IMG to SD card

Sun Jun 28, 2015 10:24 pm

Greetings.

Missed a similar thread, happening about a month ago (May 2015), with a solution that should work for me.

DougieLarson: viewtopic.php?p=764669#p764669

A very simple solution, suggesting connecting the PC to RPi with CAT5. Probably all that I need.

As for emulating RPi2 on Windows, doesn't seem like a reasonable activity. Hard to get to work, if at all, and AFAIK, picamera and GPIO won't ever work in an emulator, so what's the point?

Cheers.

Return to “General discussion”