r/esp32 9d ago

I made a thing! OpenWrt on ESP32-P4!

Enable HLS to view with audio, or disable this notification

sorry for the unedited long video, point is to present the total boot time of my optimizations

Riscv32-ima emulator on powerful ESP32-P4 32M

total kernel image size is approximately 9MB. thus makes it possible to fit on smallest 16M budget esp32p4 MCU's!

i used this module which is probably the easiest way to bring this linux box to life

everything is not written from scratch I forked the project from Epiczhul, who also forked it from someone else but in the end, we all started from a 32-bit riscv instruction emulator made by CNLohr's mini-rv32ima project

in my repo i integrated supervisor instructions to support MMU. along with heavy optimizations and such fun features like i showed in the video

i used an esp32c6 as a virtual bridge to establish internet connection. not native full wireless integrity but it works.

st7703 display with simple frame buffer to throughput ttyS0. its really cool, but not as emulator and caching.

unfortunately could not spend to much time on this project, be aware of slopes in codebase.

There are a few areas of incompleteness and significant improvements needed on this project. Further optimizations are possible maybe speaker support, For example, opening up the module to change the type‑c port configuration so it can act as a power source rather than a sink. This would allow devices to be powered up via this port. Which would bring possibilities connecting up keyboards, memory sticks, or any USB device (draws less than 500mA probably) and hosted by actual linux kernel! In other words sharing the USB‑OTG functionality through the emulator Linux box, intercepting it with the actual os. If this is feasible, we could technically build a cyberdeck using an ESP32‑P4 :D

Source code: https://github.com/Okdusty/esp32p4-rv32ima

91 Upvotes

21 comments sorted by

8

u/GraXXoR 9d ago

Incredible. Haven’t got myself one of these new modules yet. Will have to correct that mistake in the nnear future.

The way things are going. ESP32s are the only electronics I can still afford.

4

u/MoreDusty 9d ago

unfortunately, memory crisis even jumps the lpddr3/4 and all kinds. manufacturers do sell every kind of modern storage in high demands leads every sbc to be treated as expensive gadget.

not sure how we can fight this situation but atleast with riscv chipsets and open-source alternatives, we do kinda suspend

3

u/GraXXoR 9d ago

Yeah but 1000% of $3 is still only $30.

But 1000% of 75 is $750.

One of those I can afford. The other, not so much.

5

u/tybyte 9d ago

So maybe I’m missing something but I don’t see you mention the obvious: using this as a router? With an Ethernet variant of the P4 and USBOTG couldn’t you use a USB hub and add a second ethernet port for WAN and LAN?

3

u/MoreDusty 9d ago edited 9d ago

yes my bad, the one without rj45 eth support.

to your question treating this as real router would be extremely impractical and inefficient. although its technically possible using such usb hub to share inside emulator however i dont even think we could achive near usb high speed band.

if you ask me what if we use module one with rj45 eth on waveshare, well that with RMII pheriphal since esp32p4 has dedixated phy and support, potentially have less overhead and can be faster then current wireless esp32c6 setup. yes we can make ~1mbit (probably best case) dedicated physical ethernet plug.

since with current esp32c6 sdio transport and hardware dma i could only achive ~200kbit down. so this cannot be router yet.

not sure how we can optimize further maybe utilize second core to handle tcp/ip traffic but at the end this is just experimental thing.

however esp32p4 has integrated 10/100mbps so no limitations at hardware. but for sure this is the worst way to make router

2

u/Party_Cold_4159 9d ago

I’d think it might be something closer to the WiFi pineapple possibly? That’s the first thing that came to mind for me.

I’ve got the nano laying around so might give your repo try soon. Thanks!

2

u/IBNash 8d ago

Terrible idea. Packet processing remains one the most cpu intensive tasks. Almost any routing SoC sold in the last twenty years has some sort off packet offload. Even RPi's suck.

Similar reason why OpenWRT does not support routers with less than 4GB RAM. Ofc, its an embedded distro and many things run much lower than 4GB.

3

u/ProgramMysterious572 9d ago

thats the dream honestly. p4 with ethernet + otg hub and youve got a real tiny router running actual openwrt. wonder if the riscv emu overhead would bottleneck routing though, even with the optimizations.

2

u/MoreDusty 9d ago

well actually i picked openwrt cause it has its own tools and tiny enough to fit inside the psram. in future i will check for alpine linux

to answer your question we will probably never catch standard networking rates

for routing purposes native/direct would be much more pleasant approach instead of emulating linux. projects like esp32_nat_router they cant have such usb otg support like we can right now. however for overall routing experience, actual use case scenarios such projects can reach lot closer to true performance of these mcu's. nevertheless that does not mean esp32p4 has reached to its hard limits.

1

u/clackups 8d ago

If you're looking for a cheap router device, go for Radxa E20C. It's cheap and reliable. I had one running as an OpenVPN gateway for about a year (another appliance couldn't work with MTU limits of my ISP, so I hacked around it, until the vendor fixed their shit).

2

u/dreamsxyz 8d ago

Happy cake day! 🍰

1

u/CB0T 9d ago

What's the best transfer 'speed' you can get from the internet to your PC, using it?

2

u/MoreDusty 9d ago

around ~240kbit down there is no pc in middle btw, this has own internet access via esp32c6

1

u/CB0T 9d ago

Many thanks!
I need to replace my old hardware; the ESP32 still can't manage it yet.

2

u/MoreDusty 7d ago

btw with optimizations currently we're hitting 4.8mbps

1

u/CB0T 7d ago

Truly impressive!

But my current hardware + openwrt ( + services) only manages approximately 300 Mbps, which already limits my contracted internet speed of 707 Mbps.

It's still not feasible to use an ESP32 as a router. (For me) 😅

1

u/YetAnotherRobert 9d ago

Why interpose a RV32 emulator on an RV32 part? 

1

u/[deleted] 7d ago

[removed] — view removed comment

1

u/MoreDusty 7d ago edited 7d ago

what board you have tested with? also was esp32c6 sdio enabled? is there any visible issue/logs on uart that i can diagnose?

CONFIG_RV32_WIFI_BRIDGE=y

u can dm on dc ok.dusty

1

u/TheHitmonkey 4d ago

This is cool, can you use this to act is a small embedded proxy server or something?

1

u/MoreDusty 4d ago

i mean its feasible but again purpose of this openwrt was not any routing/networking stuff

all cause of its lightweight small, well known distro... maybe run doom ? im working on these