Skip to content

esp32: make use of wear levelling from IDF #4999

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

Conversation

c0d3z3r0
Copy link

@c0d3z3r0 c0d3z3r0 commented Aug 11, 2019

This is a rework of loboris' wear leveling patch
micropython/micropython-esp32#126

Signed-off-by: Michael Niewöhner foss@mniewoehner.de

Tested and running productive on my device

This is a rework of loboris' wear leveling patch
micropython/micropython-esp32#126

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
@nevercast
Copy link
Contributor

May conflict with #4987
Should be checked.

@@ -26,9 +27,8 @@ def ioctl(self, op, arg):
return self.SEC_SIZE

size = esp.flash_size()
if size < 1024*1024:
if size < 512*1024:
Copy link
Contributor

@nevercast nevercast Aug 16, 2019

Choose a reason for hiding this comment

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

Are you including the wear level size here? I'm not sure I see that.
#3576 (comment)
https://www.esp32.com/viewtopic.php?t=1897

Copy link
Author

Choose a reason for hiding this comment

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

uhm... not really sure... but I guess this should be the minimum partition size, so this should be 528k... have to check this again, to be really sure

@c0d3z3r0
Copy link
Author

c0d3z3r0 commented Aug 20, 2019

May conflict with #4987
Should be checked.

Yup and with #5027, #4854 and #3576 so we should wait for them; then we can simply drop the flashbdev patch from this PR

@dpgeorge
Copy link
Member

Thanks for the contribution.

But I guess this will no longer work if #5027 is merged. Because that patch removes calls to the esp.flash_read etc functions and instead uses a Partition object.

Do you know how to make wear levelling work with the IDF partition interface?

@nevercast
Copy link
Contributor

I see that wl_mount takes an esp_partition_t*

@nevercast
Copy link
Contributor

nevercast commented Aug 21, 2019

Actually, looking at the high level API, https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/wear-levelling.html#high-level-api-reference, it seems this is very much supported. Should be able to implement wear levelling as a Partition object that uses the high level API provided here as a middleware.

Edit:

WL doesn't explicitly mention anything about Flash Encryption. Its my assumption that it would be handled transparently if the partition table for a fatfs partition was tagged with encrypted. This would need to be verified.

Last thought:
I think I'm of the opinion that the vfs partitions, via the Partition class, should default to wear-levelling. I'm not sure I see a need otherwise; unless it breaks being able to read and write the fat partition via esptool / creating a fat image on the PC and pushing it to an ESP32.

It would be my preference that wear levelling just works and just happens whenever a read/write partition is mounted.

@c0d3z3r0
Copy link
Author

c0d3z3r0 commented Aug 21, 2019

I see that wl_mount takes an esp_partition_t*

Yes, a partition must be "mounted as wearlevel partition".

Actually, looking at the high level API, https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/wear-levelling.html#high-level-api-reference, it seems this is very much supported. Should be able to implement wear levelling as a Partition object that uses the high level API provided here as a middleware.

The problem here is that we DO NOT use the highlevel API / espressif's vfs but instead build on our own fatfs and vfs implementation. This means no, we can not use that. The partitions must be mounted explicitely through the mid level API (wl*). @dpgeorge's code uses esp_partition_write which relies on spi_flash_write which does not do wear levelling natively.

Edit:

WL doesn't explicitly mention anything about Flash Encryption. Its my assumption that it would be handled transparently if the partition table for a fatfs partition was tagged with encrypted. This would need to be verified.

Wear levelling is completely transparent, as is encryption. You can mount an unencrypted or an encrypted partition as wearlevelling partition:

spi flash <- partition (encrypted or unencrypted) <- wear levelling <- <mapped blocks / partition> <- filesystem

Last thought:
I think I'm of the opinion that the vfs partitions, via the Partition class, should default to wear-levelling. I'm not sure I see a need otherwise;

unless it breaks being able to read and write the fat partition via esptool / creating a fat image on the PC and pushing it to an ESP32.

This is NOT possible with wear levelling currently as esptool writes directly to flash. You must create a wear levelling partition image and flash that. There's a tool for this: https://github.com/TobleMiner/mk_esp32fat

It would be my preference that wear levelling just works and just happens whenever a read/write partition is mounted.

The right way would be dropping our own vfs and fatfs and instead build on espressif's vfs and fatfs which both natively support encryption and wear levelling. This would even make it possible to easily use spiffs or anything else that is getting added to esp-idf in later versions.

@nevercast
Copy link
Contributor

Thanks for taking the time to write up the detailed reply, clears a lot of thoughts. 👍

@dpgeorge
Copy link
Member

#5027 (use of Partition class as the FS block device) was merged in 31de447, so this PR would need to be reworked against that.

The right way would be dropping our own vfs and fatfs and instead build on espressif's vfs and fatfs which both natively support encryption and wear levelling. This would even make it possible to easily use spiffs or anything else that is getting added to esp-idf in later versions.

I understand the sentiments here, but the idea is that MicroPython is consistent across many different ports/boards/architectures/SoCs/MCUs/etc and so in that light it's important to use the MicroPython-supplied VFS (eg then you can mount custom filesystems the same way on all ports).

Well, it may be possible to merge both worlds by using the VfsPosix class to interface to the ESP-IDF filesystem. Feel free to look into that if you like. Otherwise I'd suggest to find a way to make the Partition class use wear leveling.

@c0d3z3r0 c0d3z3r0 closed this Apr 5, 2020
@c0d3z3r0 c0d3z3r0 deleted the for-upstream/esp32_wear_levelling branch April 5, 2020 22:07
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Jul 15, 2021
ESP32S2: Fix PWM timer leak and variable frequency conflicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants