Figure 2: The Role of MMU
MCUs have an address set known as the virtual address range. For example, the virtual address range for Cortex-M 32-bit is 0 ~ 0xFFFFFFFF (4G address space).
When this controller addresses a 256M memory, its usable address range is limited to 0 ~ 0x0FFFFFFF (256M).
1. In processors without memory management, virtual addresses are sent directly to the memory bus to read/write the physical memory at that address.
Further reading: The Preemption Mechanism of Non-MMU Real-Time Operating Systems
2. In controllers with memory management, virtual addresses are first sent to the MMU, mapped to physical addresses, and then sent to the memory bus.
Figure 3: Memory Management Mechanism
Note: The above figure only briefly reflects the mapping mechanism of memory management; other discussions are not included.
The main role of MMU virtual memory management is to provide each process with an independent address space.
The same virtual address in different processes is mapped by the MMU to different physical addresses, and accessing any address in one process cannot access data from another process. This prevents any process from accidentally overwriting data from other processes due to executing erroneous instructions or malicious code, thus ensuring the stability of the entire system.
On the other hand, each process believes it exclusively owns the entire virtual address space, making the implementation of linkers and loaders easier, without worrying about whether the address ranges of different processes conflict.
Operating systems are generally divided into real-time operating systems and non-real-time operating systems.
1. Real-time operating systems are mostly single-process and multi-threaded (multi-tasking), so they do not involve address space allocation between threads and do not require an MMU, such as ucos, FreeRTOS, RT-Thread, etc.
2. The Linux system is a non-real-time operating system, characterized by multi-process. You can refer to the article: Is Linux a Real-Time System or a Time-Sharing Operating System?
Taking Ubuntu as an example, opening a shell and checking the address range of the bash process as shown in Figure 4, its address range is 0x0000000000400000 ~ 0xffffffffff600000.
Figure 4: Bash Address in Shell 1
We open another shell and check the address range of the bash process in that shell, as shown in Figure 5. It is evident that the address ranges of the two different bash processes are identical. In fact, the operating system or user does not need to consider physical memory address allocation when forking() processes; this task is handled by the microcontroller’s memory management unit (MMU).
Figure 5: Bash Address in Shell 2
Since multi-processes rely on the memory management unit, can we run only one process when using embedded Linux? Certainly not! After booting, even if the user does nothing, there are already dozens to hundreds of essential processes running, as shown in Figure 6.
From the above description, we can see that the Linux operating system has a strong dependency on the MMU (memory management unit). If Linux were to run on a CPU without a memory management unit, the entire system would likely remain stuck at the Uboot stage.
Since ARM’s Cortex-M processors lack a memory management unit, it is generally not recommended to run the Linux operating system.
Of course, nothing is absolute; if you rewrite the Linux kernel and pair it with a sufficiently large memory chip, theoretically, it is possible to do without an MMU.
However, is such a workload really worth it? In reality, the MMU was created to address the increasingly complex memory management of operating systems.
Disclaimer: Some materials in this article are sourced from the internet, and copyright belongs to the original authors. If there are copyright issues, please contact me to remove them.
———— END ————

● Column “Embedded Tools”
● Column “Embedded Development”
● Column “Keil Tutorial”
● Selected Tutorials in the Embedded Column
Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Click “Read the Original” to see more shares.