Skip to content

meoyushi/Micro_eBPF_RTOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation


Micro eBPF RTOS (STM32F4)

A custom-built Real-Time Operating System (RTOS) written in Modern C++ (C++17) for the STM32F407 Discovery Board.

The ultimate goal of this project is to implement a lightweight eBPF (Extended Berkeley Packet Filter) Virtual Machine inside the kernel, allowing for safe, dynamic code execution on the microcontroller without flashing firmware updates.

🚀 Project Status

•⁠ ⁠[x] Bootloader: Custom Assembly startup (⁠ startup.s ⁠) and Linker Script (⁠ .ld ⁠).

•⁠ ⁠[x] Build System: CMake + ARM GCC Toolchain (No IDE required).

•⁠ [x] ⁠GPIO (Digital I/O)

•⁠ [x] ⁠UART (Serial Communication)

•⁠ ⁠[ ] eBPF VM: Instruction interpreter (In Progress).

•⁠ ⁠[x] Scheduler: Round-Robin task switching (Planned).


🛠 Hardware Required

•⁠ ⁠STM32F407G-DISC1 (Discovery Board)

•⁠ ⁠Mini-USB Cable (for programming via ST-Link)

•⁠ ⁠Micro-USB Cable (optional, for USB OTG features)

💻 Software Prerequisites

•⁠ ⁠VS Code (Editor)

•⁠ ⁠ARM GNU Toolchain (arm-none-eabi-gcc)

•⁠ ⁠CMake (Build Automation)

•⁠ ⁠STM32CubeProgrammer (Optional, for flashing)


📂 Project Structure

Below is the file tree generated after a successful build:

 .
├── build
└── micro_eBPF
    └── software
        ├── CMakelists.txt
        ├── Toolchain.cmake
        ├── build
        │   ├── CMakeCache.txt
        │   ├── CMakeFiles
        │   │   ├── 3.31.0-rc1
        │   │   │   ├── CMakeASMCompiler.cmake
        │   │   │   ├── CMakeCCompiler.cmake
        │   │   │   ├── CMakeCXXCompiler.cmake
        │   │   │   ├── CMakeDetermineCompilerABI_C.bin
        │   │   │   ├── CMakeDetermineCompilerABI_CXX.bin
        │   │   │   ├── CMakeSystem.cmake
        │   │   │   ├── CompilerIdC
        │   │   │   │   ├── CMakeCCompilerId.c
        │   │   │   │   └── CMakeCCompilerId.o
        │   │   │   └── CompilerIdCXX
        │   │   │       ├── CMakeCXXCompilerId.cpp
        │   │   │       └── CMakeCXXCompilerId.o
        │   │   ├── CMakeConfigureLog.yaml
        │   │   ├── CMakeDirectoryInformation.cmake
        │   │   ├── Makefile.cmake
        │   │   ├── Makefile2
        │   │   ├── STM32_RTOS_CPP.elf.dir
        │   │   │   ├── ASM.includecache
        │   │   │   ├── DependInfo.cmake
        │   │   │   ├── build.make
        │   │   │   ├── cmake_clean.cmake
        │   │   │   ├── compiler_depend.make
        │   │   │   ├── compiler_depend.ts
        │   │   │   ├── depend.internal
        │   │   │   ├── depend.make
        │   │   │   ├── flags.make
        │   │   │   ├── progress.make
        │   │   │   └── src
        │   │   │       ├── App
        │   │   │       │   ├── Ledblinker.cpp.obj
        │   │   │       │   ├── Ledblinker.cpp.obj.d
        │   │   │       │   ├── MotorControl.cpp.obj
        │   │   │       │   └── MotorControl.cpp.obj.d
        │   │   │       ├── drivers
        │   │   │       │   ├── Gpio.cpp.obj
        │   │   │       │   ├── Gpio.cpp.obj.d
        │   │   │       │   ├── Timer.cpp.obj
        │   │   │       │   ├── Timer.cpp.obj.d
        │   │   │       │   ├── Uart.cpp.obj
        │   │   │       │   └── Uart.cpp.obj.d
        │   │   │       ├── kernel
        │   │   │       │   ├── Scheduler.cpp.obj
        │   │   │       │   ├── Scheduler.cpp.obj.d
        │   │   │       │   ├── Thread.cpp.obj
        │   │   │       │   ├── Thread.cpp.obj.d
        │   │   │       │   ├── mutex.cpp.obj
        │   │   │       │   └── mutex.cpp.obj.d
        │   │   │       ├── main.cpp.obj
        │   │   │       ├── main.cpp.obj.d
        │   │   │       └── startup.s.obj
        │   │   ├── TargetDirectories.txt
        │   │   ├── cmake.check_cache
        │   │   └── progress.marks
        │   ├── Makefile
        │   ├── STM32_RTOS_CPP.bin
        │   ├── STM32_RTOS_CPP.elf
        │   ├── STM32_RTOS_CPP.map
        │   └── cmake_install.cmake
        ├── include
        │   ├── Drivers
        │   │   ├── Gpio.hpp
        │   │   ├── Registers.hpp
        │   │   ├── Timer.hpp
        │   │   └── Uart.hpp
        │   └── Kernel
        │       ├── Scheduler.hpp
        │       └── Thread.hpp
        ├── src
        │   ├── App
        │   │   ├── Ledblinker.cpp
        │   │   └── MotorControl.cpp
        │   ├── drivers
        │   │   ├── Gpio.cpp
        │   │   ├── Timer.cpp
        │   │   └── Uart.cpp
        │   ├── kernel
        │   │   ├── Scheduler.cpp
        │   │   ├── Thread.cpp
        │   │   └── mutex.cpp
        │   ├── main.cpp
        │   └── startup.s
        └── stm32_flash.ld


⚡ How to Build

This project uses an Out-of-Source build system to keep the code clean.

1.⁠ ⁠Open Terminal in the ⁠ software ⁠ directory.

2.⁠ ⁠Create a Build Directory:

mkdir build
cd build

3.⁠ ⁠Configure (Generate Makefiles): ⁠ cmake -G "MinGW Makefiles" .. ⁠

4.⁠ ⁠Compile: ⁠ ⁠ cmake --build . ⁠

Success: You will see ⁠ [100%] Built target STM32_RTOS_CPP.elf ⁠ and a generated ⁠ STM32_RTOS_CPP.bin ⁠ file.


📥 How to Flash

Option 1: Drag & Drop (Recommended)

1.⁠ ⁠Connect the board via the Mini-USB (ST-LINK) port.

2.⁠ ⁠The board appears as a USB Drive named ⁠ DIS_F407VG ⁠.

3.⁠ ⁠Drag the ⁠ STM32_RTOS_CPP.bin ⁠ file from the ⁠ build ⁠ folder into the drive.

4.⁠ ⁠The LEDs will flash while copying, then the board will reset and run your code.

Option 2: STM32CubeProgrammer

1.⁠ ⁠Open STM32CubeProgrammer.

2.⁠ ⁠Connect to the board.

3.⁠ ⁠Select ⁠ STM32_RTOS_CPP.elf ⁠.

4.⁠ ⁠Click Download.


🔮 Roadmap: The eBPF Implementation

The next phase introduces the eBPF Virtual Machine to the kernel:

1.⁠ ⁠Instruction Set: Define 64-bit eBPF opcodes (ALU, JMP, MEM).

2.⁠ ⁠Registers: Implement the 11 virtual registers (⁠ r0 ⁠-⁠ r10 ⁠).

3.⁠ ⁠Interpreter: A ⁠ switch-case ⁠ engine to decode and execute bytecode.

4.⁠ ⁠Maps: Shared memory data structures for kernel-user interaction.


📜 License

This project is open-source. Feel free to use it for learning RTOS development.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors