[Answered]: flash memory mapping to specific address space

User avatar
Posts: 1216
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Answered]: flash memory mapping to specific address space

Postby kolban » Sat Feb 24, 2018 7:04 pm

I'm looking into how to dynamically load a binary into an already running ESP32 environment. One thought I had was to compile my binary so that it "thinks" its run-time address is 0x4800 0000. I would then place this binary within flash (perhaps in a partition). I would then use memory mapping to map the instruction data on flash into the ESP32 address space starting at 0x4800 0000.

I then started studying spi_flash_mmap which I felt was heading in the right direction. However, as I read this API, I get the feeling that I can't declare where in the address space of the ESP32 the mapping should target. It seems that I am returned a pointer to where the ESP32 has decided to map my flash data to ... I am not seeing an option to declare where in the address space I want the flash data to be mapped.

Am I wrong in either (or both) of my thinking on using mmap or in my thinking of the end goal of mapping executable code into address space?
Last edited by kolban on Mon Feb 26, 2018 3:51 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Posts: 783
Joined: Sun May 08, 2016 4:11 am

Re: flash memory mapping to specific address space

Postby ESP_Angus » Mon Feb 26, 2018 12:18 am

Hi Neil,

Neil & I discussed this elsewhere, but I'll summarise the answers here:

- Yes, you can use the MMU to map flash into the instruction address space.

- No, spi_flash_mmap() doesn't let you choose the destination address in memory. It's designed for creating dynamic mappings.

- To reliably reserve a region of the address space for mapping, I recommend modifying the IDF linker script (components/esp32/ld/esp32.ld) to take your desired range of address space out of consideration for the app. Possibly also modify the spi_flash_mmap routine, so it doesn't support dynamically mapping into the full range of available MMU slots. Then write your own mapping routines, very similar to the ones used by the IDF bootloader (esp_image_load() routine, etc.)


Who is online

Users browsing this forum: No registered users and 4 guests