esp8266: Support up to 16 MB of flash
The ESP8266 supports up to 16 megabytes of SPI flash (source, page 12). NodeMCU has supported this much flash for about two months now, and I notice that MicroPython does not. I don't know all the nuances of the ESP8266, but from what I understand there are three things that should all encode the same size: the flash chip's ID, the SpiFlashChip structure from the SDK, and the bootloader size ID. They might not all agree about the flash chip's size, so we try to make them all agree in flashbdev.py. It looks like in the similar routine from NodeMCU, they use size IDs 8 and 9 for 8 MB and 16 MB, respectively. Setting these IDs in MicroPython seems to make mpy think that it has only 512 kB of flash, and I'm not sure why. Ignoring the bootloader size ID and only calculating flash size from the flash chip's ID seems to work, but somehow that seems like the wrong thing to do.
Long story short, I want to add support for 8 and 16 MB of flash to MicroPython, but I don't know what the right way to do it is. Any advice would be greatly appreciated.
esp8266: SPI flash access functions and user mounting.
Combined all the effort from previous discussions: #1483, #1507.
- FatFS and SPI flash driver now only consist of 3 files with #1597 in place. Simplified read/write functions.
- Byte-by-byte writing for user space as well as 512 byte sector writes used by fatfs.
- All flash access functions are added to the esp module, prefixed with flash_*, all tested.
- Added user mounting via pyb.mount.
Needs further work:
- All read/writes have a fixed start/end offset address defined in flash.h#41 in ESP sectors. Previously discussed, it is possible to have an automatic offset decided by the linker. In the meantime I can keep or remove the existing #define.
- I haven't actually tested the pyb.mount yet, but shouldn't be too hard.
- Byte-by-byte access can be optimised by detecting if the requested size can fit in the buffer straight away and use memcpy. flash.c#L111