Can Cortex-M Run the Linux Operating System?

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, so why can’t it run Linux?
Many friends may have similar questions, so let’s discuss the 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.

Can Cortex-M Run the Linux Operating System?

Before ARMv6, the core instruction set architecture was a single style, but starting with ARMv7, it became three styles, namely the well-known Cortex-M, Cortex-R, and Cortex-A, or ARMv7-A, ARMv7-R, and ARMv7-M.
  • Cortex-M refers mainly to microprocessors;

  • Cortex-R refers mainly to real-time processors;

  • Cortex-A refers mainly to application processors;

For more information, 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, multi-process operating systems like Linux, the MMU allows each user process to have an independent address space to prevent memory overflow.

Can Cortex-M Run the Linux Operating System?

Figure 2: The Role of MMU

MCUs have an address set, known as the virtual address range. For example, with Cortex-M 32, the virtual address range is 0 ~ 0xFFFFFFFF (4G address space).
When this 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 Working Principle of Preemptive Operating Systems Without MMU
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.

Can Cortex-M Run the Linux Operating System?

Figure 3: Memory Management Mechanism

Note: The above figure simply reflects the mapping mechanism of memory management, and other discussions are not included.
The main function of MMU virtual memory management is to give each process 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 other processes’ data due to erroneous instructions or malicious code, 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 address range conflicts between processes.

Linux Operating System

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, multi-threaded (multi-task), so they do not involve address space allocation between threads and do not require the use of MMU, such as ucos, FreeRTOS, RT-Thread, etc.

2. The Linux system is a non-real-time operating system, with multi-process as its main feature, which can be referred to in the article:Is Linux a Real-Time System or a Time-Sharing Operating System?

For example, in Ubuntu, open a shell and check the address range of the bash process as shown in Figure 4, which ranges from 0x0000000000400000 to 0xffffffffff600000.

Can Cortex-M Run the Linux Operating System?

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 not difficult to see that the address ranges of the two different bash processes are completely the same. In fact, the operating system or user does not need to consider physical memory address allocation when forking a process; this work is done by the memory management unit (MMU) of the microcontroller.

Can Cortex-M Run the Linux Operating System?

Figure 5: Bash Address in Shell 2

Since multi-process relies on the memory management unit, is it possible to run embedded Linux with just one process? It is definitely not feasible! After booting, even if the user does nothing, the visible system must have dozens to hundreds of necessary processes running, as shown in Figure 6.

Can Cortex-M Run the Linux Operating System?

Figure 6: Process Tree

Conclusion

From the description above, 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 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 reality, the MMU was created to address the increasingly complex memory management of operating systems.

Source: Zhiyuan Electronics, StrongerHuang
Copyright belongs to the original author. If there is any infringement, please contact for deletion.
– ENDFollow @Breadboard Community to learn more about robotics, electronics, circuits, and embedded technology

#Recommended Reading#

Design of STM32 Self-Balancing Robot (Code, Circuit Diagram)Implementation of Multiple Servos Controlled Independently on a Robotic ArmSolutions for Sweeping Robot SystemsHow to Implement PID Control Algorithms Using C Language and Ladder Diagrams?Understanding Basic Data Structures and Algorithm Ideas in ProgrammingBeginner’s Guide: Comprehensive Knowledge of C Language BasicsAn Interesting C Language Algorithm Problem

Can Cortex-M Run the Linux Operating System?Click to read the original text and download the material “Common Algorithm Assembly (C/C++ description)”

Leave a Comment