Is it possible to make pybflash disk readonly?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Is it possible to make pybflash disk readonly?

Post by shaoziyang » Sun Nov 15, 2020 8:51 am

I want make pybflash disk to readonly mode, what command can be used to implement this function?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is it possible to make pybflash disk readonly?

Post by jimmo » Sun Nov 15, 2020 11:11 am

shaoziyang wrote:
Sun Nov 15, 2020 8:51 am
I want make pybflash disk to readonly mode, what command can be used to implement this function?
os.mount() takes a `readonly` kwarg.

In boot.py you can unmount /flash and then re-mount it readonly.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: Is it possible to make pybflash disk readonly?

Post by shaoziyang » Mon Nov 16, 2020 2:25 am

jimmo wrote:
Sun Nov 15, 2020 11:11 am
shaoziyang wrote:
Sun Nov 15, 2020 8:51 am
I want make pybflash disk to readonly mode, what command can be used to implement this function?
os.mount() takes a `readonly` kwarg.

In boot.py you can unmount /flash and then re-mount it readonly.
I tried it the way you did, it does change to read-only mode in micropython, but it's still writable in windows.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is it possible to make pybflash disk readonly?

Post by jimmo » Mon Nov 16, 2020 10:14 am

shaoziyang wrote:
Mon Nov 16, 2020 2:25 am
I tried it the way you did, it does change to read-only mode in micropython, but it's still writable in windows.
I don't know much about Windows, but here are some pointers that might help:

The pyboard makes a virtual USB device by emulating a partition table in the first block. See storage_read_block() in ports/stm32/storage.c which intercepts the read for block zero. Then the real internal flash is returned to the USB interface, offset by FLASH_PART1_START_BLOCK. The actual flash on the Pyboard contains a real FAT formatted filesystem.

I understand that Windows supports the concept of a readonly volume. I don't know if this is stored in the partition table or in the filesystem metadata (and is perhaps GPT or NTFS only?). See https://docs.microsoft.com/en-us/window ... formationw

So perhaps you could try setting the readonly flag (from diskpart.exe) and see what it tries to write to the device.

Post Reply