Fine grained control over where the heaps reside in memory

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

Fine grained control over where the heaps reside in memory

Postby kolban » Tue Jun 12, 2018 4:22 pm

My current belief is that when the ESP32 loads an application at boot time, it copies the .data and .bss sections of that application into RAM and then maps the .text (found in flash) into the address space of the ESP32 and then control is branched to the entry point of the application. I further am assuming that prior to control being given to the application, the remaining RAM is "given" to the heap management subsystem for further dynamic allocation at run-time.

Now the question ... suppose I wanted to have control over the locations and amount of RAM used for heap, how might I go about this?

Let us make up an example. Imagine I compile my app to its ELF binary. I then look in that ELF and find (made up numbers) that .data is 10K and .bss is 20K. This says that the app will need 30K for its global storage. Now assume we have 200K of RAM in total in an ESP32. From this 200K, we would carve out 30K for the app's global storage leaving 170K remaining. I am assuming that the heap size is now 170K. This is normal and standard.

Now assume that I wanted to "reserve" some chunk of RAM that is not under heap management/control but yet needs to be at a fixed location in the ESP32 address space. For example, if today RAM starts at address <base> then we have:

<base+0> Start of .data/.bss
<base+30K> Start of heap
<base+200K> End of heap

What if I wanted:

<base+0> Start of .data/.bss
<base+30K> Start of heap part 1
<base+100K> End of heap part 1
<base+100K> Start of reserved
<base+140K> End of reserved
<base+140K> Start of heap part 2
<base+200K> End of heap part 2

I would end up with:

30K for .bss/.data
130K for total heap (70K+60K)
40K for reserved RAM

Would such a scheme be possible? I seem to see that there are APIs for heap control as described here ...

http://esp-idf.readthedocs.io/en/latest ... alloc.html

however I'm thinking that I can't use the heap initialization in my "app" as by that time the heap has already been locked down and can't be changed. Would I be looking at modifying a bootloader? Any other notions/ideas?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32


Who is online

Users browsing this forum: Baidu [Spider], Drohne, steevke and 64 guests