4 ms·
Linux on an 8bit Microcontroller (2012)
- ostenning 3y ago“It takes about 2 hours to boot to bash prompt ("init=/bin/bash" kernel command line). Then 4 more hours to boot up the entire Ubuntu ("exec init" and then login). Starting X takes a lot longer.” I laughed at this - amazing work once again.
- PumpkinSpice 3y agoIt's this slow not because of the MCU, though, but because the author is emulating another architecture in software. It would be fairly sluggish on a PC too. This is both very impressive in terms of the sheer amount of work that went into that, but also a tiny bit disappointing because it's not really Linux running natively on an 8-bit chip. I suspect that native Linux is technically doable and would be a lot faster, but would require a lot of fiddling with the kernel, to the point where you'd be rewriting as much as you're keeping. A lot of assembly shims to port, gotta get rid of all the MMU code, etc. AVR chips in particular also also a bit weird because they follow the Harvard architecture - separate addressing for code and data, which is not something the Linux kernel is made for. FWIW, modern 8-bit MCUs are actually pretty darn fast. They have clocks all the way to 50 MHz or so, single-cycle execution for most opcodes, some have DMA and other cool gizmos on the die. They are orders of magnitude faster than the 8-bit tech we had back in the 1980s.
- DougMerritt 3y agoYep. IIRC the ubiquitous 8051 originally took 10-20 clocks just to execute a NOP, and everything else was even slower. For example.
- jdblair 3y agoYou could make a multi-tasking os with no memory protection (kind of like AmigaOS), and with a partially posix api. Is that still Linux?
- AlotOfReading 3y agoThat's basically just NuttX. Along similar lines is Zephyr, which is actually managed by the Linux foundation and broadly follows kernel conventions where reasonable.
- bestouff 3y agoYes, that's called uCLinux - linux without an MMU.
- ladyanita22 3y agoYes, such a thing exists and its a build flag in the Linux kernel.
- swagempire 3y agoWait, isn't this Fuzix? https://hackaday.com/2017/04/16/z80-fuzix-is-like-old-fashioned-unix/ https://hackaday.com/2017/04/16/z80-fuzix-is-like-old-fashio...
- ladyanita22 3y agoIf we had to make a comparison, what would each Cortex M be equivalent to in microprocessors? I wonder how fast is a Cortex M0, an M1, an M3, an M4 and a Cortex M7.
- PumpkinSpice 3y agoIt's really hard to meaningfully compare. They're designed for other things. Most desktop or server CPUs prioritize massive parallelism, which is useful for OSes and multithreaded apps. In contrast, most MCUs have just one single-threaded core. CPUs are expected to run with sophisticated and bulky active cooling, so they reach speeds up to 3-5 GHz; in contrast, MCUs are almost always used without any added cooling and need to be power-efficient, so they seldom venture above 500 MHz. CPUs require external power controllers for dynamic voltage scaling to realize that performance. MCUs are often expected to run off a single supply, often something like "anywhere between 1.8 and 3.3 V". CPUs have a variety of hardware accelerators for operating on gobs of data (e.g., AVX vector instructions). In contrast, the most an MCU is typically expected to do is handle some low-resolution camera, and only some higher-end models have a hardware floating point unit. Most benchmarks are optimized for desktop tasks too, so you can expect MCUs scores to be two orders of magnitude lower. But that doesn't mean they perform that much worse at the tasks they're intended for. In situations where you need to do some real-time ML-based image classification, drive a 4K display, and stream H.265 videos, you generally don't reach for a traditional MCU, but for a CPU, with all the extra power supply complexity and thermal management issues this entails. SoCs blur the line somewhat, because they often combine a CPU core, a graphics card, lots of memory, and a bunch of other things in a single package - making them essentially a fully-fledged computer that can run Linux, but is about as easy to integrate as an MCU. These are still slower than top-of-the-line desktops, but they're in the "one order of magnitude" territory.
- cdelsolar 3y agothis is amazing lmao
- KingLancelot 3y agoWhy are 8bit microcontrollers still a thing?
- PumpkinSpice 3y agoIt's a pretty interesting question, even if a bit tangential to the article! Their main advantage is the comparatively low transistor count. The chips can be made cheaply and don't need cutting-edge fabs. This also makes them exceptionally power-efficient and tolerant of a wide range of supply voltages, so they're easier to integrate into many designs. Just as important, they are far easier to master. Single-cycle instruction execution, single chip-wide clock, simple interfaces to all peripherals. If you don't have an OS to abstract it all away, most of the contemporary 32-bit platforms are a serious pain. Adjusting clock speed on a typical Cortex-M chip requires following a carefully-choreographed sequence of steps, possibly fiddling with flash wait states, various bus clocks, PLLs, and so on. On an 8-bit MCU, you just flip a bit or two. It's a weird misconception that "8-bit" means antiquated or slow. Modern 8-bit MCUs run at high speeds, have plenty of fast memory, and integrate all kinds of cool on-die peripherals - DACs, ADCs, op-amps, DMA controllers, USB controllers, and so on. And in a good majority of embedded applications, they are enough. Of course, there's nothing sacred about 8-bit ALUs, so I wouldn't be surprised if 32-bit ALUs eventually take hold in this market segment. But the replacements would need to preserve that "I can learn this in a weekend" property that isn't preserved in most of the high-performance 32-bit chips available today.
- sweetjuly 3y ago> This also makes them exceptionally power-efficient ... > Single-cycle instruction execution For what it's worth, single cycle execution is really a detriment to power efficiency. There is an optimal logic level per pipeline stage for CMOS processes which will minimize power (and it's usually quite small!). Extremely deep pipelining lets you hit a higher Fmax, but if you don't crank up the frequency you will often save quite a bit of power.
- KingLancelot 3y agoI appreciate your thorough answer, USB is pretty surprising, but just 256 byte address space, and that needs to take into account NULL (I assume?), and various hardware devices represented in the address space, I just don’t get how it’s possible. Honestly even 16 bit is tiny.
- ddtaylor 3y agoObviously now we run Doom on it.
- deleted 3y ago[deleted]
- fsiefken 3y agoI wonder if fuzix could be run on it and would result in a nore performant OS environment
- rapnie 3y agoDo people know about new RISC-V based boards to experiment with? The other day I found Milk-V Duo [0], a $9 computer that runs Linux, and watched a cool video demonstration [1]. Another interesting board is the BeagleV®-Ahead [2], but there must be many more such open source HW/SW projects. [0] https://milkv.io/duo https://milkv.io/duo [1] https://yewtu.be/watch?v=z-GoLDQHYsE https://yewtu.be/watch?v=z-GoLDQHYsE [2] https://www.beagleboard.org/boards/beaglev-ahead https://www.beagleboard.org/boards/beaglev-ahead Update: Found this discussion on the Milk-V of 3 months ago: https://news.ycombinator.com/item?id=36377439 https://news.ycombinator.com/item?id=36377439
- rwmj 3y agoVisionFive 2 is "the one" as far as I'm concerned. Very cheap and crucially it has a slot on the back for an NVMe drive.
- RetroTechie 3y agoFirst decide what you're looking for: Some kind of Raspberri Pi style desktop replacement (or capable of that). GPU, GB's of RAM, plug in USB peripherals, fast external storage, ... Microcontroller: on the lower extreme of CPU power, no graphics, small flash/RAM, grab soldering iron to hook up peripherals. There's ~$0.10 parts there. Boards like the Milk-V Duo fall in between. uC like, faster cpu, larger embedded RAM, may produce video output, not suitable to run modern desktop OS. Very different beasts for very different applications.
- roschdal 3y agoLinux on an Arduino, that's one of my dreams.
- mihaigalos 3y agoAmazing. Congrats.
- sandreas 3y agoNice, but I prefer something slightly more Powerful like the Unihiker with a Rockchip 3308 (https://www.dfrobot.com/product-2691.html https://www.dfrobot.com/product-2691.html, https://www.youtube.com/watch?v=EmBhBfV3Kfw https://www.youtube.com/watch?v=EmBhBfV3Kfw) or the Funkey S (https://www.funkey-project.com/ https://www.funkey-project.com/) with an Allwinner V3s... or even the non open X-Boy Plus (https://github.com/hsinyuwang/X-Boy https://github.com/hsinyuwang/X-Boy) with Allwinner T113-S3. I'm still keeping an Eye on these device types because someday I hope it will be possible to create my personal Audio Player / iPod Nano clone with Wifi and long battery life by putting a buildroot based image (https://github.com/FunKey-Project/FunKey-OS https://github.com/FunKey-Project/FunKey-OS) and Running a C# or Flutter UI on the framebuffer (https://docs.avaloniaui.net/docs/guides/deep-dives/running-on-raspbian-lite-via-drm https://docs.avaloniaui.net/docs/guides/deep-dives/running-o...) I think Mango Pis Cyberpad 1 is pretty close to my wishes, but I haven't had the time to check it out :-) https://mangopi.org/cp1m https://mangopi.org/cp1m
- deleted 3y ago[deleted]
- dmitrygr 3y agoI do like how this comes up here almost perfectly once a year :) I did improve upon this more recently: http://dmitry.gr/?r=05.Projects&proj=33.%20LinuxCard http://dmitry.gr/?r=05.Projects&proj=33.%20LinuxCard