[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.
User avatar
pythoncoder
Posts: 4147
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by pythoncoder » Wed May 06, 2020 4:31 am

The beauty of open source is that you can answer these questions by studying the source ;)

If you look at the code in flashbdev.py I think you'll find the answer. The chip is reporting a flash size too small to support a filesystem so, instead of creating a filesystem it sets bdev to None. This causes _boot.py to skip mounting the nonexistent filesystem and to skip initialising it.

The question is what does esp.flash_size() return on the ESP8255? There may be a bug here, and if so, it needs to be reported.
Peter Hinch

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 10:36 am

Code: Select all

import uos
from flashbdev import bdev
print(esp.flash_size())
returns 1048576 on this board

So it seems like flashbdev.py is ok.

This only works if I also first do:

Code: Select all

import esp
Otherwise I get this:

Code: Select all

NameError: name 'esp' isn't defined

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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by pythoncoder » Thu May 07, 2020 5:06 am

I'd expect you to have to import esp, and flashbdev.py does this.

I can't explain why bdev is being set to None. Very odd.
Peter Hinch

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 » Fri May 08, 2020 1:30 am

I found another clue that may help.

Using my build from the latest repo (unmodified - the one that does not work) I see the following message in the serial terminal:

Code: Select all

Traceback (most recent call last):
  File "_boot.py", line 13, in <module>
  File "inisetup.py", line 45, in setup
  File "inisetup.py", line 16, in check_bootsec
  File "flashbdev.py", line 13, in readblocks
OSError: [Errno 5] EIO
I think I didn't see this initiallly because I was interacting with the board through a Jupyter Notebook.

So maybe the inisetup routine _is_ getting called after all?

The offending line in flashbdev.py is this:

Code: Select all

esp.flash_read((n + self.start_sec) * self.SEC_SIZE + off, buf)
So I executed this from my terminal:

Code: Select all

from flashbdev import bdev
buff=bytearray(bdev.SEC_SIZE)
esp.flash_read(n,buff)
And did not get any errors for values of n < 1044480 but do get the EIO error for larger values

I am not sure what start_sec gets initialized to with FlashBdev but could this be related to the problem? I am also not sure if this is consistent with the behavior of the v1.12 _boot.py working while the latest _boot.py does not.

In a web search I found some indications that EIO errors could be related to timing which I am guessing could explain why it works on the Wemos on not on the Sonoff.

Thanks again for the help with this.

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 » Fri May 08, 2020 11:53 pm

The root cause of this problem was with the way I was building the firmware - not in the firmware itself.

When I built the firmware I used

make board=GENERIC_1M

rather than

make BOARD=GENERIC_1M :oops:

Unfortunately this defaults to building the GENERIC firmware rather than the GENERIC_1M firmware and does not throw an error. This is why the firmware worked on the Wemos and not on the Sonoff. I compounded the problem by copying the wrong binary file when moving it between machines which led me down a wrong path.

Embarrassing but ultimately solved.

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

Re: Problem running latest GENERIC_1M firmware on Sonoff

Post by kevinkk525 » Sat May 09, 2020 6:53 am

Good to know! Thanks for the feedback. Glad it works now.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply