It’s Linux – But On An ESP32

GNU/Linux is an open-source marvel that has over the past three decades given us an almost infinitely versatile and powerful UNIX-like operating system. But even it has its limitations, particularly at the lower end of the hardware scale where less fully-featured processors often lack the prerequisites such as a memory management unit. Thus [JuiceRV]’s feat of booting a Linux kernel on an ESP32 microcontroller seems impossible, what’s happening?

The ESP’s dual 32-bit Xtensa cores are no slouch in the processing power department, but without that MMU it’s not an obvious Linux candidate platform. The solution to this problem comes in the form of an emulated RISC-V virtual machine which provides just enough grunt for a Linux 5.0.0 kernel to boot.

By any measure this represents an impressive piece of work, but will this new-found ability to run Linux on a microcontroller take the world by storm? Of course not, unless your tastes run to the very slowest of computing experiences. It is however the essence of the hack, and for that we salute it.

It’s not the first time Linux has run on a microcontroller, in the past someone hooked up a 30 pin SIMM and an SD card to an 8-bit Atmel chip and did it in a similar way with an ARM emulator.

Via CNX Software.

Header image: Ubahnverleih, CC0.

43 thoughts on “It’s Linux – But On An ESP32

  1. The virtual machine appears cool, could work for very many platforms.

    But MMU-less Linux (previously uClinux) has been in mainline for a long time now, so probably this could be done natively also.

    1. In practice modern Linux is so bloated with features for the PC and server world that the MMUless option is almost irrelevant because anything big enough to usefully run Linux other than as a single kernel bound to a single appliance binary (probably in XIP flash) already has external DRAM and an MMU. Didn’t use to be the case – ucLinux used to be fine with 1Mb in the 2.x days.

    2. Running Linux without MMU is highly insecure and a vast of memory because in that case there are no pages that can be protected, managed and shared efficiently. The irony it that it’a precisely CPUs designed for low memory that lack MMU. A have been forced to build such systems by incompetents that simply don’t understand what a MMU is in the first place and how critically important is a MMU to get all the best features of the Linux operating system. There all went back later when there realized that a simple bug in there user application will most of the time crash the full system because of the lack of protection. Also there a lot of scenarios where you can exhaust the memory faster without a MMU than with a MMU.

      1. I’ll admit I haven’t had my first cup of tea of the morning, but I’ve read, and re-read that passage… and I’m just getting a garbled mess. Maybe auto-incorrect is to blame, but either way, the end result is the same.

        What’s a “vast” of memory? “It’a”? “A have been forced”? “There all went back”? If you could re-post without the grammatical and typographical errors, then I think your post could make sense and you may have a good point.

        Probably the biggest limitations without an MMU are that:
        1. the linker needs to do symbol relocations itself in software
        2. swap space is an impossibility, run out of RAM, tough titties, `malloc() == NULL; errno = ENOSPC;` for you.

        Years ago, cost would have been a big driver in MMU-less Linux systems. Today, MMU-capable chips are common enough there’s just no point in putting the extra engineering time into making a MMU-less design work.

      2. The embedded world has been using uClinux, very successfully, for most on my linux career (over 30 years now) with several significant successful product designs under my belt. I am neither incompetent nor lacking in knowledge or understanding of these systems.
        So don’t be too hasty to discount the merits of a very important aspect of the linux world.

  2. Why? … Sledge hammer to crack a peanut. How about something like FreeRTOS on the ESP32? Wait!! That has already been done and is widely supported. Amazon likes it :). Admirable work, though, Jenny.

    1. Espressif’s own official SDK uses FreeRTOS, so that’s kind of moot. Besides which, just simply making Linux run on the ESP32 for the shits and giggles is a reasonable reason in and of itself — it doesn’t always have to be anything useful.

      1. Are you suggesting that Linux on the ESP32 is not useful? Please clarify. I guess next project could be Linux on the venerable 8051, …, just for “shits and giggles.”

    2. I wish the ESP tools and SDK had a stronger focus on dynamically loading code. That’s one thing missing from the IoT is “apps”.

      Having the ability to make “app capable” devices with less powerful hardware would be amazing, because everything from kitchen timers to multimeters to watches could benefit from just being able to drop an app file on an SD card to customize it.

      They always try to make an OS for devices(Usually just Android) but it always sucks because it doesn’t run on “device” hardware and the battery life is abysmal, and the UIs are touch based instead of some kind of 3 or 4 button standard and 128px screen.

      Being able to make *real* smart devices without taking a poo on cost and battery life would be amazing.

  3. I think people misunderstood what this whole thing is supposed to be. From what i understand juicevm was made first as a small risc-v emulator, and then they ported the emulator to the esp32 which means it can run software that supports the risc-v. They didn’t do this whole thing to run linux or whatever, the point is to make a risc-v emulator that is small enough to be ported to anything.

    Or atleast thats my understanding from this whole thing.

  4. Let me get this straight. He built a VM on an ESP-32 and then boot Linux on it??!! Wow. I have enough hassles to get a RISC-V chip burned into a FPGA. So my question: Can he run an Amiga Emulator on his RISC-V? Then one can run an Apple II Emulator in the Amiga Emulator, I can play Epic again and find a use for all my ESP-32s lying around in a box.

  5. In the 1980’s Microware’s OS9 ran fine on an 8-bit CPU, the entire kernel fit into 8k, and the machines booted using about 32k of 512k. What did you get for that? Real-time multitasking, and Unix-like, but not only that, you got up to 15 virtual windows, for command-line, graphics, and whatever, that could be switched by tapping a key.

    So, no, it’s not quite a miracle that Linux ran on a 32-bit processor.

    1. Didn’t the OS-9 run on the Motorola MC6809? This was a project came out of Motorola, Austin, TX, around 1978-79. There was a Basic09 also. OS9 was awesome!! It was simply ahead of its time. Also the 6809 had a companion MMU chip. I was working in the Applications Group along with Terry, Ed, Joel, et al. Those were the good ol’ days!!

      1. Yes it was the 6809, that had 16bit registers inside, and designed for high level languages.

        The story goes that Motorola wanted to show it off, so they went to Microware. I can’t remember how much Motorola had to do with the design of BASIC09, which was BASIC but had things for more structure. It’s an i terpreter, but you couod do something so the results could run as a program (it’s been years since I last used it.). Microware had previously been offering improvements on Motorola’s monitor for the 6800, or rather, improved monitors that were compatible with Motorola’s.

        Microware didn’t stop with BASIC09, the came up with OS-9. Unix-like, not an attempt at cloning it, it was multiuser and multitasking, with pipes and redirection. Any program could run anywhere, no absolute addresses (the 6809 allowed e eruthing to be relative).

        There were two levels of OS-9. One could only handle 64K, the other required an MMU, and I’m not sure what the limit was.

        Motorola did have the 6829 (I think it was) but I never heard of that MMU being used. SWTP used a 7489 RAM for MMU.

        Radio Shack sold OS-9 for their Color Computer, which maybe was its most visible place. The prices were better there. In 1986 or 87, they introduced the CoCo III, which had a better keyboard, more integration, an 80 column video output, and the needed MMU to handle 128K of RAM, 512K if you upgraded. And they sold OS-9 Level II that made use of that RAM, included BASIC09, a steal.

        There was customizing, not sure if by Microware or the customer, so OS-9 could be adapted to different MMU (the COCO III had 8K blocks, but others had 2K).

        There was a version of OS-9 for the 68000, no MMU there.

        Let’s not forget that in the early eighties Microsoft Xenix was a variant of Unix, and ran withiut an MMU.

        1. There is an OS9 community, in the darkest corners of the retro-computing world. I, myself have a Color Computer 3, with a Coco SDC drive emulator. There’s a good CC3 emulator, and plenty of fresh images. The NitrOS9 source is available. There’s a Drive-Wire system for using a Windows computer to serve images as well.

          https://github.com/VCCE/VCC
          https://sourceforge.net/projects/nitros9/
          https://nitros9.sourceforge.io/snapshot/
          http://www.lcurtisboyle.com/nitros9/nitros9.html

      2. Yes Chuck, Motorola did have their hands in it. I would like to make an OS9-like operating system. The code for NitrOS9 is available, though I want to make something, making sure there’s not one byte of OS9 code– just the naming conventions.

        I liked Basic09, too. It just needed better error handing.

        The future might be in the past : )

        1. Wow, great comments. Looks like someone wants to port OS-9 to the ESP32 (one with RISC-V core) . We are all showing our ages :). BTW I forgot to mention my friend Don W. as one of the contributors to the OS-9 effort. Those were the days!!

  6. I see no reason why one of the early linux versions wouldn’t run – the esp32 has more cpu power, memory, and storage, than my first linux machine.
    You just have to go back a bit, as the current main linux has got very bloaty.
    And it also has more of everything than my amiga 1000 did – even including it’s hard disk – so it could run something like that too..

    But I like to encourage people to hack the other way around – I’d like FreeRTOS to be on more bigger things instead of linux! ie it is surprising that PI doesn’t have a official FreeRTOS version (and no, I don’t have time to do it, and things like Pico are only part done).

  7. I grok that Linux has run in an MMU without environment before, as it happens I’ve done work with the variant on the DragonBall. Oddly enough years earlier met one of the guys behind it. I also met Pat V behind Slackware Linux. But why a virtual machine, if an MMU-less application of Linux could be grafted onto an ESP32?

    1. There’s a port of BSD for PIC32 devices. You need an SD card for the main filesystem, but it exists.
      I’m slowly writing a *nix style OS for ARM M0s, and when I say slowly…

    1. tl,dr: No, you have to change the chip for that.

      A MMU sits between the CPU and memory (at least when they where separate chips) and in a micro controller everything is on the same chip. Yes, esp32 can use PSRAM but I don’t know of any mmu for that bus/ram and in that case there is still unMMUed ram on the chip.
      Using a MMU it is a all or nothing thing.
      The simplest way is probably writing a emulator/virtual machine like in the article and hope that no one writes a program that escapes the emulator/virtual machine.

Leave a Reply to markus muetschardCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.