Running MicroPython under Windows for IoT

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Running MicroPython under Windows for IoT

Post by pfalcon » Mon Dec 15, 2014 11:29 pm

Microsoft recently came out with initiative to provide special Windows and related tools to build IoT applications: http://www.windowsondevices.com/ . They provide development set consisting of Intel Galileo board and this special Windows version, and were kind enough to contribute it, which I'm taking as a chance to help stijn to maintain Windows version of MicroPython.

So, I tried to run MicroPython and it starts and executes simple commands well. Next step is running the testsuite, and that's where I hit the problems. Testsuite requires CPython (to compare results against), and the latest versions of CPython for Windows are distributed as MSI archive. But Windows for IoT doesn't have "msiexec" tool to install it. I tried to install it via generic redistributable package offered by Microsoft, but that didn't really work. Generally, it seems that any GUI applications don't work on Windows for IoT - it's essentially a headless version of Windows (you work with it accessing command line via telnet).

All the above didn't really stop me, and I installed CPython from MSI on my Linux box in Wine, verified it starts, them carefully copied all its files and (hopefully) all dependent DLLs to Galileo. No avail - CPython doesn't run (no errors, just running command exits immediately). More info may be available to my post to python-dev: https://mail.python.org/pipermail/pytho ... 37234.html


Bottom line? MicroPython already support Windows for IoT better than CPython ;-). I'm currently thinking how to get testsuite on it running.

I hope to update this topic from time to time with more news/results.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Running MicroPython under Windows for IoT

Post by stijn » Tue Dec 16, 2014 8:44 am

If you have an msi but want a portable version, it is often sufficient to run

Code: Select all

msiexec /a PathToMSIFile /qb TARGETDIR=DirectoryToExtractTo
to get all files out of it. Or else try to open the msi with 7zip.

How did you get micropython running on it exactly? Was it built on the board itself, or a cross-compiled mingw version?

Anyway regarding CPython not running: last time I checked CPython insisted on consulting the registry upon startup. Maybe there is a problem with that. What is the return code?
Haven't looked into IoT but is it possible to build an executable, put it on a suported device and then debug it remotely using Visual Studio? That would by far be the quickest way to figure out where CPython fails.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Running MicroPython under Windows for IoT

Post by pfalcon » Wed Dec 17, 2014 9:54 pm

Thanks for the hints!
Or else try to open the msi with 7zip.
That's what I tried, but that leads to flat and mangled filenames, I figure a lot of metadata kept in MSI somewhere else but raw filenames.
How did you get micropython running on it exactly? Was it built on the board itself, or a cross-compiled mingw version?
Surely, crosscompiled under Linux.
Anyway regarding CPython not running: last time I checked CPython insisted on consulting the registry upon startup. Maybe there is a problem with that.
Both msiexec and python behaved the same, and for both it looked like some missing dependency. I would imagine that on normal GUI Windows at that place there would be popup with the name of missing DLL, but as there's no GUI on Galileo, that's it - silent quit. Of course, it may be not missing DLL, but missing function in it, etc.
What is the return code?
Windows has return codes? D'oh, I remember what it is whole day! It's %errorlevel, right? But that can be used only in .bat files, no? Feel free to give an exact command to try next time (which mat take few weeks).
Haven't looked into IoT but is it possible to build an executable, put it on a suported device and then debug it remotely using Visual Studio? That would by far be the quickest way to figure out where CPython fails.
Well, I'm more interested in validating MicroPython on that platform, so currently thinking how to run testsuite without CPython and unix shell.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Running MicroPython under Windows for IoT

Post by Damien » Wed Dec 17, 2014 10:40 pm

To run the test suite without CPython, didn't you add an option to generate the .exp files so the output of uPy can be compared against them?

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Running MicroPython under Windows for IoT

Post by pfalcon » Wed Dec 17, 2014 11:32 pm

Yes, and also a unix shell script to run testsuite against those .exp files. What to do when neither CPython nor unix shell is available? Nope, my solution is not to write bunch of implementations in other shells, but to (ab)use micropython to run it. It's not the most formally correct idea to use device-under-test to manage testing itself, but with some caution, why not? ;-) Expect patches soon.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Running MicroPython under Windows for IoT

Post by stijn » Thu Dec 18, 2014 9:24 am

on standard windows you'd check dependencies using dependency walker or dumpbin. (first if freeware, dumpbin is part of VS but you can probably find it standalone on the net)
The first is the nicest one but I'm not sure it'll run as it depends on gdi32.dll which is the graphical layer. Anywaway you use them like

Code: Select all

depends /c /ot:out.txt /path/to/python.exe
type out.txt

dumpbin /dependents /path/to/python.exe
Display return codes with echo %ERRORLEVEL%, doesn't matter if it's in a bat file or not.

Anyway I'll check if it's possible to run IoT in a virtual machine/quemu or so, that would be nice to test it

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Running MicroPython under Windows for IoT

Post by pfalcon » Thu Dec 18, 2014 12:34 pm

Well, I used to have ldd for (native) Windows: http://mingwrep.cvs.sourceforge.net/vie ... ldd-win32/ . Nowadays I just search for ".dll" in a binary viewer. As I mentioned, I tried to copy any non-system DLLs (like used MSVC runtime) over to Galileo. Of course, there could be user error.

Yes, there's an Windows for IoT SD image provided somewhere on the site in the starter message, feel free to look into it if you have time/interested.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Running MicroPython under Windows for IoT

Post by stijn » Thu Dec 18, 2014 4:02 pm

Tried the image both in qemu and vbox, but no avail. It does enter boot stage but then Windows boot Manager complains about boot configuration errors. I assume because the virtualized x86 environment isn't close enough to the Galileo environment.

Post Reply