Bug in "_boot.py" and enhance inisetup.py ?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
jedie
Posts: 245
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Bug in "_boot.py" and enhance inisetup.py ?

Post by jedie » Thu Jan 09, 2020 3:42 pm

Think i found a bug in "_boot.py" for ESP8266 and created my first pull request to micropython with a bugfix: https://github.com/micropython/micropython/pull/5509

The current _boot.py does this:

Code: Select all

...
import uos
from flashbdev import bdev

try:
    if bdev:
        uos.mount(bdev, '/')
except OSError:
    import inisetup
    inisetup.setup()
...
If the flash is not formatted, i get this error:

Code: Select all

  File "_boot.py", line 8, in <module>
AttributeError: 'FlashBdev' object has no attribute 'mount'
So i change OSError to AttributeError and move the "if bdev:", too.


But a question: In my project i also change the inisetup.py to this:

Code: Select all

...
import esp
import flashbdev
import uos

FS_FAT = 'FAT'
FS_LITTLEFS = 'LittleFS'


def detect_filesystem():
    buf = bytearray(16)
    flashbdev.bdev.readblocks(0, buf)
    if buf[3:8] == b'MSDOS':
        return FS_FAT
    elif buf[8:16] == b'littlefs':
        return FS_LITTLEFS
    return 'unknown'


def setup():
    print("Performing initial setup")

    filesystem = detect_filesystem()
    print('Detected filesystem: %r' % filesystem)
    if filesystem != FS_LITTLEFS:
        print('Erase flash start sector 0x%x' % flashbdev.bdev.START_SEC)
        esp.flash_erase(flashbdev.bdev.START_SEC)

        print('convert to littlefs2')
        uos.VfsLfs2.mkfs(flashbdev.bdev)

    print('mount filesystem')
    uos.mount(flashbdev.bdev, '/')

    with open("boot.py", "w") as f:
        f.write("""\
...
Think the current check here: https://github.com/micropython/micropyt ... nisetup.py is a little bit "strange", isn't it?

Do any of you think I could submit this as a pull request, too?
Maybe a cleaned/tunes variant of this.

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

Re: Bug in "_boot.py" and enhance inisetup.py ?

Post by pythoncoder » Thu Jan 09, 2020 6:36 pm

The current default filesystem for ESP8266 is FAT: this is by design. If you want to implement littlefs you do have to make some changes.
Peter Hinch

Post Reply