Page 1 of 1

Run linux on the ESP32?

Posted: Fri Aug 10, 2018 11:24 am
by timl12332
Hi there!

I recently read that there are ESP32 modules with 4MB and I heard even 8MB ram. This made me wonder if we can run Linux?
Now I know Linux needs a MMU, but I thought older Linux versions(3.x?) that had the UClinux changes integrated and thus can compile without MMU.
Is it maybe interesting for someone to try?
Or would it at least be possible?

Thanks!

Re: Run linux on the ESP32?

Posted: Fri Aug 10, 2018 1:28 pm
by username
You'd be stretching yourself to thin in doing so, not to mention what real gain would you get by doing so.
For just a few more bucks you can get a Allwinner H2+, Quad-core Cortex-A7 that is meant to run it
https://www.friendlyarm.com/index.php?r ... uct_id=197

Re: Run linux on the ESP32?

Posted: Fri Aug 10, 2018 2:45 pm
by kolban
.... for technical completeness, the ESP32 does indeed have an MMU as well as hardware assistance for process instance isolation of memory.

Re: Run linux on the ESP32?

Posted: Fri Aug 10, 2018 2:56 pm
by timl12332
kolban wrote:.... for technical completeness, the ESP32 does indeed have an MMU as well as hardware assistance for process instance isolation of memory.

I thought that one was not complete enough for Linux?
But what is it needed for anyway? Is it just preventing a process from modifying another process's ram?(Hacking or something)

Re: Run linux on the ESP32?

Posted: Fri Aug 10, 2018 9:06 pm
by kolban
Typically memory isolation is used for robustness. In a privileged address space (ESP32 default), an error in an application or subroutine or task could merrily step all over the memory of other applications. By leveraging process isolation, one adds an extra degree of resiliency to a solution. Assuming an application is composed of multiple coarse grained components, each of those components could be insulated and isolated from the others so a logic error in one component would have that much more resiliency from interfering with the operation of another. While security is a possible utilization, historically, memory isolation between processes was designed for robustness and form simplifcation of the overall environment in which applications run.

Re: Run linux on the ESP32?

Posted: Fri Aug 10, 2018 9:13 pm
by timl12332
kolban wrote:Typically memory isolation is used for robustness. In a privileged address space (ESP32 default), an error in an application or subroutine or task could merrily step all over the memory of other applications. By leveraging process isolation, one adds an extra degree of resiliency to a solution. Assuming an application is composed of multiple coarse grained components, each of those components could be insulated and isolated from the others so a logic error in one component would have that much more resiliency from interfering with the operation of another. While security is a possible utilization, historically, memory isolation between processes was designed for robustness and form simplifcation of the overall environment in which applications run.

That's interesting. So if I e.g. am writing outside of an array, into another process. The MMU(if active) would just terminate the process? Or reset the ESP?

Also I did some research on MMU's, and one thing I read was that it gives each process it's own memory space. Is that correct?
If so, does this mean, I could load precompiled programs from an SD, into memory. Give a process a memory space(using the MMU), and have multiple programs running?
As I would love to turn an ESP into some mini PC, developing my own mini OS.

Thanks!

Re: Run linux on the ESP32?

Posted: Fri Aug 10, 2018 11:31 pm
by kolban
There is a super detailed ESP32 manual called the ESP32 Technical Reference. In chapter "26 - PID/MPU/MMU" there are descriptions of the hardware support for these areas of functions. What I would suggest is to have a good slow read of that section and see how much of it makes sense. I had to read it multiple times and am still novice level.

See:

https://www.espressif.com/sites/default ... ual_en.pdf

Re: Run linux on the ESP32?

Posted: Sat Aug 11, 2018 1:41 am
by Deouss
I must admit I also don't understand quite well how exactly memory management looks like.
What I found out is that it is all done by special memory mapping tables that assign certain context of the process to addressees.
I don't understand why PSRAM space cannot be executed by CPU - is it because MPU disallows it meaning the addresses don't exist in the tables or they have forbidden access flags assigned. This is supposed to be more straightforward.

Re: Run linux on the ESP32?

Posted: Sat Aug 11, 2018 10:52 am
by timl12332
kolban wrote:There is a super detailed ESP32 manual called the ESP32 Technical Reference. In chapter "26 - PID/MPU/MMU" there are descriptions of the hardware support for these areas of functions. What I would suggest is to have a good slow read of that section and see how much of it makes sense. I had to read it multiple times and am still novice level.

See:

https://www.espressif.com/sites/default ... ual_en.pdf

Thanks, I'll read it when I have some time!

Deouss wrote:I must admit I also don't understand quite well how exactly memory management looks like.
What I found out is that it is all done by special memory mapping tables that assign certain context of the process to addressees.
I don't understand why PSRAM space cannot be executed by CPU - is it because MPU disallows it meaning the addresses don't exist in the tables or they have forbidden access flags assigned. This is supposed to be more straightforward.

PSRAM can't contain executable instructions? That's unfortunate. Would have been useful for making a little OS that can load programs into ram and execute them.