Follow+Star public number, don’t miss exciting content
Source | Zhiyuan Electronics
Compiled by | strongerHuang
What are the differences between microcontrollers, Cortex-M, and Linux in embedded systems?What processors are needed to run the Linux operating system? ARM9, ARM11?Cortex-M is newer than ARM9, why can’t it run Linux?
Many friends may have similar questions. Below, we will discuss related content around Cortex-M, ARM, and Linux.
ARM and Cortex-M
The architecture of ARM processors defines the instruction set (ISA) and the model of processors based on this architecture. The ARM instruction set has evolved from ARMv1 to today’s ARMv9, with each architectural modification adding practical technologies.
Before ARMv6, its core instruction set architecture was a single type, but starting from ARMv7, its instruction set architecture became three types, namely the well-known Cortex-M, Cortex-R, and Cortex-A, or ARMv7-A, ARMv7-R, ARMv7-M.These three types.
Cortex-M: mainly refers to microcontrollers;
Cortex-R: mainly refers to real-time processors;
Cortex-A: mainly refers to application processors;
For more introductions, refer to the article:The relationship between STM32, Cortex-M3, and ARMv8-M.
It is worth noting that processors under Cortex-M do not have a Memory Management Unit (MMU).
Memory Management Unit (MMU)
MMU: Memory Management Unit.
The Memory Management Unit is mainly responsible for mapping from virtual addresses to physical addresses and checking memory access permissions at the hardware level.In multi-user and multi-process operating systems like Linux, the MMU ensures that each user process has an independent address space to prevent memory overflow.
Figure 2: The position of MMU
MCUs have an address set, called the virtual address range.For example, the Cortex-M 32 has a virtual address range of 0 ~ 0xFFFFFFFF (4G address space).When the controller addresses a 256M memory, its available address range is limited to 0 ~ 0x0FFFFFFF (256M).1. In processors without memory management, virtual addresses are directly sent to the memory bus to read and write the physical memory at that address.Here is an extended reading:The principle of preemptive operation in non-MMU operating systems2. 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 simply 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 a process cannot access data from another process, ensuring that any illegal memory access caused by erroneous instructions or malicious code in any process does not accidentally overwrite data from other processes and does not affect the operation of other processes, thus ensuring the stability of the entire system.On the other hand, each process thinks it exclusively occupies the entire virtual address space, making the implementation of linkers and loaders easier without having to consider whether the address ranges of each process conflict.
Linux Operating System
Operating systems are usually 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-task), so they do not involve address space allocation between threads and do not need to use MMU, such as ucos, FreeRTOS, RT-Thread, etc.
2. Linux systems are non-real-time operating systems, and multi-process is its main feature. You can refer to the article:Is Linux a real-time system or a time-sharing operating system?
Taking Ubuntu as an example, open a shell and check 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 to check the address range of the bash process in that shell, as shown in Figure 5. It is not difficult to find that the address ranges of two different bash processes are exactly the same. In fact, the operating system or user does not need to consider the physical memory address allocation when forking a process; this work is done by the Memory Management Unit (MMU) of the microcontroller.
Figure 5: bash address in shell 2
Since multi-process relies on the memory management unit, can we only open one process when using embedded Linux? Certainly not! After booting, even if the user does nothing, the visible system must have dozens to hundreds of processes running, as shown in Figure 6.
Figure 6: Process Tree
Conclusion
From the above description, we can see that the Linux operating system has a strong dependence on the MMU (Memory Management Unit). If Linux runs on a CPU without a Memory Management Unit, the entire system may only remain at the Uboot stage.
Since ARM’s Cortex-M processors do not have 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 the MMU.
However, is such a workload really worth it? In fact, the MMU was created to solve the increasingly complex memory management of operating systems.
Disclaimer:This article’s material comes from the internet, and the copyright belongs to the original author. If there are any copyright issues, please contact me to delete.———— END————
Reply in the background『Cortex-M』『Linux』 to read more related articles.
Welcome to follow my public account, reply “Join group” to join the technical exchange group according to the rules, reply “1024” to see more content.Welcome to follow my video account:
Click “Read the original text” to see more shares, welcome to share, collect, like, and see.