Running programs from sd using ESP32.

timl12332
Posts: 27
Joined: Wed May 10, 2017 3:05 pm

Running programs from sd using ESP32.

Postby timl12332 » Sun Dec 30, 2018 5:46 pm

Hi,

As the title says, I am trying to build an "OS" that loads programs from SD into memory, and executes them. Now I'm not an expert on this, but I think I have an idea of what needs to be done.
If I'm correct, I need something that will compile the programs, e.g. the esp-idf toolchain. Then, I need a ELF parser to find out at which location in the memory the functions are(e.g. "main"). Then, I need to load the whole file in memory, and point the program to the location where "main" is.(Location is retreived from ELF parser)

Now first, I'd like to know if it's actually possible to run code from ram. Secondly, does my explaination from above make sense? And last, is the esp-idf suitable for use as standalone program compiler.(e.g. using the .elf file it generates)

And do you maybe have any other ideas or corrections?

Thanks!

timl12332
Posts: 27
Joined: Wed May 10, 2017 3:05 pm

Re: Running programs from sd using ESP32.

Postby timl12332 » Sun Dec 30, 2018 7:38 pm

Hello again, I did some research. And I believe in order for the loaded program to work, I need to put it in it's own Page Table. Which I believe is part of the MMU. The ESP32 has an MMU. So is it possible to create page tables? Is that implemented?
And I still hope someone can answer the questions in my first post.

Thanks!

Edit:
Currently the progress is is that I am able to read an esp32 .elf file and extract the entry point from it.(Using elfio) Now I believe I need to load the program in(probably in it's own page table) and point the program to the loaded entry point. Is that correct?

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

Re: Running programs from sd using ESP32.

Postby ESP_Sprite » Mon Dec 31, 2018 12:23 pm

The ESP32 MMU does not have page tables as such, it just has a flat mapping. However, on a more general note, in the architecture for the ESP32 you can only execute from either flash or internal IRAM. This implies that you either need to flash your program into the SPI flash chip, or it needs to be small enough to fully fit into IRAM (disqualifying e.g. anything that does anything with WiFi/TCP/IP).

timl12332
Posts: 27
Joined: Wed May 10, 2017 3:05 pm

Re: Running programs from sd using ESP32.

Postby timl12332 » Mon Dec 31, 2018 12:34 pm

ESP_Sprite wrote:
Mon Dec 31, 2018 12:23 pm
The ESP32 MMU does not have page tables as such, it just has a flat mapping. However, on a more general note, in the architecture for the ESP32 you can only execute from either flash or internal IRAM. This implies that you either need to flash your program into the SPI flash chip, or it needs to be small enough to fully fit into IRAM (disqualifying e.g. anything that does anything with WiFi/TCP/IP).
Thanks for your reply! So if I understand it correctly, not all ram banks on the ESP32 can contain executable memory. And there are no page tables. So the architecture makes it impossible to load programs into ram and execute them.(Because afaik I need page tables for the loaded programs adresses to be correct)
Then, I have another question. Is it possible to attach a second spi flash chip to the esp, and load programs on there and execute them? While still keeping the ability to boot from the first chip?

Thanks!

Edit:
I'm a bit confused on page tables. Do I need them to run programs from memory? Let's say I have a small enough program to fit inside the IRAM, can I succesfully execute it? Or do I need an MMU/page tables for that?

And how would I load something in IRAM specifically?

User avatar
ayan4m1
Posts: 5
Joined: Sun Dec 30, 2018 4:51 pm

Re: Running programs from sd using ESP32.

Postby ayan4m1 » Mon Dec 31, 2018 9:23 pm

See here for what might be a similar question in the GitHub issues.

I also found this this post which seems to sum it up:
There isn't an equivalent for mmap-ing from a filesystem or any other device

Here is more info about the IRAM that ESP_Sprite mentioned.

Seems like SPI flash is the closest thing to what you want, but I am not an expert - spi_flash_mmap Page 557, ESP32 Technical Manual

timl12332
Posts: 27
Joined: Wed May 10, 2017 3:05 pm

Re: Running programs from sd using ESP32.

Postby timl12332 » Wed Jan 02, 2019 10:59 pm

ayan4m1 wrote:
Mon Dec 31, 2018 9:23 pm
See here for what might be a similar question in the GitHub issues.

I also found this this post which seems to sum it up:
There isn't an equivalent for mmap-ing from a filesystem or any other device

Here is more info about the IRAM that ESP_Sprite mentioned.

Seems like SPI flash is the closest thing to what you want, but I am not an expert - spi_flash_mmap Page 557, ESP32 Technical Manual
Thanks!

User avatar
hassan789
Posts: 154
Joined: Thu Jun 29, 2017 2:15 am

Re: Running programs from sd using ESP32.

Postby hassan789 » Sun Jan 06, 2019 3:07 am

why don't you just have multiple images inside the SD card... and have your GUI "ota" the image you want to run.

Who is online

Users browsing this forum: Bing [Bot], MindReader32 and 44 guests