Convert Figma logo to code with AI

s-matyukevich logoraspberry-pi-os

Learning operating system development using Linux kernel and Raspberry Pi

13,132
1,291
13,132
58

Top Related Projects

11,012

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/

1,828

A C++ bare metal environment for Raspberry Pi with USB (32 and 64 bit)

Bare metal Raspberry Pi 3 tutorials

Raspberry Pi ARM based bare metal examples

Build a minimal multi-tasking OS kernel for ARM from scratch

Quick Overview

The raspberry-pi-os repository is an educational project that guides users through the process of building a simple operating system for the Raspberry Pi. It provides a step-by-step tutorial on developing a basic OS from scratch, covering topics such as boot process, memory management, and process scheduling.

Pros

  • Offers hands-on experience in low-level OS development
  • Provides detailed explanations and code examples for each step
  • Focuses specifically on Raspberry Pi hardware, making it accessible for hobbyists
  • Includes exercises and questions to reinforce learning

Cons

  • May be challenging for beginners with limited programming experience
  • Requires specific hardware (Raspberry Pi) to fully implement and test the OS
  • Does not cover advanced OS features or optimizations
  • Updates and maintenance may be infrequent

Getting Started

To get started with the raspberry-pi-os project:

  1. Clone the repository:

    git clone https://github.com/s-matyukevich/raspberry-pi-os.git
    
  2. Install the required tools:

    • ARM GNU Toolchain
    • QEMU (for emulation)
  3. Navigate to the desired lesson directory:

    cd raspberry-pi-os/src/lesson01
    
  4. Build the kernel:

    make
    
  5. Run the OS in QEMU:

    qemu-system-aarch64 -M raspi3 -kernel kernel8.img -serial stdio
    

For detailed instructions and explanations, refer to the README files in each lesson directory.

Competitor Comparisons

11,012

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/

Pros of linux

  • Full-featured, production-ready Linux kernel for Raspberry Pi
  • Extensive hardware support and drivers for various Raspberry Pi models
  • Regular updates and maintenance from the official Raspberry Pi team

Cons of linux

  • Large codebase, potentially overwhelming for beginners
  • Steeper learning curve for those new to kernel development
  • Less focused on educational purposes compared to raspberry-pi-os

Code Comparison

raspberry-pi-os:

void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
    uart_init();
    uart_send_string("Hello, world!\r\n");

    while (1) {
        uart_send(uart_recv());
    }
}

linux:

asmlinkage __visible void __init start_kernel(void)
{
    char *command_line;
    char *after_dashes;

    set_task_stack_end_magic(&init_task);
    smp_setup_processor_id();
    debug_objects_early_init();
    // ... (more initialization code)
}

The raspberry-pi-os example shows a simple kernel entry point, while the linux code demonstrates a more complex initialization process typical of a full-featured kernel.

1,828

A C++ bare metal environment for Raspberry Pi with USB (32 and 64 bit)

Pros of Circle

  • More comprehensive and feature-rich, offering a complete bare metal environment
  • Better documentation and examples for various Raspberry Pi models
  • Active development with regular updates and bug fixes

Cons of Circle

  • Steeper learning curve due to its complexity
  • Less focused on educational purposes compared to raspberry-pi-os
  • May be overwhelming for beginners or those seeking a minimalistic approach

Code Comparison

raspberry-pi-os:

void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
    uart_init();
    uart_send_string("Hello, world!\r\n");

    while (1) {
        uart_send(uart_recv());
    }
}

Circle:

#include <circle/startup.h>

class CKernel
{
public:
    CKernel(void) {}
    bool Initialize(void);
    TShutdownMode Run(void);
};

CKernel kernel;
CKernel *pKernel = &kernel;

The raspberry-pi-os example shows a simple bare-metal kernel with UART communication, while Circle demonstrates a more structured C++ approach with initialization and run methods. Circle's code reflects its more comprehensive nature, offering a fuller development environment for Raspberry Pi projects.

Bare metal Raspberry Pi 3 tutorials

Pros of raspi3-tutorial

  • More comprehensive coverage of low-level hardware interactions
  • Includes graphics programming and USB support
  • Provides a broader range of topics, including bootloader development

Cons of raspi3-tutorial

  • Less focus on operating system concepts and design
  • May be more challenging for beginners due to its low-level nature
  • Fewer explanations of theoretical concepts compared to raspberry-pi-os

Code Comparison

raspberry-pi-os (scheduler implementation):

void scheduler_init(void) {
    preempt_disable();
    for (int i = 0; i < NR_TASKS; i++) {
        task[i] = NULL;
    }
    preempt_enable();
}

raspi3-tutorial (GPIO initialization):

void gpio_init() {
    *GPFSEL1 = 0;
    *GPSET0 = (1<<16);
    *GPCLR0 = (1<<16);
}

The raspberry-pi-os example focuses on task management and scheduling, while the raspi3-tutorial example demonstrates low-level hardware interaction with GPIO pins.

Raspberry Pi ARM based bare metal examples

Pros of raspberrypi

  • More comprehensive coverage of Raspberry Pi models and peripherals
  • Includes examples for various programming languages (C, Python, Assembly)
  • Provides detailed hardware-specific documentation and register descriptions

Cons of raspberrypi

  • Less structured learning path for beginners
  • Fewer explanations and tutorials on operating system concepts
  • Documentation may be more technical and harder to follow for newcomers

Code Comparison

raspberry-pi-os:

void enable_interrupt_controller()
{
    put32(ENABLE_IRQS_1, SYSTEM_TIMER_IRQ_1);
}

raspberrypi:

void enable_irq()
{
    unsigned int ra;
    ra = get32(ARM_IC_BASE + ARM_IC_IRQENABLE1);
    ra |= 1 << 1;
    put32(ARM_IC_BASE + ARM_IC_IRQENABLE1, ra);
}

Both repositories provide examples for enabling interrupts, but raspberrypi uses more hardware-specific register names and bitwise operations, while raspberry-pi-os uses more abstracted function calls and constants.

raspberry-pi-os focuses on building an educational operating system from scratch, providing step-by-step tutorials and explanations of OS concepts. raspberrypi, on the other hand, offers a broader range of examples and documentation for various Raspberry Pi programming tasks, including bare-metal programming and interfacing with different peripherals.

Build a minimal multi-tasking OS kernel for ARM from scratch

Pros of mini-arm-os

  • Simpler and more lightweight, focusing on bare-metal ARM programming
  • Includes examples for both ARM7 and Cortex-M3 architectures
  • Provides a step-by-step tutorial for building a minimal OS

Cons of mini-arm-os

  • Less comprehensive than raspberry-pi-os in terms of OS features
  • Lacks specific Raspberry Pi hardware support
  • Limited to basic OS concepts without advanced functionality

Code Comparison

mini-arm-os (context switching):

void activate(tcb_t *new)
{
    current_task = new;
    context_switch(&(new->sp));
}

raspberry-pi-os (context switching):

void switch_to(struct task_struct * next) 
{
    if (current == next) 
        return;
    struct task_struct * prev = current;
    current = next;
    cpu_switch_to(prev, next);
}

Both projects demonstrate context switching, but raspberry-pi-os includes additional checks and uses a more complex structure for task management.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Learning operating system development using Linux kernel and Raspberry Pi

This repository contains a step-by-step guide that teaches how to create a simple operating system (OS) kernel from scratch. I call this OS Raspberry Pi OS or just RPi OS. The RPi OS source code is largely based on Linux kernel, but the OS has very limited functionality and supports only Raspberry PI 3.

Each lesson is designed in such a way that it first explains how some kernel feature is implemented in the RPi OS, and then it tries to demonstrate how the same functionality works in the Linux kernel. Each lesson has a corresponding folder in the src directory, which contains a snapshot of the OS source code at the time when the lesson had just been completed. This allows the introduction of new concepts gracefully and helps readers to follow the evolution of the RPi OS. Understanding this guide doesn't require any specific OS development skills.

For more information about project goals and history, please read the Introduction. The project is still under active development, if you are willing to participate - please read the Contribution guide.

Follow @RPi_OS on twitter Follow Raspberry Pi OS on facebook Join Raspberry Pi OS in slack Subscribe for updates

Table of Contents