A simple #OCaml "Hello World" for a #RPi4 as a bare-metal Operating System with #MirageOS (in 4 days)
At this stage, I'm only able to boot the "caml runtime" on RPi4. But, in MirageOS, we did everything in OCaml, so it's perfect to start IoT in OCaml.
The next step will be the integration in MirageOS 4 where I specially pay my attention into how we orchestrate the compilation from the boot.S to the "caml_startup" function. UART is our serial port to be able to print something: en.wikipedia.org/wiki/Universal…
But the gap between the ability to boot a small bare-metal OS and the integration of the caml runtime is huge. Specially when the cross-compilation story with OCaml is not very... fun...
Indeed, I see 2 main points where the cross-compilation become hugely complex and the ceremony can be the scenario of a Western spaghetti.
The first point is about the absolute location of the caml compiler where you need to care about **all** paths and a certain **fixed** layout of the toolchain. But the OCaml core team is aware about this specific problem: github.com/ocaml/ocaml/is…
The second problem is options and their orders! If you know about the linker, you know what I means. It requires extra binaries which call compilers **plus** some options in the right order (and before what the user/the OCaml compiler puts).
The third issue (yes !) is about C libraries as a 3-part of the OS. Indeed, a Caml library can include a C library - and you must be sure to take the right one (compiled with right flags, etc.). MirageOS 4 and specially opam-monorepo solves this issue! github.com/ocamllabs/opam…
Finally, the path becomes complex when you need a C library and a mathematic lib needed by the caml runtime. Of course, GLIBC is **not** an option.
But MirageOS has a nice experience with that and "ocaml-freestanding", our caml runtime for the virtualization purpose (but not only that): github.com/mirage/ocaml-f…
So we did the static link between a small #nolibc (better is your program with less C!) and we use #openlibm. At least, we must implement from the OS point-of-view only three things: 1) a monotonic clock 2) sbrk 3) puts ... and that's all!
So I mostly followed the great work from Solo5 which does the same thing. And a great thanks to the team, it's nice to see and understand how the pipe can go well!!! github.com/Solo5/solo5
More specifically about RPi4, I would to thanks this tutorial which explains step by step how to make a bare-metal OS: rpi4os.com (and some other sources from Rust/RPi3/osdev wiki)
And finally, I made it in this repository: github.com/dinosaure/gilb… as a souvenir about our cancelled MirageOS retreat in Morocco (I'm currently in Málaga).

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Calascibetta Romain

Calascibetta Romain Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Dinoosaure

25 Feb
Let's talk about Git protocol! I think this one of your most used commands:
Under this simple command, several things appear. You can see a "technical description" of the protocol here:
github.com/git/git/blob/m…
The Git/"Smart" protocol is simple, it's an exchange between the client and the server with a certain format: the PKT-line:
Read 23 tweets
20 Oct 20
Let's talk about one of the most old program I ever see! The file command.
A small research about this command brings us to 1986-1987 - I was not born - so it's a really old project. But it still is updated (last release is 5.38 - 2020-06-27).
But the official mirror repository seems not really accurate (where the Changelog started from 2003). The first "commit" is dated 1987 (according to the website).

darwinsys.com/file/
Read 24 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(