Load code to certain regions of the flash

Rafael Pires
Posts: 1
Joined: Mon Aug 07, 2017 3:45 pm

Load code to certain regions of the flash

Postby Rafael Pires » Mon Aug 07, 2017 4:09 pm

In my application I want load some drivers to a region of the flash (specified by a custom partition table), and use those drivers on my app. Later i want be able to build my application and use those drivers without have to flash that section of the flash again. Basically i want to have pre-compiled functions stored on the flash and have those functions available on the IDF to build my own application. How can i load some parts of the code to a specific flash region? And, how can i have those functions available on the composer?

Best Regards,

Rafael Pires

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

Re: Load code to certain regions of the flash

Postby kolban » Wed Aug 09, 2017 3:35 pm

Howdy Rafael,
I don't have any technical answers to your questions but I am interested in the back story. What problem/puzzle/solution does having "preloaded" libraries of function solve/resolve?

My best guess is that you want to modularize an Over The Air (OTA) refresh of an application so that only portions of the application that are likely to be changed need be changed. That is only a guess though and I'd love to hear the design thinking and goal you have in mind.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Sprite
Posts: 894
Joined: Thu Nov 26, 2015 4:08 am

Re: Load code to certain regions of the flash

Postby ESP_Sprite » Wed Aug 09, 2017 5:35 pm

I would also be very interested in the purpose of this... For the 'how', it is possible in multiple ways. The easiest way may be to write your code, link it using a custom linker script (that makes it end up somewhere in the ESP32 address space) and end up with a binary blob with all the functions in it. Then use a script to convert the symbols in it into a linker file (for example, my elf_to_ld.sh hack is still in esp-idf/components/esp32/ld, you could use that.) Then all you would need to do is use the MMU to map the flash segment into the address space at the address specified in your linker script. (Unfortunately, esp-idf doesn't have an easy option to do this at the moment - if needed, please add a github issue for it) and then you can link your application against the linker script containing the symbols.

There are more complex options - something like a semi-dynamic loader comes to mind - bit as far as I know this is the easiest.

WiFive
Posts: 971
Joined: Tue Dec 01, 2015 7:35 am

Re: Load code to certain regions of the flash

Postby WiFive » Wed Aug 09, 2017 10:20 pm

ESP_Sprite wrote:Then all you would need to do is use the MMU to map the flash segment into the address space at the address specified in your linker script.

What about data/bss/IRAM?

ESP_Sprite
Posts: 894
Joined: Thu Nov 26, 2015 4:08 am

Re: Load code to certain regions of the flash

Postby ESP_Sprite » Sat Aug 12, 2017 1:52 pm

Ah - fair point, I neglected any static variables. Hmm, that's a hard one, you'd have to modify the esp-idf to steer clear of those regions as well.

WiFive
Posts: 971
Joined: Tue Dec 01, 2015 7:35 am

Re: Load code to certain regions of the flash

Postby WiFive » Sat Aug 12, 2017 2:16 pm

ESP_Sprite wrote:Ah - fair point, I neglected any static variables. Hmm, that's a hard one, you'd have to modify the esp-idf to steer clear of those regions as well.


...and you'd have to modify the bootloader to load those sections too.

Who is online

Users browsing this forum: Google [Bot] and 5 guests