SkillAgentSearch skills...

Sophon

A Raspberry Pi OS Kernel in Rust

Install / Use

/learn @wenyuzhao/Sophon

README

Sophon - A Raspberry Pi Kernel in Rust

An experimental modular-kernel written in Rust.

The name "Sophon" comes from the novel The Three-Body Problem.

Getting Started

Preparation

  1. Install rustup.
  2. qemu-system-aarch64 (optionally gdb-multiarch or lldb for debugging).
  3. For debugging: LLVM tools (lldb, llvm-objcopy and llvm-objdump)
  4. VSCode setup: install the rust-analyzer extension.

Run on QEMU

$ cargo dev run

Run on a Raspberry Pi 4B

Prepare UEFI and bootable USB (once)

  1. Prepare a USB drive with UEFI firmware.
  2. Plug the usb to your Raspberry Pi and connect to a HDMI monitor (or using UART0).
  3. Start Raspberry Pi and goto UEFI settings menu.
  4. Navigate to Device ManagerRaspberry Pi ConfigurationAdvanced Settings and enable ACPI + Device tree

Install kernel

  1. cd boot/uefi
  2. make deploy boot=/path/to/your/usb/directory
  3. Plug the usb to your Raspberry Pi and connect a serial cable to UART0 ports properly.
  4. Use screen to connect to the serial device
    • e.g. screen /dev/tty.usbserial 115200.
  5. Start Raspberry Pi

Design

The current plan is:

Make the kernel as simple and small as possible. Instead of following the micro-kernel approach that puts each kernel component as a isolated user process, Sophon tries to treat the components as kernel modules. This is expected to have higher performance than micro-kernels due to the absence of context switches and message passing overheads.

TODO

Boot

  • [x] Make the kernel boot on AArch64 QEMU (UEFI)
  • [x] Make the kernel boot on a real Raspberry Pi 4B (UEFI)
  • [x] Setup EL1 virtual memory
  • [x] Load kernel as relocatable ELF
  • [x] Start kernel at Exception Level 1
  • [ ] UEFI Network boot
  • [ ] U-boot support

Kernel

  • [x] Initialize drivers based on a device tree
  • [x] Basic interrupt handler support
  • [x] Kernel heap allocation
  • [x] Timer interrupts
  • [x] Scheduling / Context switch
  • [x] Syscalls support
  • [x] Log syscall (output to UART, for user process debugging)
  • [x] Kernel Modules
  • [x] Module-defined syscalls (Module calls)
  • [x] VFS module and Root-FS
  • [ ] Memory management module; mmap and munmap syscalls
  • [ ] File system modules like fat32
  • [x] Process management module
  • [x] Process and multi-threading
  • [x] Driver interface based on modules
  • [ ] SMP support

User Space

  • [ ] Properly trap and handle Stack-overflow exception
  • [x] Launch init process in privileged mode
  • [x] Launch init process in user mode
  • [x] TTY
  • [ ] Update/release ref-counted pages after process exit
  • [ ] Port gcc/libc/rustc

Architectures

  • [x] AArch64
  • [ ] X86_64
  • [ ] X86
  • [ ] ARMv6-M (RTOS)

Others

  • [x] Unit / integration tests
  • [x] Continuous integration (based on GitHub Actions)

References

  1. Raspberry Pi Bare Bones Rust - OSDev
  2. Mailbox Property Interface
  3. Bare Metal Raspberry Pi 3 Tutorials
  4. Bare Metal Raspberry Pi 3 Tutorials (Rust)
  5. Raspberry Pi Hardware Documents
  6. Learning OS dev using Linux kernel & Raspberry Pi
  7. ARM Quad-A7 Documentation (for timer configuration)
  8. Circle - A C++ bare metal programming env for RPi
  9. PanicOS - A simple x86 operating system with graphical user space

Related Skills

View on GitHub
GitHub Stars37
CategoryDevelopment
Updated1mo ago
Forks3

Languages

Rust

Security Score

80/100

Audited on Feb 8, 2026

No findings