hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:40 pm

INTRODUCTION

These are primarily the notes which accompany my "Disklessly booting Zeroes from Windows" adventure for those who want to join in with that -

https://www.raspberrypi.org/forums/view ... p?t=223336

Background

My original enquiry was where things stood regarding Windows use; whether a diskless Pi could be booted from Windows ? The answer is "Yes" for Windows XP and upwards.

That then expanded into whether it was possible to build one's own things to upload from Windows to a diskless Pi and the answer again is "Yes", and using Windows 10 and its Windows Subsystem for Linux turns out to be one way to do that.

It then gets a bit murky as to whether what's built and uploaded to a diskless Pi can interact as desired with Windows, and that's still being struggled with. It's partly working, and working in limited situations, but not all - Any help with that would be welcomed.

Rather than just ask the questions I set about trying to see what could be done, seeing what did work and what didn't.

I am currently wading through things so the adventure is by no means over but the following documents should help you get up to speed if you wish to follow in my footsteps, take it further, or somewhere else.

The journey so far has not been easy with plenty of detours, backtracking, tangential explorations and plenty of frustration along the way but the instructions below should help others get to something without the hard slog of getting there.

Hopefully this will be useful to someone some day but, even if not, documenting it means I know where to find the instructions when I come to do it again.

The documents are currently a work in progress but should be complete so far as what has been documented, but none the less - E&OE.

Comments, suggestions, improvements, additions and questions are welcomed. And please join in and have a go if you are feeling adventurous, at a loose end, or have a Pi Zero sitting there doing nothing.

Prerequisites for diskless booting
  • A Windows PC running XP upwards
  • A Pi Zero or Pi Zero W
  • A blank SD Card
  • A USB plug to micro-USB plug cable
Prerequisites for building uploads
  • A Windows 10 PC with Windows Subsystem for Linux (WSL) installed.
Optional but recommended
  • A HDMI or DVI-D monitor for the Pi
  • A mini-HDMI to 'whatever the monitor expects' cable
  • A terminal emulator installed on Windows ( eg Tera Term )
Documents

Phase 1 - Getting the basics to work
Phase 2 - Getting GPIO Expander booted
Phase 3 - Adding Lua and MicroPython
Phase 4 - Adding Full Python
Phase 5 - Adding an MSD device
Phase 6 - Enabling WiFi
Phase 7 - Enabling Bluetooth
Phase 8 - Adding our own application
Phase 9 - Booting from SD Card
Phase 10 - Other things to do
Phase 11 - The Windows side of things
Tips and Tricks

Notes

It may be possible to undertake development for a Pi A, Pi A+ and Compute Modules using the mechanism as described here, however I am currently restricting its scope to the Pi Zero and development is being undertaken with a Pi Zero W.

I am not going to update the history entries for the following documents for typo corrections or immaterial changes or minor clarifications, but I will note material changes, anything important added or noted. Unless I forget to.

Links

The original adventure : https://www.raspberrypi.org/forums/view ... p?t=223336

PHASE ONE - GETTING THE BASICS TO WORK

The first step is to ensure we can upload something to the Pi and have what is uploaded running. We will start by turning the Pi into a gadget which acts as an MSD device, something which is seen as a removable disk drive by Windows.

The 'rpiboot' software provided by the Raspberry Pi Foundation can do this by default out of the box.

Install rpiboot on Windows 10

1) Download rpiboot-setup.exe from -

https://github.com/raspberrypi/usbboot/ ... _setup.exe

2) Run rpiboot-setup.exe

The rpiboot software will be installed in -

C:\Program Files (x86)\Raspberry Pi

Check that rpiboot works

1) Put a blank SD card into your Pi
2) Don't connect the Pi to a power supply
3) Connect the Pi via USB cable to the PC
4) Go to C:\Program Files (x86)\Raspberry Pi
5) Run : rpiboot -d .\msd

Check the Pi has booted and running as an MSD device

If successful a new removable disk should be detected by Windows File Explorer

Windows may report errors with the disk but it seems that can be ignored and the Pi MSD removable disk will work despite whatever those errors are.

Go ahead; drag and drop things to it. Unplug it, re-insert it and rpiboot it again.

Notes

No output will appear on the monitor attached to the Pi.

The Pi must be unplugged from the PC's USB port and plugged back in for it to be able to accept a new rpiboot upload. This is because, as upload and booting progresses, the Pi changes its USB VID/PID identifier so is no longer seen as a Pi which can be used by rpiboot.

Do not drop any 'bootcode.bin' onto the MSD as, when the Pi is next powered-up with the card inserted, it will see that and try to boot from it rather than appearing as a bootable Pi. If you have done that; just remove the SD Card from the Pi and delete the bootcode.bin file.

Windows XP

The rpiboot executable should run on Windows XP upwards. In some cases there may be an issue with not being able to find BCM2708 or BCM2710 drivers when rpiboot is run.

If that is the case then it is worth rebooting, trying again, and if that doesn't fix things then for missing BCM2708 drivers -

Code: Select all

cd "\Program Files\Raspberry Pi\redist"
wdi-simple.exe -n "Raspberry Pi USB boot" -v 0x0a5c -p 0x2763 -t 0
And for missing BCM2710 drivers -

Code: Select all

cd "\Program Files\Raspberry Pi\redist"
wdi-simple.exe -n "Raspberry Pi USB boot" -v 0x0a5c -p 0x2764 -t 0
That wdi-simple.exe isn't intended to be run on XP but it does for me and solved my problems.

Links

Details of rpiboot : https://www.raspberrypi.org/documentati ... lashing.md
Download rpiboot-setup.exe : https://github.com/raspberrypi/usbboot/ ... _setup.exe
wdi-simple : https://github.com/pbatard/libwdi/blob/ ... i-simple.c
Tera Term download : https://osdn.net/projects/ttssh2/releases

History

11 Oct 2018 - Original document
Last edited by hippy on Sun Oct 14, 2018 1:16 pm, edited 6 times in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:41 pm

PHASE TWO - GETTING GPIO EXPANDER BOOTED

It's all well and good booting the supplied MSD application but it would be nice to install an application developed from scratch.

To begin with we will use an application which already exists and is known to work with rpiboot and the Pi Zero - GPIO Expander by Ben Nuttall -

https://bennuttall.com/raspberry-pi-zero-gpio-expander

Hopefully we will be able to modify that and use it as the basis of our own application.

Unfortunately GPIO Expander is a buildroot application which needs to be built using Linux. And more unfortunate still; that needs more memory than a Pi provides.

Luckily Windows 10 has Windows Subsystem for Linux (WSL) which is basically Ubuntu running under Windows which makes is very convenient because it means we can do Windows and Linux development on the same PC.

Not entirely without having to set some things up first.

Create a shared directory to move things between Windows and WSL

We need a means to be able to copy things from WSL so they can be seen by Windows. The easiest way to do that is to create a Windows directory which Linux can write to without problems -

Code: Select all

C:
MKDIR \wsl-share
MKDIR \wsl-share\buildroot
MKDIR \wsl-share\buildroot\info
In the original adventure I created 'C:\wsl-share\rpiboot' but this is a more sensible name, reflecting that files came form a Buildroot build and not from some other type of build.

The 'info' sub-directory is just to receive details of what was actually built which may prove useful later.

You can create sub-directories on a per application basis once you get seriously into things.

Install Windows Subsystem for Linux (WSL)

https://docs.microsoft.com/en-us/window ... tall-win10

It may be possible to install WSL on Windows 7 or 8 but I am going to assume Windows 10 as that is what it is primarily intended for and installing is a straight forward process.

If you are using Windows 7 or 8 and have managed to get WSL installed then everything here should be pretty much the same as described here.

Configure WSL

First, let's make sure WSL is up to date. Launch WSL and -

Code: Select all

sudo apt-get update
sudo apt-get dist-update
And, because we are going to run into problems with 'fakeroot' pretty soon, we might as well pre-empt that now -

Code: Select all

sudo update-alternatives --set fakeroot /usr/bin/fakeroot-tcp
And we'll install the stuff we'll need to make building the source code work -

Code: Select all

sudo apt-get install git-core build-essential rsync libncurses-dev unzip python bc
Some of those may already be installed.

Install the GPIO Expander source code

Code: Select all

cd ~
git clone --depth 1 https://github.com/raspberrypi/gpioexpander.git
cd gpioexpander
Tweak the build script

Code: Select all

nano ./build.sh
At the top of the file add -

Code: Select all

PRODUCT=buildroot
WSLSHARE=/mnt/c/wsl-share
Immediately before the 'echo "IP Configuration"' line, Add -

Code: Select all

uname -a
echo
Add at end of script -

Code: Select all

echo $BUILDROOT `date` > $WSLSHARE/$PRODUCT/info/build
cp ./gpioexpand/configs/gpioexpand_defconfig $WSLSHARE/$PRODUCT/info/
cp ./gpioexpand/board/kernelconfig-gpioexpand.fragment $WSLSHARE/$PRODUCT/info/
cp ./gpioexpand/board/overlay/etc/init.d/S99gpioext $WSLSHARE/$PRODUCT/info/
This passes information about what has been built back to the Windows side of things which may will prove useful later on.

Then, last of all -

Code: Select all

cp -r ./output/* $WSLSHARE/$PRODUCT
echo "Files copied to Windows filesystem"
echo
Press Ctrl-X, press the 'y' key, then return to save the changes.

This final 'cp' copy saves us from having to explicitly copy the WSL generated output to the 'C:\wsl-share\buildroot' folder so Windows rpiboot.exe can see them.

Because, let's just accept it; at some point in the future, we will otherwise forget to do that after a './build.sh' and will waste time scratching our heads and frustrated and wondering why the changes we made have not appeared on the Pi we have booted.

It might have been nice to copy the files directly into a sub-directory below the rpiboot.exe directory but writing to "C:\Program Files (x86)" and below is prohibited from within WSL.

Configure what we are building

Code: Select all

nano ./gpioexpand/configs/gpioexpand_defconfig
Change -

Code: Select all

BR2_TARGET_GENERIC_HOSTNAME="diskless"
BR2_TARGET_GENERIC_ROOT_PASSWD=""
That gives us a "diskless" host name which is different to the "extzero" which the GPIO Expander uses.

And, as life is short enough as it is, I am going to allow login as "root" without a password, simply so I don't have to type one every time. You can add a password if you wish.

It should be possible to have automatic login without having to specify "root" but that's an adventure for another day. We will live with how it is for now.

Some more tweaking

Code: Select all

nano ./gpioexpand/board/kernelconfig-gpioexpand.fragment
Change -

Code: Select all

CONFIG_LOCALVERSION="-wslbuilt"

Code: Select all

CONFIG_IPV6=n
Add -

Code: Select all

CONFIG_USB_CONFIGFS_RNDIS=y
CONFIG_USB_CONFIGFS_EEM=y
I am not sure if these last two are necessary or even do anything but they do no harm. I'm leaving them in rather than removing them and risk seeing something fail but you're welcome to leave them out and see how it goes.

The 'CONFIG_LOCALVERSION' is mostly so we can identify what we have and distinguish things from the standard GPIO Expander build

The 'CONFIG_IPV6=n' is because things simply don't seem to work with IPv6 enabled.

Tweak the gadget mode configuration

Code: Select all

nano ./gpioexpand/board/overlay/etc/init.d/S99gpioext
Replace the existing script in its entirety with -

Code: Select all

 #!/bin/sh

case "$1" in
  start)
        GADGET=/sys/kernel/config/usb_gadget/g1

        SERIAL="$(grep Serial /proc/cpuinfo | sed 's/Serial\s*: 0000\(\w*\)/\1/')"
        MAC="$(echo ${SERIAL} | sed 's/\(\w\w\)/:\1/g' | cut -b 2-)"
        MAC_HST="12$(echo ${MAC} | cut -b 3-)"
        MAC_DEV="02$(echo ${MAC} | cut -b 3-)"

        mount -t configfs none /sys/kernel/config
        mkdir -p $GADGET
        (cd $GADGET

# Need to change below
echo 0xf055 > idVendor
echo 0x0001 > idProduct
# Need to change above

        echo "0x0200" > bcdUSB
        echo "0x02" > bDeviceClass
        echo "0x00" > bDeviceSubClass
        echo "0x3066" > bcdDevice
        echo "1" > os_desc/use
        echo "0xcd" > os_desc/b_vendor_code
        echo "MSFT100" > os_desc/qw_sign

        mkdir strings/0x409
        echo $SERIAL > strings/0x409/serialnumber
        
# Need to change below ...
echo "Pimoroni Ltd." > strings/0x409/manufacturer
echo "PiratePython" > strings/0x409/product
# Need to change above

        mkdir configs/c.1
        mkdir configs/c.1/strings/0x409
# Need to change below ...
echo "CDC 2xACM+Mass Storage+RNDIS" > configs/c.1/strings/0x409/configuration
# Need to change above
        echo 500 > configs/c.1/MaxPower

        mkdir functions/acm.GS0
        mkdir functions/acm.GS1

        mkdir functions/rndis.usb0
        echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
        echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
        echo $MAC_HST > functions/rndis.usb0/host_addr
        echo $MAC_DEV > functions/rndis.usb0/dev_addr

        ln -s functions/rndis.usb0 configs/c.1
        ln -s configs/c.1 os_desc

        echo "20980000.usb" > UDC

        sleep 2

        echo "" > UDC

        ln -s functions/acm.GS0 configs/c.1
        ln -s functions/acm.GS1 configs/c.1

        echo "0x00" > bDeviceClass

        echo "20980000.usb" > UDC

        )

        # Set led0 trigger to none, so apps can use it for other purposes
        echo none > /sys/class/leds/led0/trigger
        echo 255 > /sys/class/leds/led0/brightness

        ifconfig usb0 172.16.0.99 up

        echo
        uname -a
        echo
        ifconfig -a
 	echo
        ;;
  stop)
	;;
  restart|reload)
	"$0" stop
	"$0" start
	;;
   *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?
Many thanks to Gadgetoid ( aka Philip Howard ), Pimoroni and PiratePython in getting all that to work, to present two ACM CDC serial interfaces and an RNDIS network interface to the PC the Pi is attached to.

The curent configuration is incomplete but works as is, is good enough for now.

And now we can start building things

Code: Select all

./build.sh
Some hours later ( four and a half for me ) you will probably encounter a failure -

Code: Select all

PATH="..." /home/me/gpioexpander/buildroot-2017.02/output/host/usr/bin/fakeroot -- /home/me/gpioexpander/buildroot-2017.02/output/build/_fakeroot.fs
fakeroot, while creating message channels: Function not implemented
This may be due to a lack of SYSV IPC support.
fakeroot: error while starting the `faked' daemon.
... more here...
The fix is likely -

Code: Select all

cp /usr/bin/fakeroot ./buildroot-2017.02/output/host/usr/bin/fakeroot
Then, as before -

Code: Select all

./build.sh
This second run of ./build.sh should only take a few minutes

Then it's "goodbye WSL" for now and back to Windows.

Use rpiboot to boot what you have just built on your Pi

Code: Select all

cd "\Program Files (x86)\Raspberry Pi"
rpiboot -d C:\wsl-share\buildroot
Be amazed and be astounded

Perhaps just a little. Once the Pi has booted you should see the familiar rainbow screen on the Pi's monitor, a load of booting messages and eventually a network list showing 'lo', and 'usb0'.

Windows Device Manager should have spotted that the Pi has presented two CDC ACM serial ports, automatically installed drivers, and given them COM Port Number.

It should also have spotted that the Pi presented an Remode NDIS interface, assigned a driver, but there is still a little configuration to do on the Windows side to make that usable. We will come back to that later.

For now we will simply access the Pi through the virtual serial port it has exposed which will be running a login shell.

Logging in to the Pi

Use a terminal emulator to connect to the COM Port which Windows has allocated the Pi. Press return and you should get a "Welcome to Buildroot" and a "diskless login" prompt. Note that "diskless" is the host name we set earlier.

Enter "root" as the login username, and because we did not set a password earlier, you are dropped straight into the command prompt. That's '#' here -

Code: Select all

Welcome to Buildroot
diskless login: root
# 

Code: Select all

# uname -a
Linux diskless 4.4.50-wslbuilt #1 PREEMPT Wed Oct 10 17:17:00 DST 2018 armv6l GNU/Linux

Code: Select all

# lua
-sh: lua: not found

Code: Select all

# micropython
-sh: micropython: not found

Code: Select all

# python
-sh: python: not found
Those last three are just to prove Lua, MicroPython and Python are not already included in the upload, that adding them in, as we will, is not just an exercise in pointlessness.

Notes

If you rpiboot the same on a Window XP, 7 or 8 system, Windows may not recognise the CDC ACM serial interface and may not automatically install drivers for that.

For Windows XP ( or was it 7 ? ) I installed Intel Android Drivers then force-updated via Device Manger to make the CDC ACM use those which got a COM port created which was usable -

https://software.intel.com/en-us/androi ... id-devices

Links

Ben Nuttall's Expander : https://bennuttall.com/raspberry-pi-zero-gpio-expander
Raspberry Pi Blog article :
https://www.raspberrypi.org/blog/gpio-expander
GPIO Expander Wiki : https://github.com/raspberrypi/gpioexpander/wiki
GPIO Expander source code : https://github.com/raspberrypi/gpioexpander
Installing WSL : https://docs.microsoft.com/en-us/window ... tall-win10
Tera Term details : https://ttssh2.osdn.jp/index.html.en
Tera Term download : https://osdn.net/projects/ttssh2/releases
Intel Android Drivers : https://software.intel.com/en-us/androi ... id-devices
Gadgetoid : https://gist.github.com/Gadgetoid
Pimoroni : https://shop.pimoroni.com
PiratePython : https://github.com/pimoroni/PiratePython

History

11 Oct 2018 - Original document
13 Oct 2018 - Added 'C:\wsl-share\buildroot\info' sub-directory
14 Oct 2018 - Added $PRODUCT and $WSLSHARE substitutions
14 Oct 2018 - Added working ./gpioexpand/board/overlay/etc/init.d/S99gpioext
Last edited by hippy on Sun Oct 14, 2018 1:23 pm, edited 8 times in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:41 pm

PHASE THREE - ADDING LUA AND MICROPYTHON

We are now going to add Lua and MicroPython to our build so those can be used on our disklessly booted Pi.

Adding MicroPython is an easier and quicker process than installing a full Python which we can do later.

Update the Buildroot configuration

Code: Select all

cd ./buildroot-2017.02
make menuconfig
There will be a short delay while things are set-up. But this will eventually bring up a text menu which allows us to select the build root options.

Use up arrow and down arrow keys to choose a particular option and press space or return to set or clear that option or configure a variety of things for that option.

Use the left arrow and right arrow keys to switch between the '<select>' and '<exit>' modes at the bottom of the screen. Once a configuration option has been set choose '<exit>' and press space or return. This will return you to the earlier menu.

Keep selecting '<exit>' and pressing space or return to exit the configuration process.

Select '<yes>' to have your changes saved or '<no>' if you have messed something up.

Enabling Lua and MicroPython

1) Go down to "Target packages -->" and press return

2) Go down to "Interpreter languages and scripting -->" and press return

3) Go down to "lua" and press space. An asterisk (*) should now appear next to that.

4) Go down to "micropython" and press space. An asterisk (*) should now appear next to that and a new "micropython-lib (NEW)" option appear below that.

5) Go down to "micropython-lib (NEW)" and press space. An asterisk should also now appear next to that

6) Press right arrow to select '<exit>'. Press return.

7) Keep using right arrow to select '<exit>' and pressing return until you reach the "Do you want to save your new configuration?" option.

8) Ensure '<yes>' is selected then press return to save the new configuration.

Effecting the change

Code: Select all

make
After a few minutes ( about 20 minutes for me ) that will complete.

Code: Select all

cd ..
./build.sh
Definitely don't forget this step after you have changed configurations or those changes won't appear on your booted Pi.

Than back to Windows and upload the new build to the Pi.

Uploading the new build

Code: Select all

rpiboot -d C:\wsl-share\buildroot
Checking Lua is now present

Use your terminal emulator to connect to the Pi. Login as "root" and issue the "lua" command.

Code: Select all

Welcome to Buildroot
diskless login: root
# lua
Now you should see something like -

Code: Select all

Lua 5.3.4  Copyright (C) 1994-2017 Lua.org , PUC-Rio
>
Press Ctr-C to get back to the command prompt, and -

Code: Select all

echo 'print "Hello from Lua"' > helloworld.lua
lua helloworld.lua
Checking MicroPython is now present

Code: Select all

# micropython
Now you should see something like -

Code: Select all

MicroPython v1.8.7 on 2018-10-11; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>>
Press Ctrl-D to exit, or have a play around with MicroPython while you are there

Perhaps undertake a quick test to see that libraries have been installed -

Code: Select all

import uos
dir(uos)
And back at the Pi's command line -

Code: Select all

echo "print('Hello from MicroPython')" > helloworld.py
micropython helloworld.py
Notes

If Ctrl-D terminates your terminal emulator session with the Pi, takes you back to the 'login' prompt when you next type something, then MicroPython can be exited with -

Code: Select all

import sys
sys.exit()
Most times we probably won't be using MicroPython interactively so this should not be a major problem if it occurs.

Also note that any files ( such as 'helloworld.py' above ) are lost when the Pi is unplugged and re-booted.

How to have non-volatile or persitent storage is something which needs to be investigated further.

Links - Buildroot

Buildroot manual : https://buildroot.org/downloads/manual/manual.html

Links - Lua

Home Page : https://www.lua.org
Documentation : https://www.lua.org/docs.html
Community : https://www.lua.org/community.html

Links - MicroPython

Home Page : https://micropython.org
Documentation : http://docs.micropython.org
Community Forum : https://forum.micropython.org

History

11 Oct 2018 - Original document
12 Oct 2018 - Added Lua
Last edited by hippy on Fri Oct 12, 2018 8:12 pm, edited 6 times in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:42 pm

PHASE FOUR - ADDING FULL PYTHON

This is more involved than adding MicroPython because it requires the Buildroot toolchain to be reconfigured and a clean build undertaken. That can take quite some time.

You have a choice of Python 2.7 or Python 3. You can have one or the other but not both.

I am going to install Python 2.7 because that is what most of my Python code is written for but Python 3 is pretty much the same as below.

Update the buildroot configuration

Code: Select all

cd ./buildroot-2017.02
make menuconfig
In "Toolchain -->" enable WCHAR support -

Code: Select all

[*] Enable WCHAR support
Then '<exit>' and under "Target packages -->", "Interpreter languages and scripting -->", select the Python or Python 3 option -

Code: Select all

[*] Python
[ ] Python 3
A couple of new options will then appear beneath that.

Select "Python module format to install" and change to ".py sources and .pyc compiled"

Then in "External Python modules -->" select whichever Python modules you are likely to use, for example, to give an idea of what's available -

Code: Select all

[*] python-bottle
[*] python-flask
[*] python-numpy
[*] python-paho-mqtt
[*] python-pygame
[*] python-pymysql
[*] python-rpi-gpio
[*] python-serial
[*] python-smbus-cffi
[*] python-spidev
[*] python-tornado
[*] python-twisted
[*] python-urllib3
As it's most likely a diskless Pi will be doing 'network things', accessed and retrieving data over the network, probably with some sort of Web Browser interface, it makes sense to include various Web frameworks like bottle, flask, tornado and twisted, as well as support for Mosquitto (MQTT). PyGame gives access to frame buffers, rpi-gpio, serial, smbus-cffi and spidev will be useful for interfacing to Pi hardware.

After the options you want have been selected, exit, save the configuration.

Effecting the change

Code: Select all

make clean
Which should only take a few minutes, then -

Code: Select all

make
Which takes a lot longer, as long as the original ./build.sh did, a good few hours.

When that eventually completes -

Code: Select all

cd ..
./build.sh
Than back to Windows and upload the new build to the Pi.

Code: Select all

rpiboot -d C:\wsl-share\buildroot
Checking full Python is now present

Use your terminal emulator to connect to the Pi. Login as "root" and issue the "python" command.

Code: Select all

Welcome to Buildroot
diskless login: root
# python
Now you should see something like -

Code: Select all

Python 2.7.13 (default, Oct 13 2018, 16:25:12)
[GCC 2.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
Type quit() then return or press Ctr-D to get back to the command prompt. Note that's Ctr-D not Ctr-C.

You can now run full Python apps on your Pi assuming the libraries they require were installed.

Notes

If you add additional scripting languages or Python packages later, or deselect any previously selected, you only need to run 'make' rather than a 'make clean' which is a lot quicker. The 'make clean' is mostly needed if the Toolchain or something core to Buildroot is reconfigured. Don't forget the './build.sh'.

History

11 Oct 2018 - Original empty document template
14 Oct 2018 - First proper document
Last edited by hippy on Mon Oct 15, 2018 1:18 am, edited 5 times in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:42 pm

PHASE FIVE - ADDING AN MSD DEVICE

More to appear here later

History

11 Oct 2018 - Original document ( for adding networking )
14 Oct 2018 - Reworked sections
Last edited by hippy on Sun Oct 14, 2018 1:18 pm, edited 3 times in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:42 pm

PHASE SIX - ENABLING WIFI

More to appear here later

History

11 Oct 2018 - Original empty document template
Last edited by hippy on Sun Oct 14, 2018 1:19 pm, edited 1 time in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:43 pm

PHASE SEVEN - ENABLING BLUETOOTH

More to appear here later

History

11 Oct 2018 - Original empty document template
Last edited by hippy on Sun Oct 14, 2018 1:19 pm, edited 1 time in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:43 pm

PHASE EIGHT - ADDING OUR OWN APPLICATIONS

Creating the apps

I am going to assume development of program code is going to be done on windows so we will create an 'apps' staging directory under our 'C:\wsl-share' directory for holding those apps, and subdirectories for the various types of app we support so far -

Code: Select all

C:
MKDIR \wsl-share\apps
MKDIR \wsl-share\apps\lua
MKDIR \wsl-share\apps\micropython
MKDIR \wsl-share\apps\python
And we'll use NotePad or WordPad to create a 'helloworld.lua' Lua script in that 'C:\wsl-share\apps\lua' directory -

Code: Select all

print "Hello from Lua running /apps/lua/helloworld.lua"
And also a 'helloworld.py' MicroPython script in the 'C:\wsl-share\apps\micropython' directory -

Code: Select all

print("Hello from MicroPython running /apps/micropython/helloworld.py")
And finally a 'helloworld.py' Python script in the 'C:\wsl-share\apps\python' directory -

Code: Select all

print("Hello from Python running /apps/python/helloworld.py")
Adding apps to the build

Back on WSL we will edit the './build.sh' file and add near the top -

Code: Select all

mkdir -p ./gpioexpand/board/overlays/apps
rm -r ./gpioexpand/board/overlays/apps/*
cp -r $WSLSHARE/apps/* ./gpioexpand/board/overlays/apps/
cp -r $WSLSHARE/$PRODUCT/apps/* ./gpioexpand/board/overlays/apps/
That will copy the apps from our 'C:\wsl-share\app' staging directories into our build.

Building the apps

Now, when we run the build, the files will be copied from our Windows staging directory, into the build, and once built will be placed in the '/apps' directory of the Pi.

Using WSL -

Code: Select all

./build.sh
Back at Windows -

Code: Select all

rpiboot -d c:\wsl-share\buildroot
Testing the apps

Using the terminal emulator to access the Pi -

Code: Select all

lua /apps/lua/helloworld.lua

Code: Select all

micropython /apps/micropython/helloworld.py

Code: Select all

python /apps/python/helloworld.py
Running apps when the Pi boots

Edit the configuration script -

Code: Select all

nano ./gpioexpand/board/overlay/etc/init.d/S99gpioext
And immediately after the 'ifconfig -a' line which is near the end of the file add -

Code: Select all

for FILENAME in /apps/lua/*; do
  lua $FILENAME &
done

Code: Select all

for FILENAME in /apps/micropython/*; do
  micropython $FILENAME &
done

Code: Select all

for FILENAME in /apps/python*; do
  python $FILENAME &
done
Then './build.sh' and 'rpiboot -d C:\wsl-share\buildroot' again, and when the Pi boots, after the network configuration listing on your Pi monitor you should see three welcome messages. These may be interspersed with other boot messages but they should be there.

And that's it; we have our own scripts running on the Pi. It's up to you to create ones which do what you want.

A simple web server

Here's a simple web server which can be dropped into 'C:\wsl-shrea\apps\python' as 'httpd.py' -

Code: Select all

import BaseHTTPServer
import urllib

class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_GET(self):
    with open(urllib.unquote(self.path), "rb") as f:
      self.send_response( 200 )
      self.send_header("Content-type", "text/html")
      self.end_headers()
      self.wfile.write(f.read())

BaseHTTPServer.HTTPServer(("", 8082), HttpHandler).serve_forever()
Once the Pi is running you can point a browser at that Pi and access any file on the Pi, for example, with above on port 8082 -

Code: Select all

http://172.16.0.99:8082/apps/lua/helloworld.lua
Notes

You will either have to develop your apps in the 'C:\wsl-share\app' sub-directories or figure out a way to get them there before running './build.sh'.

As configured here; the directory structure of "C:\wsl-share\apps' will be completely replicated to './gpioexpand/board/overlay/apps' on WSL and finally to '/apps' on the Pi once booted.

Note that any additional apps added to the 'C:\wsl-share\apps' tree are automatically copied and the automatically run when the program starts.

And we added an ampersand (&) to the end of the commands which run app scripts so when we start them when the Pi booted, if they are server apps, they will continue to run in the background and allow the rest of the boot process to continue.

You can create any directory structure you wish to use. You can adjust the './build.sh' script to only include the parts of the tree you want.

History

11 Oct 2018 - Original empty document template
13 Oct 2018 - First draft
13 Oct 2018 - App sub-directories and auto-running
13 Oct 2018 - Added web server example
14 Oct 2018 - Added $PRODUCT and $WSLSHARE substitutions
Last edited by hippy on Sun Oct 14, 2018 3:14 pm, edited 8 times in total.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:43 pm

PHASE NINE - BOOTING FROM SD CARD

Though we build everything for diskless booting there is no reason we should not boot what we have built from SD Card.

To do that, simply drag all the files and sub-directories which are in 'C:\wsl-share\buildroot' and drop them into the root directory of an empty FAT32 formatted SD Card.

If you want to be fancy, want to avoid removing the SD Card from your Pi, or having to find an SD Card writer, you can 'rpiboot -d .\msd' then drag all the files and sub-directories which are in 'C:\wsl-share\buildroot' to the root directory of the removable drive that creates.

Next time the Pi is powered-up it will boot from those. You can now run your uploaded application by plugging the Pi into the PC, or disconnecting it from the PC and using a separate own power supply.

Notes

Never connect your Pi to your PC with a standard USB cable when it is being powered by a power supply. The PC and the power supply will battle with each other which may lead to damage to the PC, the Pi or its power supply.

Once you are booting from an SD Card you will need to reformat that card, or at least delete or rename bootcode.bin, in order to have rpiboot recognise it as a Pi which can be uploaded to.

History

11 Oct 2018 - Original empty document template

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:44 pm

PHASE TEN - OTHER THINGS TO DO

More to appear here later

History

11 Oct 2018 - Original empty document template

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:44 pm

Reserved. Just in case it's needed.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:44 pm

PHASE ELEVEN - THE WINDOWS SIDE OF THINGS

More to appear here later

History

11 Oct 2018 - Original empty document template

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:44 pm

Reserved. Just in case it's needed.

hippy
Posts: 3913
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: How To: Building and booting apps from Windows for diskless Pi's

Thu Oct 11, 2018 9:45 pm

TIPS AND TRICKS

Build files

The four files you will be editing for the build, assuming you are in the ~/gpioexpander' directory, are -

Code: Select all

nano ./build.sh
nano ./gpioexpand/configs/gpioexpand_defconfig
nano ./gpioexpand/board/kernelconfig-gpioexpand.fragment
nano ./gpioexpand/board/overlay/etc/init.d/S99gpioext
History

11 Oct 2018 - Original empty document template
13 Oct 2018 - Added 'build files' list

Return to “Other projects”