
Building an Operating System for the Raspberry Pi - gregorymichael
https://jsandler18.github.io/
======
AndyKelley
If you're starting a new operating system project, you might consider using
Zig[1] instead of C.

It does all the low level stuff that C does but it has some safety features as
well as generics.

The standard library is usable in freestanding mode, even the data structures
that allocate memory, because everything takes an allocator as a parameter.

Here are some examples:

* i386 OS: [https://github.com/AndreaOrru/zen](https://github.com/AndreaOrru/zen)

* ARM (raspberry pi) OS: [https://github.com/andrewrk/clashos](https://github.com/andrewrk/clashos)

[1]: [http://ziglang.org/](http://ziglang.org/)

~~~
earenndil
Apparently this is the shill-c-alternatives thread. Here's a short list:

* Rust

* D

* Zig

* C2

* Nim

* LISP

* Ante

* Clay

Please note: I think all of the above languages (with the exception of C2) are
awesome and should be looked at.

~~~
rhaps0dy
LISP Is Systems Programming

or, if you want,

LISP: Loses In Systems Programming

~~~
earenndil
LISP machines?

------
jsandler18
Oh shoot. this is mine! If you have any questions or suggestions, feel free to
ask me!

~~~
bringtheaction
In what order should the extra information pages be read in relation to the
tutorial parts?

~~~
jsandler18
The extra information is all linked to from the main parts. The reason it's
also on the main page is so anyone looking for that info independently of this
particular tutorial might find it more easily.

------
epynonymous
this is excellent, i've been thinking about this as well recently. my goal has
been to create a small device/appliance using raspberry pi. i tried out lots
of operating systems: raspbian, ubuntu-mate, ubuntu core, windows iot, fedora,
etc. i needed a lightweight x windows environment, a decent package manager,
and modern linux kernel, overall none of these really seemed to match my
needs. basically raspbian was too heavyweight, it was a desktop environment
with way too many applications like libre office, etc that i just didn't need.
ubuntu core required the use of snaps which are based on docker, i'm hosting
an electron app so that's just overkill, i'm thinking in terms of preserving
memory, too since there's only 1g on the rpi 3 model b so everything has to be
optimized. windows iot requires a windows license, a definite non-starter for
me. i even looked at chromium and android, but those didn't seem to be a good
match because i want to host a golang service and i don't have a touchscreen.
i even looked at fuchsia, but that seems too experimental.

i even considered doing my own os, but ultimately my goal is to build an
appliance so that would be a major distraction. dietpi seems good, i will
probably pursue that, but thanks for writing the article.

~~~
WoodenChair
Why can't you start with Raspbian and uninstall most of the apps?

~~~
untog
There's Raspian Lite, which is pretty much exactly that. You can just add a
window manager onto it.

~~~
epynonymous
will give it a try, i think raspbian is sort of targeted at the education
market for students that need a full blown desktop computer for various
things. the fact that it's running debian as a base is great. how does this
differ from dietpi?

~~~
khedoros1
DietPi is smaller, but I'm not sure exactly what it's missing that Raspbian
Lite has. I've looked into it before, but I don't remember the answer. They're
both Debian-based.

This has a list of DietPi's pre-installed applications and the packages that
it has available for installation:
[http://dietpi.com/phpbb/viewtopic.php?f=8&t=5#p5](http://dietpi.com/phpbb/viewtopic.php?f=8&t=5#p5)

~~~
epynonymous
i noticed dietpi has a great list about the various hardware sbc's and their
performance ratings for things like file system storage, etc. time to also
check out the asus tinker board or odroid c2.

------
xkarga00
I recently discovered dietpi and I am very happy about it.

[http://dietpi.com/](http://dietpi.com/)

~~~
jopsen
When did 400mb linux become light weight?

Sorry, wasn't DSL debian based too... Have the basic things needed grown that
much?

~~~
tylersmith
When it became less than 100% of the size of the smallest common OS for rpis.

------
DSMan195276
Very nice! I've been considering attempting to port an OS that I've been
writing to an ARM device like the Pi, but I've never really looked into it
much. With that said, I'm surprised the booting portion is so easy, I was
under the impression that for the Raspberry Pi (And ARM devices in general) it
was more complex. I suppose though, this is started after the bootloader
that's normally on the SD card correct? I would imagine that makes things a
fair bit simpler if that's the case, since the bootloader would take care of
all the secret sauce.

Do you have plans to implement paging eventually?

~~~
bpye
Yep the proprietary bootloader on the Raspberry Pi handles most initialisation
leaving the SoC in a usable state. If you want to see how things like DRAM
init work you can take a look at the open source reverse engineered firmware
at [https://github.com/christinaa/rpi-open-
firmware](https://github.com/christinaa/rpi-open-firmware) . It isn't complete
but it is just about enough to also boot the Linux kernel.

~~~
DSMan195276
Thanks for linking that, that is one impressive piece of work!

------
0xTJ
I just want to thank you for posting this over here, I've been looking for
something like this. I need something where I can develop and understand code
as I go, so not a completed system, but that also provides final code so I can
have something that actually works. I tried following the OSDev pages to try
an x86 kernel, but I gave up when I couldn't get interrupts to fire.

------
ajb257
This is fantastic. Especially the line-by-line explanations on separate pages.
Thank you @jsandler18!

------
moondev
You can also leverage yocto/bitbake/openembedded to build your own linux
distro for the pi

[https://git.yoctoproject.org/cgit.cgi/meta-
raspberrypi/](https://git.yoctoproject.org/cgit.cgi/meta-raspberrypi/)

------
flamedoge
awesome.. might buy rpi 1 cuz of this

~~~
m-p-3
I think for the cost, a RasPi is always a nice board to tinker with. And
having a bunch of MicroSD cards to experiments makes it easy to test multiple
scenarios easily.

