[SOLVED] Problem running latest GENERIC_1M firmware on Sonoff

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Ev Quink
Posts: 9
Joined: Thu Apr 30, 2020 9:32 pm

[SOLVED] Problem running latest GENERIC_1M firmware on Sonoff

Post by Ev Quink » Fri May 01, 2020 12:48 am

Hello,

I have successfully built and run v1.12 firmware on both a Wemos D1 Mini and a Sonoff RF Rev2 board. When I build from the latest repo, I can successfully run it on the Wemos but not on the Sonoff.

Using the latest build on the Sonoff, everything seems fine and I am able to boot, connect through serial and establish a wifi connection but when I go to enable the webrepl I get the following:

Code: Select all

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "webrepl_setup.py", line 108, in <module>
File "webrepl_setup.py", line 75, in main
File "webrepl_setup.py", line 44, in get_daemon_status
OSError: [Errno 1] EPERM
Looking at the root directory on the Sonoff, I see that the boot.py file is missing (there are no file there) and I am not able to write files to the device. When I try to write a file I get the following:

Code: Select all

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'O' isn't defined
Any thoughts on how to troubleshoot or next steps? Thanks for any advice you can offer.

Evan
Last edited by Ev Quink on Mon May 11, 2020 2:18 pm, edited 1 time in total.

Ev Quink
Posts: 9
Joined: Thu Apr 30, 2020 9:32 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by Ev Quink » Mon May 04, 2020 8:12 pm

I am guessing that what I am seeing may be an indication that the file system did not get set up correctly.

As an experiment, I attempted to reconfigure the build to use FAT instead of LittleFS by editing the mpconfigboard.mk file. That file originally contained:

LD_FILES = boards/esp8266_1m.ld
MICROPY_PY_BTREE = 1
MICROPY_VFS_LFS2 = 1

So I changed it to this which is similar to the file in the V1.12 build:

LD_FILES = boards/esp8266_1m.ld
MICROPY_VFS_FAT = 1

But I have no idea if this is all that is required.

Unfortunately this yielded the same result - a generally functioning board but no working file system.

I am working well beyond my experience here -- learning a lot but not making much progress towards solving this problem.

Thanks again for guidance anyone can provide.

Evan

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by kevinkk525 » Mon May 04, 2020 9:15 pm

did you erase the board before flashing the firmware?
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Ev Quink
Posts: 9
Joined: Thu Apr 30, 2020 9:32 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by Ev Quink » Tue May 05, 2020 12:14 am

Thanks for the reply. Yes I did start by erasing the flash using: esptool --port COM5 erase_flash

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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by pythoncoder » Tue May 05, 2020 5:48 am

I think it's unlikely that littlefs is the problem but the quick way to prove it would be to erase flash then load V1.11 or earlier: builds which predate the use of littlefs. I found Sonoff devices to be choosy about the parameters passed to esptool but I don't recall ever having a working REPL yet no filesystem.
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by kevinkk525 » Tue May 05, 2020 7:30 am

I flashed many sonoff devices with littlefs and have no problem, so I doubt littlefs is the culprit. As Peter said it might be worth checking with an older version that the flash does indeed work.

This is the command line I used to flash the firmware: esptool.py --port /dev/ttyS3 --baud 115200 write_flash --flash_size=1MB -fm dout 0x0 /home/kevin/micropython/ports/esp8266/build-GENERIC/firmware-combined.bin

However, I did not yet try any firmwares since the new uasyncio version got merged and different board definitions for esp8266 got introduced. My last esp8266 firmware build is probably 4 month old. I have yet to update everything but was busy with esp32

I am not sure the flashing itself is a problem because I always either ended up with nothing working or everything working. But not with a working micropython firmware without a working filesystem..

But with a working repl you could format the filesystem from within micropython, maybe that helps.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by pythoncoder » Tue May 05, 2020 3:19 pm

@Ev Quink In your OP you mentioned building it yourself. Is it possible you made a mistake with the manifest files? ESP builds need to include inisetup.py and _boot.py otherwise a filesystem won't be created. If your build lacked those, yet only the D1 Mini had a pre-existing filesystem, it would explain your symptoms.
Peter Hinch
Index to my micropython libraries.

Ev Quink
Posts: 9
Joined: Thu Apr 30, 2020 9:32 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by Ev Quink » Wed May 06, 2020 1:38 am

In which file would I find the include statements for inisetup.py and _boot.py? I did two "builds" if I am using that term correctly. These steps for V1.12:

Code: Select all

wget https://micropython.org/resources/source/micropython-1.12.tar.xz
tar xf micrpython-1.12.tar.xz
cd ~/micropython-1.12
make -C mpy-cross
cd ~/micropython-1.12/ports/esp8266/
make
Similar steps for the latest but I started by cloning the master repo -- https://github.com/micropython/micropython.git

I don't really understand the structure of the manifest files (and I didn't change them before building the firmware) but I compared the manifest.py and manifest_release.py between the latest and V1.12. The manifest.py file is the same and the manifest_release.py is similar but V1.12 includes:

Code: Select all

# uasyncio
freeze('$(MPY_LIB_DIR)/uasyncio', 'uasyncio/__init__.py')
freeze('$(MPY_LIB_DIR)/uasyncio.core', 'uasyncio/core.py') 
But I don't see where inisetup.py and _boot.py are included in either version -- and V1.12 works while the build from latest does not.

I did try formatting the filesystem per @kevinkk525's suggestion using this:

Code: Select all

import os
import flashbdev
os.VfsFat.mkfs(flashbdev.bdev)
But no joy:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "flashbdev.py", line 13, in readblocks
OSError: [Errno 5] EIO
I am wondering if I should be building from the daily snapshot (https://micropython.org/resources/micro ... master.zip) rather than the master repo itself. Would this make a difference?

Thanks for your patience and help.

Evan

Ev Quink
Posts: 9
Joined: Thu Apr 30, 2020 9:32 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by Ev Quink » Wed May 06, 2020 2:26 am

Answering my own question here...

I think this line from manifest.py pulls in all the files in the modules directory:

Code: Select all

freeze("$(PORT_DIR)/modules")
I verified that my cloned master repo includes both the _boot.py and inisetup.py files so presumably they are getting pulled into the build.

So I think I am still stuck :(

Ev Quink
Posts: 9
Joined: Thu Apr 30, 2020 9:32 pm

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by Ev Quink » Wed May 06, 2020 3:02 am

Ok - I figured out how to make it work but it would be good to understand what is happening here.

In the V1.12 _boot.py we have:

Code: Select all

try:
    if bdev:
        
        uos.mount(bdev, '/')
except OSError:
    import inisetup
    inisetup.setup()
In the latest repo _boot.py has this:

Code: Select all

if bdev:
    try:
        uos.mount(bdev, "/")
    except:
        import inisetup
                    

        inisetup.setup()
I changed the _boot.py file in the latest repo to match what was in V1.12 and it solved my problem.

I can see that inisetup.setup() is getting skipped in the latest version of _boot.py but don't understand why the file was changed in the latest version nor why it would work on a Wemos and not on the Sonoff. If it matters, this version of the Sonoff board uses an esp8255.

Wow that was painful but I'm just a little smarter than I was before I started. Hopefully that will last for a little while. :D

Post Reply