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
Posts: 245
Joined: Fri Jan 29, 2016 12:32 pm

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

    if bdev:
        uos.mount(bdev, '/')
except OSError:
    import inisetup
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


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)

        print('convert to littlefs2')

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

    with open("boot.py", "w") as f:
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
Posts: 3936
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

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