Page 1 of 2

[SOLVED] Problem running latest GENERIC_1M firmware on Sonoff

Posted: Fri May 01, 2020 12:48 am
by Ev Quink
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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Mon May 04, 2020 8:12 pm
by Ev Quink
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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Mon May 04, 2020 9:15 pm
by kevinkk525
did you erase the board before flashing the firmware?

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Tue May 05, 2020 12:14 am
by Ev Quink
Thanks for the reply. Yes I did start by erasing the flash using: esptool --port COM5 erase_flash

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Tue May 05, 2020 5:48 am
by pythoncoder
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.

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Tue May 05, 2020 7:30 am
by kevinkk525
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.

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Tue May 05, 2020 3:19 pm
by pythoncoder
@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.

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Wed May 06, 2020 1:38 am
by Ev Quink
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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Wed May 06, 2020 2:26 am
by Ev Quink
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 :(

Re: Problem running latest GENERIC_1M firmware on Sonoff

Posted: Wed May 06, 2020 3:02 am
by Ev Quink
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