Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore EEPROM address to prior released location #6537

Merged
merged 3 commits into from
Sep 20, 2019

Conversation

earlephilhower
Copy link
Collaborator

When the FS_END was adjusted to end on a full block (i.e. rounded down)
to avoid filesystem issues, but _FS_end was changed. The EEPROM library
used _FS_end to implicitly calculate the start of the EEPROM data, so
this means after the _FS_end fix, EEPROM data written with prior
releases would "disappear."

Avoid the issue by explicitly calculating the EEPROM start location in
the linker, using the same formula as prior release.

Fixes #6531

When the FS_END was adjusted to end on a full block (i.e. rounded down)
to avoid filesystem issues, but _FS_end was changed.  The EEPROM library
used _FS_end to implicitly calculate the start of the EEPROM data, so
this means after the _FS_end fix, EEPROM data written with prior
releases would "disappear."

Avoid the issue by explicitly calculating the EEPROM start location in
the linker, using the same formula as prior release.

Fixes esp8266#6531
@earlephilhower earlephilhower added this to the 2.6.0 milestone Sep 19, 2019
@mcspr
Copy link
Collaborator

mcspr commented Sep 19, 2019

Hey
If adding another symbol is a way to go, perhaps we can also add _EEPROM_end?

Back in april when #5989 was proposed, I also patched to my home-brew ld script generator for ESPurna with the same fs_end calculation, but have not noticed any EEPROM issues because my 4m1m script reserved 16K for EEPROM (for wear-leveling writes) 🤷‍♂

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No difference with 2.5.2, using
for i in eagle.flash.*; do echo $i; git diff 2.5.2 $i | egrep -ie 'eprom|^-.*_end'; done

@earlephilhower
Copy link
Collaborator Author

@mcspr there's no real clean way to get what you're trying to do. The way EEPROM works is to erase and write starting from the EEPROM beginning, and it erases/rewrites the sector on each commit, so there is no way to do wear leveling, w/o going to a new EEPROM setup (which wouldn't be compat with existing setups, sadly) that iterated over a set of sectors...

@mcspr
Copy link
Collaborator

mcspr commented Sep 20, 2019

True, but that is exactly what is happening for that specific firmware because of the small shim library working on top of the eeprom logic - https://github.com/xoseperez/eeprom_rotate - where it calculates free space between sdk-reserved space and fs_end and then uses a different sector for each write.

Given that right now there is also interest to create bootloader config sector (#6538), maybe there needs to be a consistent approach to add sort-of partitions

@earlephilhower
Copy link
Collaborator Author

Partitions are part of the 3.0.0 stuff (one of the reasons for the move to esptool), and on the ESP32 are defined by Espressif. I'm not following their 8266 SDK RTOS 3.0, but that's better left for another issue.

I can add an _EEPROM_end, sure, but for compatibility it can only ever be _EEPROM_end = _EEPROM_start + 4096, so for now I'm not seeing the utility. It would also need some minor rework to the lib itself, because the lib now assume a 1-sector erase/write.

For now I'd like to have this just be a bugfix ASAP for 2.6. We can work out the best way of getting your setup working in another issue (or track in @davisonja 's PR) or new PR since EEPROM wear leveling is a breaking change...

@earlephilhower earlephilhower merged commit 69f3e81 into esp8266:master Sep 20, 2019
@earlephilhower earlephilhower deleted the eeprom branch September 20, 2019 15:24
@mcspr
Copy link
Collaborator

mcspr commented Sep 20, 2019

Btw, EEPROM at runtime specifically I think it does not even need to know where fs is and could just count -20KB (-5 sectors) from the ESP::getFlashChipSize()?

There is no specific problem with the PR, only that without -DNO_GLOBAL_EEPROM my builds would fail with undefined reference err because I need to keep custom .ld script up-to-date. But fix is pretty easy, just adding new symbol or INCLUDE the up-steam .ld script somewhere in the custom one. Perhaps I am also overthinking it and should use a different approach altogether instead of moving fs_end address down (as the only reason of that is to simplify sector calculations by using last one as a base point and counting down by a specified index)

It was not meant to derail the discussion by mentioning Rotate library, but I have not thought about adding it here before. I could try to update the existing class to optionally support it, hopefully without breaking too much.

@earlephilhower
Copy link
Collaborator Author

Great. Maybe it would make sense to put your suggestion in an issue and we can mark it for 3.0 consideration. That way we won't forget!

@d-a-v
Copy link
Collaborator

d-a-v commented Sep 20, 2019

This rotate library was proposed here as a PR and instead moved to an arduino library #4493
doc (should be moved to the 'Other libraries' paragraph below?)
https://github.com/jwrw/ESP_EEPROM

@mcspr
Copy link
Collaborator

mcspr commented Sep 20, 2019

One quirk is that both want extern _SPIFFS_end, which is replaced with _FS_end.
xoseperez/eeprom_rotate#6 had mentioned this some time ago, but I forgot about it...
I hot-fixed it via the .ld scripts too, but maybe there should be PROVIDE ( _SPIFFS_... = _FS_... ) for each one in the local.eagle.app.v6.common.ld to avoid breaking such libs?

@davisonja
Copy link

davisonja commented Sep 20, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EEPROM location was changed
4 participants