Boot from /flash and mount /sd

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
LRonHorse
Posts: 9
Joined: Thu Aug 13, 2015 10:20 am
Location: St Ives Cambridgeshire
Contact:

Boot from /flash and mount /sd

Post by LRonHorse » Wed Aug 19, 2015 5:49 pm

Hi
Does anyone know how to boot from flash but still have the sd mounted and accessible - or is possible?
I've just gotten started with the pyboard and getting to grips with it (albeit slowly) but can't find a way of doing this.
I'd like to run code from flash but use sd for writing data to.

Cheers

LRon

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Boot from /flash and mount /sd

Post by dhylands » Wed Aug 19, 2015 7:49 pm

When an sd card is inserted, it will only run /sd/boot.py and it will ignore /flash/boot.py

If you make the sdcard contain something like the following:

Code: Select all

execfile('/flash/boot.py')
then you can get the /flash/boot.py executed.

Otherwise, you'd need to comment out the f_chdrive("/sd"); line:
https://github.com/micropython/micropyt ... ain.c#L506
and then it should always run /flash/boot.py

User avatar
LRonHorse
Posts: 9
Joined: Thu Aug 13, 2015 10:20 am
Location: St Ives Cambridgeshire
Contact:

Re: Boot from /flash and mount /sd

Post by LRonHorse » Thu Aug 20, 2015 12:45 pm

Thanks Dave I shall give that a try today and see where it gets me :)

User avatar
LRonHorse
Posts: 9
Joined: Thu Aug 13, 2015 10:20 am
Location: St Ives Cambridgeshire
Contact:

Re: Boot from /flash and mount /sd

Post by LRonHorse » Fri Aug 21, 2015 2:19 pm

Hi Dave
I tried the execfile('/flash/boot.py') approach from the sd card and it didn't work for me.
However, I did try the following:
import pyb
pyb.main(('/flash/main.py')
which did work - dunno why I didn't try that first!!
It do a couple of odd things though, such as overwriting the boot.py file on the flash fs. No idea why so it could be something stupid I managed to do.
Writing to /sd also seemed to work quite happily from /flash although again with a couple of odd occurrences.
Do you, or anyone else on the forum, know if there is a way to immediately update a file write as, after the initial write I seem to have to power down the board before it'll write - and even then it's not overly reliable.
I've tried calling os.sync() but this fails also.
Anyway, thanks for the info - much appreciated :)

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Boot from /flash and mount /sd

Post by dhylands » Fri Aug 21, 2015 4:32 pm

I've found that using the USB Mass Storage to be unreliable at best. The underlying protocols were designed with exclusive access in mind. Unfortunately, the way the pyboard uses it it is very easy for the host to totally overwrite any changes made by the pyboard.

So I wound up writing a program called rshell https://github.com/dhylands/upy-shell/t ... ter/rshell which allows you to copy files into and out of the pyboard using only usb-serial. Then you can disable USB Mass storage and all accesses to the file system will come from the pyboard and you don't get files mysteriously altered by the host (because it thought it had exclusive access).

User avatar
LRonHorse
Posts: 9
Joined: Thu Aug 13, 2015 10:20 am
Location: St Ives Cambridgeshire
Contact:

Re: Boot from /flash and mount /sd

Post by LRonHorse » Fri Aug 21, 2015 5:08 pm

Thanks for that - I shall checkout RShell and see what transpires

Many thanks

LRon

Post Reply