Experimental kernel for embedded devices written in Rust

Overview

Build Status

bkernel is an experimental kernel for embedded devices written in Rust. I'm mostly trying out Rust now to see how it applies to kernel development.

Prerequisites

Note for Nix users

There is shell.nix for you. Just drop in with nix-shell and all dependencies are there (including nightly rust).

Note: it won't work for platforms other than x86-64_linux. You should change rust-nightly hash in shell.nix.

gcc-arm-none-eabi toolchain

You need an gcc-arm-none-eabi toolchain before you can build the kernel.

If you don't know where to get one, you can get it there:

  • Download one for your platform
  • Unpack
  • Add <path_to_toolchain>/bin to your $PATH variable

Rust version

This project needs lots of nightly features:

  • asm
  • core intrinsics
  • const fn
  • lang items
  • allocator
  • conservative impl trait
  • integer atomics
  • fixed size array

Nightly builds are not backward-compatible, so only the latest version is supported (it changes every 6 weeks). That's why you need a reasonably up-to-date nightly rust.

Rust sources

bkernel needs Rust sources to build libcore for the target. If you don't have one, don't worry: it will be automatically downloaded to rust directory.

If you have Rust git repo on you computer, you can point to it with:

export RUSTDIR=/path/to/rust

Note: building bkernel will checkout rust to a commit your rustc was compiled with.

Build instructions

Just invoke make.

Make targets

  • make build all binaries, documentation and run tests;
  • make build only build kernel;
  • make test run tests;
  • make doc build documentation;
  • make flash flash kernel;
  • make reset reset the device;
  • make device_test run device tests. $DEVICE can be set to point to the device tty (defaults to /dev/ttyUSB0).

Running

After booting the kernel you should see all LEDs are turned on and a terminal is running on PB6/PB7 pins.

The following commands are supported:

  • hi - says hello
  • +3/-3/+4/-4/+5/-5/+6/-6 - turn on/off LD3/4/5/6
  • temp - read temperature and humidity from HTU21D sensor
  • panic - throw a panic
  • help - for more commands

Device tests

There are device tests that are executed with expect. It must be installed on your system.

You must flash the device before testing.

To run device tests, execute:

make device_test

or

make device_test DEVICE=/dev/ttyUSB0

Note: device path can be different on your platform.

Issues

If you have any issues or questions with the bkernel, just open an issue or mail me at [email protected].

License

The bkernel source code is licensed by a modified GNU General Public License - the modification taking a form of an exception. The exception permits the source code of applications that use bkernel and are distributed as executables to remain closed source, thus permitting the use of bkernel in commercial applications without necessitating that the whole application be open sourced. The exception can only be used if you wish to combine bkernel with a proprietary product, and you comply with the terms stated in the exception itself.

The full text of the bkernel license is available here.

You might also like...
Open Source Rust kernel; Runs WASM and WASI as lightweight containers.

😳 etheryal Kernel etheryal kernel is an Open Source capability-based Kernel written in the Rust programming language. The kernel allows implementing

Basic Rust kernel using Limine

Rust Limine Barebones This is a small kernel that boots using Limine. Build First of all, download Rust ! (I guess you already did it if you are here

Examples on how to write Windows kernel drivers in Rust

windows-kernel-rs Note: this is still work in progress! This is a Windows kernel framework in Rust that consists of windows-kernel-sys, a crate that p

An x86-64 kernel with ~100% Rust (originally) in a week
An x86-64 kernel with ~100% Rust (originally) in a week

litchi-rs An x86-64 kernel with ~100% Rust (originally) in a week. The continuation of Litchi. Try it Make sure the Rust toolchains and qemu-system-x8

Kernel density estimation in Rust.
Kernel density estimation in Rust.

kernel-density-estimation Kernel density estimation in Rust. Kernel density estimation (KDE) is a non-parametric method to estimate the probability de

A KISS Rust crate to parse Windows kernel crash-dumps created by Windows & its debugger.
A KISS Rust crate to parse Windows kernel crash-dumps created by Windows & its debugger.

kdmp-parser A KISS Rust crate to parse Windows kernel crash-dumps created by Windows & its debugger. This is a cross-platform crate that parses Window

💻 An x86_64 kernel in the works

BruhOS a basic x86_64 kernel in the works. cool stuff written in rust boots with any stivale2-compliant bootloader framebuffer bitmap font renderer pm

The kernel for LibertyOS.
The kernel for LibertyOS.

This is the official repository of the LibertyOS kernel. LibertyOS is an operating system, built with Rust, that is open-source, free-to-use, and open to new contributors.

A custom kernel for educational reasons

A custom kernel for educational reasons

Comments
  • error[E0277]: the trait bound `core::cell::Cell<*mut bscheduler::Task<'static>>: core::marker::Sync` is not satisfied

    error[E0277]: the trait bound `core::cell::Cell<*mut bscheduler::Task<'static>>: core::marker::Sync` is not satisfied

    I used nix-shell and then just make. it ended up with the following:

    [nix-shell:~/home/dev/bkernel]$ make
    git clone https://github.com/rust-lang/rust
    Cloning into 'rust'...
    remote: Counting objects: 616556, done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 616556 (delta 0), reused 0 (delta 0), pack-reused 616553
    Receiving objects: 100% (616556/616556), 283.88 MiB | 1.29 MiB/s, done.
    Resolving deltas: 100% (497849/497849), done.
    Checking connectivity... done.
    cd rust && [ "$(git rev-parse HEAD)" = "a059cb2f3344c0a9efae17dde3d0e16a55ce93db" ] || git checkout -q a059cb2f3344c0a9efae17dde3d0e16a55ce93db || ( git fetch && git checkout -q a059cb2f3344c0a9efae17dde3d0e16a55ce93db )
    mkdir -p lib/thumbv7em-none-eabi
    rustc -g -Z no-landing-pads --target thumbv7em-none-eabi -C opt-level=3 -L lib/thumbv7em-none-eabi rust/src/libcore/lib.rs --out-dir lib/thumbv7em-none-eabi
    rustc -g -Z no-landing-pads --target thumbv7em-none-eabi -C opt-level=3 -L lib/thumbv7em-none-eabi rust/src/liballoc/lib.rs --out-dir lib/thumbv7em-none-eabi
    cargo rustc --target=thumbv7em-none-eabi --release -- -Z no-landing-pads
        Updating registry `https://github.com/rust-lang/crates.io-index`
       Compiling bscheduler v0.0.1 (file:///home/rosen/home/dev/bkernel/bscheduler)
       Compiling smalloc v0.0.1 (file:///home/rosen/home/dev/bkernel/smalloc)
       Compiling stm32f4 v0.0.1 (file:///home/rosen/home/dev/bkernel/stm32f4)
       Compiling bkernel v0.0.1 (file:///home/rosen/home/dev/bkernel)
       Compiling linkmem v0.1.0 (file:///home/rosen/home/dev/bkernel/linkmem)
    error[E0277]: the trait bound `core::cell::Cell<*mut bscheduler::Task<'static>>: core::marker::Sync` is not satisfied
     --> src/scheduler.rs:6:1
      |
    6 | static SCHEDULER: Scheduler<'static> = Scheduler::new();
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `core::cell::Cell<*mut bscheduler::Task<'static>>: core::marker::Sync` not satisfied
      |
      = note: `core::cell::Cell<*mut bscheduler::Task<'static>>` cannot be shared between threads safely
      = note: required because it appears within the type `bscheduler::Scheduler<'static>`
      = note: shared static variables must have a type that implements `Sync`
    
    error[E0277]: the trait bound `core::cell::Cell<u32>: core::marker::Sync` is not satisfied
     --> src/scheduler.rs:6:1
      |
    6 | static SCHEDULER: Scheduler<'static> = Scheduler::new();
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `core::cell::Cell<u32>: core::marker::Sync` not satisfied
      |
      = note: `core::cell::Cell<u32>` cannot be shared between threads safely
      = note: required because it appears within the type `bscheduler::Scheduler<'static>`
      = note: shared static variables must have a type that implements `Sync`
    
    error: aborting due to 2 previous errors
    
    error: Could not compile `bkernel`.
    
    To learn more, run the command again with --verbose.
    Makefile:35: recipe for target 'target/thumbv7em-none-eabi/release/libkernel.a' failed
    make: *** [target/thumbv7em-none-eabi/release/libkernel.a] Error 101
    
    opened by rosenk 3
  • The scope of the unsafe block can be appropriately reduced

    The scope of the unsafe block can be appropriately reduced

    In this function you use the unsafe keyword for almost the entrie function body.

    We need to mark unsafe operations more precisely using unsafe keyword. Keeping unsafe blocks small can bring many benefits. For example, when mistakes happen, we can locate any errors related to memory safety within an unsafe block. This is the balance between Safe and Unsafe Rust. The separation is designed to make using Safe Rust as ergonomic as possible, but requires extra effort and care when writing Unsafe Rust. @rasendubi Hope this PR can help you. Best regards. References https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

    opened by peamaeq 0
Owner
Alexey Shmalko
Alexey Shmalko
An OS kernel written in rust. Non POSIX

"Tifflin" Experimental Kernel (and eventually Operating System) This is an experiment in writing an OS Kernel in rust (http://rust-lang.org). Mostly t

John Hodge (Mutabah) 618 Jan 8, 2023
A tiny 32 bit kernel written in Rust

rustboot A tiny 32 bit kernel written in Rust. I was inspired to download Rust and try to do this after seeing zero.rs - a stub that lets Rust program

Charlie Somerville 1.5k Dec 30, 2022
A new operating system kernel with Linux binary compatibility written in Rust.

Kerla Kerla is a monolithic operating system kernel from scratch in Rust which aims to be compatible with the Linux ABI, that is, runs Linux binaries

Seiya Nuta 3.1k Jan 1, 2023
Minimal x86_64 OS kernel written in Rust

rkernel A minimal x86_64 Rust OS kernel. Multiboot2 VGA driver PIC PIT PS/2 Keyboard driver PS/2 Mouse driver TSC RTC Allocator ATA PIO (In progress..

Divy Srivastava 36 Apr 26, 2022
🍒 Small, simple, and fast kernel written in Rust. 🌸

?? Small, simple, and fast kernel written in Rust. ??

Cherry Developers 5 May 20, 2022
Xrs is a POSIX-subset operating system kernel written in Rust.

XRS-OS ( ?? WIP) Xrs is a POSIX-subset operating system kernel written in Rust. Current project team members 0x5459 core developer (he/him) 0x5457 cor

null 7 Nov 16, 2022
Linux kernel modules written in Rust

Linux kernel modules written in Rust A collection of in-progress experimental Linux kernel modules written for the Rust for Linux project To run the o

Milan 10 Nov 13, 2022
Rux - An x86_64 toy operating system kernel written in Rust

Rux - An x86_64 toy operating system kernel written in Rust. Rux is a port of the Hux kernel, my x86 32-bit single-CPU toy kernel written in C, following the OSTEP book structure and terminology.

Guanzhou Jose Hu 6 Feb 26, 2022
An super minimal kernel written in rust

Grisha This project depends on this blog serie Philipp Oppermann's blog Required Knowlege I don't know what you really need to know to learn efficient

Ismail Ait Bella 3 Feb 3, 2022
Linux ABI-compatible kernel written in Rust

Linux ABI-compatible kernel written in Rust ??️ Screenshot (v0.1.0-alpha.1) ?? Build dependencies To compile GalaxyOS kernel and create basic OS ISO i

Krzysztof Stefańczyk 3 Dec 5, 2022