Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 3.91 KB

README.md

File metadata and controls

110 lines (80 loc) · 3.91 KB

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

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

Kernel

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

User Space

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

Architectures

  • AArch64
  • X86_64
  • X86
  • ARMv6-M (RTOS)

Others

  • Unit / integration tests
  • 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