# sycuricon/riscv-spike-sdk architecture

> Architecture diagram of the GitHub repository sycuricon/riscv-spike-sdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sycuricon/riscv-spike-sdk
- Repository: https://github.com/sycuricon/riscv-spike-sdk

## Overview

##### Main Components
- Toolchain: The “repo/riscv-gnu-toolchain” directory holds the GNU compiler toolchain. This component is fundamental for compiling Linux, test programs, and possibly newlib.
- Linux Kernel: Found in “repo/linux” with configuration files (e.g., work/linux_defconfig). This kernel is compiled by the toolchain and deployed as the system.
- Root Filesystem/Buildroot: “repo/buildroot” is used to build the initramfs/rootfs. Also note that configuration for Buildroot is provided in “conf/buildroot_initramfs_config”.
- Bootloader: The README outlines the option to use either BBL or OpenSBI (repo/opensbi) as the bootloader for launching the simulation.
- Simulator: Spike itself is the simulator that ultimately runs the compiled Linux environment. This involves not only the simulator binary (from “repo/riscv-isa-sim” and possibly “repo/riscv-pk”) but also configuration files like “conf/boot.log” and “conf/spike.cfg”.
- Debug Support: The “conf/starship.cfg” alongside references to OpenOCD and JTAG debugging reflect external debugging support, particularly for an FPGA or similar hardware interface.

##### Interactions and Flow
- Build Process Coordination: The Makefile and quickstart.sh script, along with configuration files in the “conf” folder, orchestrate the building of the toolchain, rootfs, Linux kernel, and bootloader.
- Compilation Workflow: The toolchain builds all software components while referencing appropriate headers from the Linux kernel (as noted in the README regarding toolchain dynamic linking and kernel headers).
- Boot Process: Once built, the bootloader (either BBL or OpenSBI) initiates system startup, which then loads the Linux kernel, which in turn mounts the Buildroot-generated rootfs into memory.
- Simulation & Debug: Spike simulates the hardware. In parallel, there is an optional JTAG/debug interface configured via OpenOCD (using “conf/starship.cfg”) to debug through a physical interface connected to an FPGA development board.

##### Architectural Patterns and Design Principles
- Modular Design: The project is structured to allow independent development and testing of individual components (kernel, toolchain, bootloader, rootfs), similar to a microservices approach but applied to system development.
- Configurability: The heavy emphasis on configuration files (in “conf”) and menuconfig-based reconfiguration (for both Buildroot and Linux) underlines a design geared toward adaptability.
- Clear Separation of Concerns: Each repository directory clearly encapsulates a major subsystem and the supporting configuration enhances clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CF["Configuration Files"]:::config

    RT["RISC-V GNU Toolchain"]:::build
    BR["Buildroot/RootFS"]:::build
    BRC["Buildroot Config"]:::config
    LK["Linux Kernel"]:::os
    KC["Kernel Config"]:::config

    subgraph "Bootloader (OpenSBI/BBL)"
        OSB["OpenSBI"]:::os
        BBL["BBL"]:::os
    end

    SP["Spike Simulator"]:::sim
    SC["Spike Config"]:::config
    DBG["JTAG Debug & OpenOCD Interface"]:::debug
    OD["OpenOCD"]:::debug

    %% Build Process Flow
    RT -->|"compiles"| LK
    RT -->|"builds"| BR
    BRC ---|"configures"| BR
    KC ---|"configures"| LK

    %% Boot Process
    OSB -->|"boots"| LK
    BBL -->|"boots"| LK

    %% Deployment and Debug
    LK -->|"deploys"| SP
    SC ---|"configures"| SP
    SP -->|"debugs"| DBG
    OD -->|"assists"| DBG

    %% Configuration influences
    CF --> RT
    CF --> BR
    CF --> LK
    CF --> OSB
    CF --> BBL
    CF --> SP
    CF --> DBG

    %% Click Events
    click RT "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/riscv-gnu-toolchain"
    click BR "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/buildroot"
    click BRC "https://github.com/sycuricon/riscv-spike-sdk/tree/master/conf/buildroot_initramfs_config"
    click LK "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/linux"
    click KC "https://github.com/sycuricon/riscv-spike-sdk/tree/master/conf/linux_defconfig"
    click OSB "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/opensbi"
    click BBL "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/riscv-pk"
    click SP "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/riscv-isa-sim"
    click SC "https://github.com/sycuricon/riscv-spike-sdk/blob/master/conf/spike.cfg"
    click DBG "https://github.com/sycuricon/riscv-spike-sdk/blob/master/conf/starship.cfg"
    click OD "https://github.com/sycuricon/riscv-spike-sdk/tree/master/repo/riscv-openocd"

    %% Styles
    classDef build fill:#f9f,stroke:#333,stroke-width:2px;
    classDef os fill:#cff,stroke:#333,stroke-width:2px;
    classDef sim fill:#fc9,stroke:#333,stroke-width:2px;
    classDef config fill:#ccf,stroke:#333,stroke-width:2px;
    classDef debug fill:#cfc,stroke:#333,stroke-width:2px;
```
