Page 1 of 1

Is it possible to make pybflash disk readonly?

Posted: Sun Nov 15, 2020 8:51 am
by shaoziyang
I want make pybflash disk to readonly mode, what command can be used to implement this function?

Re: Is it possible to make pybflash disk readonly?

Posted: Sun Nov 15, 2020 11:11 am
by jimmo
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.

Re: Is it possible to make pybflash disk readonly?

Posted: Mon Nov 16, 2020 2:25 am
by shaoziyang
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.

Re: Is it possible to make pybflash disk readonly?

Posted: Mon Nov 16, 2020 10:14 am
by jimmo
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.