flash alignment

Posted on
  • In the context of the esp8266 port, I'm wondering about flash read and write alignment. jswrap_flash_write documents and enforces 4-byte alignment, which is great: https://github.com/espruino/Espruino/blo­b/master/src/jswrap_flash.c#L88-L122 But jswrap_flash_read doesn't (and the comment talks about writing https://github.com/espruino/Espruino/blo­b/master/src/jswrap_flash.c#L132). Are unaligned reads necessary? (Yes, it does complicate the implementation.)

  • Oops, scratch that comment. I now see that flash is read and written one byte at a time when called from JS!? Killer...

    The reason this is an issue is that flash is memory-mapped in the esp8266 because it executes most of the code directly from flash (there's a 32KB instruction cache). When reading or writing arbitrary cache locations the SDK first has to disable the memory mapping, then perform the SPI transactions, then re-enable the mapping. So there's quite some overhead. It may or may not matter for small stuff, like a few KB, but this would most likely not be a good interface to do the firmware upgrade through.

  • Since flash is memory mapped, the reads can presumably just come right off the mapped memory, so are basically just a memcpy that doesn't have to be aligned?

    Enforcing alignment on read wouldn't be the end of the world, but I don't think it's needed?

    But yeah, write should always be aligned. I remember having to write the code to ensure it :)

  • I had to write the read-alignment code, but it's done now and works :-)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

flash alignment

Posted by Avatar for tve @tve

Actions