GrieferPig/esp32-s31-linux
Acerca de
Porting MMU Linux to ESP32-S31 and P4
Otros proyectosCrecimiento de estrellas medido
- in 24h
- +2
- in 7 days
- +4
- in 15 days
- +8
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
OriginalLinux 6.18 for ESP32-S31 and ESP32-P4
MMU RV32 Linux running natively on Espressif RISC-V microcontrollers:
- ESP32-S31: Tested on
ESP32-S31-WROOM-3 E1H16R16V(ESP32-S31 Coreboard / Korvo) - ESP32-P4: Tested on
ESP32-P4NRW32 (rev 1.3)(Waveshare ESP32-P4-WIFI6-DEV-KIT) (Yes, it's technically MMU Linux)
WARNING: Experimental Definitely not something you want for production.
Quick Start
Flash a precompiled image from Releases:
12/3/26: The latest images are listed as pre-releases since there's some optimization works to be done.
- ESP32-S31:
s31-generic_full_flash.bin,s31-coreboard_full_flash.bin,s31-korvo_full_flash.bin - ESP32-P4:
p4-generic_full_flash.bin,p4-waveshare-wifi6-dev-kit_full_flash.bin
The generic images are intended for boards that aren't explicitly supported by this project. They have only the internal peripherals enabled by default. You can add support by adapting an existing device tree source and porting peripheral configurations to your board. (A PR for device support would be appreciated!)
Or build locally:
make TARGET=esp32s31 image
make TARGET=esp32p4 image
For more info, visit the get started guide.
Documentation
Note: Outdated, updates pending.
Porting progress
For a detailed overview of the porting progress, refer to the support matrix.
Legend
| Status | Meaning |
|---|---|
| 🟢 Stable | Fully supported and tested |
| 🟡 Experimental | Supported and mostly working |
| 🟠 WIP | Driver exists, features not complete |
| 🔴 Unsupported | Not implemented |
| ⚫ N/A | Lacks relevant peripheral |
System
| Feature | ESP32-S31 | ESP32-P4 |
|---|---|---|
| Linux 6.18 | 🟢 Stable | 🟡 Experimental |
| MMU | 🟢 Stable (Sv32) | 🟡 Experimental (MMU-Flavored MMU) |
| Dual-core SMP | 🟢 Stable | 🟡 Experimental |
| Root filesystem | 🟢 Stable | 🟡 Experimental |
| LP firmware and mailbox | 🟡 Experimental | 🔴 Unsupported |
| Power management | 🟠 WIP | 🔴 Unsupported |
Radio
| Feature | ESP32-S31 | ESP32-P4 |
|---|---|---|
| Wi-Fi station | 🟢 Stable | ⚫ N/A |
| Bluetooth (via BTstack) | 🟢 Stable | ⚫ N/A |
| IEEE 802.15.4 / WPAN | 🟠 WIP | ⚫ N/A |
Peripherals
| Feature | ESP32-S31 | ESP32-P4 |
|---|---|---|
| GPIO | 🟢 Stable | 🟢 Stable |
| UART / USB Serial-JTAG | 🟢 Stable | 🟢 Stable |
| I2C0/I2C1 | 🟡 Experimental | 🟡 Experimental |
| GPSPI2/GPSPI3 host & target | 🟡 Experimental | 🔴 Unsupported |
| I2S/TDM & audio | 🟡 Experimental | 🔴 Unsupported |
| SD/MMC | 🟢 Stable | 🔴 Unsupported |
| Ethernet | 🟢 Stable | 🔴 Unsupported |
| USB gadget / host | 🟡 Experimental | 🔴 Unsupported |
| AHB/AXI GDMA | 🟡 Experimental | 🔴 Unsupported |
| DMA2D / PPA / JPEG / Camera | 🟡 Experimental | 🔴 Unsupported |
| Timers, PWM, and pulse counter | 🟡 Experimental | 🟡 Experimental |
| Analog and sensor blocks | 🟡 Experimental | 🔴 Unsupported |
| Watchdog, NVMEM, RNG, and crypto | 🟢 Stable | 🟠 WIP |
| TWAI/CAN | 🟠 WIP | 🔴 Unsupported |
| RMT | 🟡 Experimental | 🟠 WIP |
FAQs
MMU-flavored MMU?
TL;DR: hardware translation/permission enforcement, software PT management. About 90% of programs you'd run with 32MiB ram work.
Despite not having a Sv32 MMU, the P4 does have a flash/PSRAM remapper, which (surprisingly) implements page-based virtual memory translation for the flash/PSRAM PA region. Combined with PMP (Physical Memory Protection), one can implement a MIPS-style, software backed, hardware enforced MM mechanism.
The P4 has two remappers, one for flash and the other for PSRAM. Each remapper has 1024 entries of 64KiB (ENORMOUS!) pages*, spanning 64MiB in total. Since we care about PSRAM only, this means its maximum VA address range would be a rather pitiful 64MiB, compared to 4GiB for Sv32. Subtracting linear mapping (assuming 32MiB PSRAM) for the kernel's use and vmalloc() usage, an application would have 28MiB usable VA space. This means that although it is enough for must applications that realistically would run on the P4, anything that allocates a large section of pages (e.g. Go programs) would deplete VA and not run. There's not really a way to bypass this unless we intercept memory access and manually translate the addresses on the fly, which is really bad for performance.
Another difference is that Sv32 is per-hart, while the remapper mapping is shared across two harts. This made SMP more complicated, as two processes can be mapped to the same VA and therefore causing conflicts. It is possible to mitigate this by leveraging PIE (position-independent executables) supported by the musl toolchain, by loading executables to different base addresses allocated by the OS, so that parallel processes's VA mapping are less likely to overlap. Overlap can still occur, and in this case, a software arbiter is needed to temporarily pause execution of a program in favor of the other's VA mapping.
For permission control, PMP provides permission management for user code. However, it only have 16 entries (doubled to 32 on the later v3.x chips, but I don't have them on hand), and doesn't fit the 448 PTEs needed for each process. That's why Linux still has to manage all the PT and PTEs in software, and flush/refill when needed (triggered by a PMP access violation, similar to a page fault). Think the hardware PMP and remapper entries as a TLB. NAPOT PMP entries are also preferred when the mapping allows it, so that contiguous multi-page mapping doesn't consume an absurd amount of PMP and "evicts" PMP entries too frequently.
* Later
v3.xrevisions introduced selectable page sizes, but using smaller pages would reduce VA space as remapper entries hasn't increased.
Vibe-coded?
I noticed folks on Hacker News questioning the use of AI-generated code. For transparency:
- Yes, it is heavily agent-assisted. I understand the esp32 microcontroller architecture to some extent, but I barely know how to port Linux to other RISC-V platforms. What I did is to tell the agent something like "Go implement an IPC transport that uses a shared SRAM buffer and an IPC interrupt doorbell" or "sdmmc uses designware ip, search esp-idf usage and port the existing Linux driver over." An AI agent on its own would never discover S31's bespoke hardware behavior without my guidance, for example, that the register
mcliccfghas writable bits, despite esp-idf saying otherwise. However I admit that AI assistance is the direct reason why I am able to progress this fast, and I did learn a lot about kernel development during the process.
Explorar proyectos relacionados
Cargando…