How rust-embedded/rust-raspberrypi-os-tutorials works
This project is an educational repository providing a step‐by‐step series of tutorials for developing a monolithic operating system kernel in Rust on the Raspberry Pi (both RPi3 and RPi4). The project is divided into multiple “tutorial” directories (named with numeric prefixes such as “01_wait_forever”, “02_runtime_init”, etc.), each of which builds on the previous one by gradually adding system functionality—from the early boot code and runtime initialization to device drivers, exception handling, virtual memory, and debugging support.
Main Components
• Boot & CPU Initialization:
– Highlight the boot code (found in the _arch directories; e.g., boot.s, boot.rs) and early CPU initialization routines.
– Show the execution flow starting from the bootloader to the kernel’s main entry point.
• Board Support Package (BSP):
– Emphasize the BSP layers, especially for the Raspberry Pi. These appear across multiple tutorials (“bsp/raspberrypi.rs” and folders under bsp) and encapsulate board-specific initialization, memory layout (sometimes via linker scripts like kernel.ld), device configuration, and peripheral mapping.
• Kernel Core & Runtime:
– Include core kernel modules (for example, panic handlers, synchronization primitives, prints, and common CPU routines).
– Show how these runtime components evolve across the tutorials.
• Device Drivers:
– Identify components like the GPIO and UART drivers (e.g., directories like “05_drivers_gpio_uart”, “X1_JTAG_boot”), that manage hardware I/O.
– Represent the interactions between these drivers and the underlying hardware.
• Memory Management & Virtual Memory:
– Outline modules for virtual memory mapping and MMU configuration (evident in directories such as “10_virtual_mem_part1_identity_mapping”, “14_virtual_mem_part2_mmio_remap”, etc.).
– Include key modules like “mmu.rs”, “translation_table.rs”, and supporting memory allocation modules.
• Exception & Interrupt Handling:
– Include exception handling components (directories “09_privilege_level”, “11_exceptions_part1_groundwork”, “13_exceptions_part2_peripheral_IRQs”, etc.).
– Represent the flow for synchronous and asynchronous exception requests, device interrupts, and how these are routed within the kernel.
• Debugging & Testing Tools:
– Show toolchains and support libraries (e.g., “17_kernel_symbols”, “18_backtrace”, “utils”, “devtool”).
– These support integration testing, symbol extraction, and debugging (using Docker, QEMU, OpenOCD, and GDB).
• Build & Support Infrastructure:
– Represent the build scripts (build.rs in each tutorial), configuration files (like Cargo.toml, rust-toolchain.toml), and Docker-related files (docker folder).
– Include external utilities such as “Minipush” for UART loading and common scripts (in “common”) that support testing.
Relationships and Interactions
• Data Flow:
– Begin with the hardware layer (the physical Raspberry Pi board) and show how the boot ROM triggers the bootloader (via assembly code in _arch).
• Architectural Layers:
• Component Interactions:
– Indicate dependency flows: Bootloader initializes hardware, passes control to the core kernel, which in turn calls out to device drivers, which interface with peripherals via the BSP.
Architectural Patterns and Design Principles
• Modularity:
• Portability:
– Mark the abstraction provided by the BSP for Raspberry Pi, which isolates platform-specific details from core OS services.
• Safety & Performance:
– Indicate where Rust’s unique features are leveraged to provide memory safety and concurrency (modules like synchronization, safe globals, etc.).