file corrupted and reset firmware no works

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

file corrupted and reset firmware no works

Post by IHOXOHI » Mon Oct 19, 2020 8:40 am

Hi,

I have a file corrupted on the flash memory of my pyb-d SF6...
I can't delete it. I can't change permisssions on this file (from a rshell root session too)...
When I try to reset the firmware, there isn't error during the reset, but finally the corrupted file is still there, not any one other file on flash memory and I can't create or add other file...

Thanks for your help.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: file corrupted and reset firmware no works

Post by Roberthh » Mon Oct 19, 2020 12:19 pm

Try recreating the file system. That error typically happens after concurrent writes to the files, or when writing with a PC and shuuting the board off without not closing the drive. Better do not use the drive feature, or at least use it only for reading.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: file corrupted and reset firmware no works

Post by IHOXOHI » Mon Oct 19, 2020 1:36 pm

Thanks Roberthh,

Yes, exactly... It happens with a file, normaly on sd card, which save data. It could happen during a saving time... But now I have this corrupted file on my flash. It's very strange... At first it has corrupted others files on my flash. By root rshell session, it looks that I have stoped "the infection". After I have had to use a user rshell session for write something on flash memory, I success to create a new boot file like this.
In "normal" use, I can just read. I have to use rshell session for have an access to write. Now I can have an access to sd card, I don't know why because before I haven't???
Maybe the corrupted file will disappear alone?

Thanks for your support.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: file corrupted and reset firmware no works

Post by Roberthh » Mon Oct 19, 2020 2:43 pm

A corrupted file system will stay a source of surprises. Better re-format the internal file system.
Use for Lfs2
import uos
import pyb
uos.VfsLfs2.mkfs(pyb.Flash)

or for FAT:
uos.VfsFat.mkfs(pyb.Flash)

Of course that will delete all files in the file system. On Pyboard D you can also hold the user button and push reset and hold the user button, until the led turns blue , then release the user button. Then the file system will be recreated.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: file corrupted and reset firmware no works

Post by pythoncoder » Mon Oct 19, 2020 4:52 pm

The factory reset as described by Robert would be my approach. Then edit /flash/boot.py so that it has

Code: Select all

pyb.usb_mode('VCP')
removing MSC mode.

The Pyboard will no longer appear as a mass storage device but the filesystem will remain intact. This feature causes endless trouble for reasons which are well established and unavoidable: the USB standard requires mass storage devices to be dumb, and Pyboards can modify the filesystem. So it breaks.

I've answered this so many times I'll write a FAQ on my GitHub page.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

FAQ on USB filesystem corruption

Post by pythoncoder » Mon Oct 19, 2020 5:18 pm

OK, for the benefit of others offering support I suggest we point people here.
Peter Hinch
Index to my micropython libraries.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: file corrupted and reset firmware no works

Post by IHOXOHI » Tue Oct 20, 2020 3:01 pm

Thanks a lot for your help.

So, finally I will use alls pyboards in 'VCP' usb mode, now. Good to known for what. It's just an habit to take. An advise about this problem could be good in the readme of the board, because for sure, lots of people prefers to have a "direct and easy" access. Most of the time, there isn't problem for save data in "normal" mode.

Otherwise, just for clean up my file system, I tried Roberthh's command. No one works.
I have the return "TypeError: argument has wrong type" for both... Fortunatly It's a pyb-d. The "button's reset" works fine.

Thanks.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: file corrupted and reset firmware no works

Post by davef » Tue Oct 20, 2020 6:54 pm

I went to where you are pointing people and none of the links on that page work ... for me. I have followed links before, but there seems to be some "trick" I don't know.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: file corrupted and reset firmware no works

Post by Roberthh » Tue Oct 20, 2020 7:33 pm

@IHOXOHI Following the manual, it should have been.

import os, pyb
os.umount('/flash')
os.VfsFat.mkfs(pyb.Flash(start=0))
os.mount(pyb.Flash(start=0), '/flash')
os.chdir('/flash'

and accordingly for LittleFS. Link: http://docs.micropython.org/en/latest/r ... filesystem
I'm almost sure I will forget that soon.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: file corrupted and reset firmware no works

Post by IHOXOHI » Wed Oct 21, 2020 11:10 pm

Youp,

Thanks a lots for yours goods advises.
There isn't words for describe micropython discovering...

Finally I have chosen, just like the doc explain (like Roberthh say), the fat format for my boot partition and the LittleFS format for my data partition.
The result looks perfect for alls situations. I can manage easily my files and folders by a rshell session, and stay protected over corrupted files with my littlefs partition. No more software installation.
The code of my boot.py (after follow the littleFS partition's method in the doc):

Code: Select all

import pyb
import machine
import sys, os

p2 = pyb.Flash(start=256*1024)
os.mount(p2, '/data')
os.chdir('/data')

pyb.main('main.py')
sys.path[1:1] = ['/data/lib']

pyb.usb_mode('VCP')

if pyb.SDCard().present():
    os.mount(pyb.SDCard(), '/sd')
In this case, I need a sdcard for save a pdf file formated for beeing display on an epaper. This is too big for the flash memory. I can save the page's number in a file on the data partition, logically without risk of corruption. If not, I will report with pleasure.

THANKS.

Post Reply