ENGINEERING ★ 449 upvotes 2021

Writing a “bare metal” operating system for Raspberry Pi 4

Retrospective Overview & Key Insights

Distilled analysis of the business dynamics, operational challenges, and strategic takeaways:

In this technical retrospective (2021), @rcarmo shares practical architectural lessons learned from running, scaling, or migrating production software under lean constraints.

Core Principles for Independent Builders:
1
Defaulting to simpler architectures (such as monolithic frameworks, SQLite, or managed VPS) prevents early engineering bankruptcy.
2
Evaluating true compute and egress costs reveals that high cloud bills can often be slashed by 80%+ through judicious re-platforming.
3
Code you write at 2 AM as a solo engineer must be easy to debug six months later without complex microservice dependencies.
Community Debate Themes:

HN engineers debated the tradeoffs between cloud convenience and raw server economics, database indexing strategies, and resisting premature architectural complexity.

Community Discussions & Critical Reviews

High-signal perspectives, counter-arguments, and peer founder insights debated on Hacker News (95 total discussions):

DE @Decabytes Peer Contributor

Setting aside any impracticalities of doing this, I've always wondered what an operating system would look like if it was tightly integrated into a specific virtual machine. Something like Java or Racket (or blub if you would like), to the point where only languages that ran on those platforms could run on the operating system.

One of the biggest issues people bring up when someone asks "Why can't the OS handle garbage?" is that the OS doesn't know what is garbage and what isn't. But if you only ran languages that ran on the OSes virtual machine, then it would know the memory model. Java and Racket both have histories of languages being built on top of them, so if you don't like the base language you could create your own.

I'm not saying this would be practical or useful (other than maybe as a proof of concept) but it could be fun!

TH @throwaway889900 Peer Contributor

Of all the sections in the tutorial, https://github.com/isometimes/rpi4-osdev/tree/master/part10-multicore is probably the best one for anyone to read. I don't think a lot of people grasp that all the cores on a system start running immediately on power up and they're all running the same code from memory initially.

DI @DixieDev Peer Contributor

The readmes in each section are fantastic.

Also, I cannot believe how straight-forward bootstrapping is on a modern ARM chip compared to x64, where things become painful quickly thanks to decades worth of backwards compatibility. Enabling the A20 line[0] is my favourite example of the nonsense you have to deal with.

[0] https://wiki.osdev.org/A20_Line

NO @not-elite Peer Contributor

Wow, is it really this [1] easy to run a C routine?

Where does the rpi4 store the firmware necessary to read from the sd card where this software is (presumably) stored?

[1] https://github.com/isometimes/rpi4-osdev/blob/master/part1-bootstrapping/boot.S

PO @poetaster Peer Contributor

For my older pies I found https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ great. But this is arm assembly territory. I believe subsequent generations of pi have had good tutorials. OS, of course, is a very large, encompassing term. What is a minimal OS?

HISTORICAL ERA Pandemic Bubble (2020–2022)
COMMUNITY SCORE ★ 449 points
TOTAL DISCUSSIONS 95 comments
TOPICS & TECH STACK:
More Retrospectives by @rcarmo