···33include(cmake/target.cmake)
44setup("MODEL_1" ${CMAKE_CURRENT_SOURCE_DIR})
55message("Build Info:\n\t - Arch:\t${ARCH}\n\t - Model:\t${MODEL}")
66+add_compile_options(-DUART_MODE=1) # Activate special mode where charater output gets redirected to UART_0
6778set(CMAKE_DEPENDS_USE_COMPILER ON)
89···20212122set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
22232323-add_subdirectory(os)2424+add_subdirectory(os)
+12-4
README.md
···3344This project is trying to build a simple OS for the RaspberryPi Zero W.
55I have zero experience with embedded SW-development and unfortunately also never had a change to look at it in university. This is a hobby project that I started to get some familiarity with the subject.
66-I don't really have a clear goal, but I'm using other peoples projects on the internet as a reference and will see where it will take me... I have two RaspberryPi's (Zero W, Zero 2 W, and B+) and in the end I would like the code to run on all devices.
66+I don't really have a clear goal, but I'm using other peoples projects on the internet as a reference and will see where it will take me... I have three RaspberryPi's (Zero W, Zero 2 W, and B+) and in the end I would like the code to run on all devices.
7788[[_TOC_]]
99···2222* [Learning operating system development using Linux kernel and Raspberry Pi (*Sergey Matyukevich*)](https://github.com/s-matyukevich/raspberry-pi-os) Lots of explenations about concepts related to OS developement using the Linux kernel and RPi OS as an example. Helps to understand some of the code out there doing things/solving things and seeing the bigger picture!
23232424## How to build the project?
2525-As often with embedded projects, the toolchain hassle is real. The tricky part for this project is the compiler. Since we are writing code that is supposed to run on an ARM processor, you will need the corresponding compiler. All compilers to build for ARM CPU's can be found on [ARM's website](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads). You will most probably have to cross-compile (`x86`->`arm`) and you will need to be careful if you are compiling the kernel for a `32-bit` or a `64-bit` CPU (`arm-none-eabi` vs `aarch64-none-elf`).
2525+As often with embedded projects, the toolchain hassle is real. The tricky part for this project is the compiler. Since we are writing code that is supposed to run on an ARM processor, you will need the corresponding compiler. All compilers to build for ARM CPU's can be found on [ARM's website](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads). You will most probably have to cross-compile (`x86`->`arm`) and you will need to be careful if you are compiling the kernel for a `32-bit` or a `64-bit` CPU (`arm-none-eabi` vs `aarch64-none-elf`). The `CMakeLists.txt` file has all the logic needed to handle which compiler to pick depending on the Raspberry Pi Model you want to compile this code for. You will find in the toplevel `CMakeLists.txt` file a variable thats called `MODEL_X`, where `X` can be `[0,1,2,3,4]`. `MODEL_3` and `MODEL_4` have a `64bit` CPU and thus need the `aarch64` compiler.
2626+2727+*Note*: This project was started with a `32bit` board (RPi 0) and thus most of the code was initially written with the ARMv6 architecture in mind. For example, the entire memory management code was written with ATAGS (ARM Tags) in mind, which where replaced by DTB's (device tree blob's) in ARMv8-a and would thus need a refresh. I will do this at some point, but for now I will focus more on exploring some of the capabilities of the `32bit` version of the board. In short, the `64bit` boards have a lot less functionality compared to the `32bit` boards with this kernel as of now.
26282729Once you have all of this setup, you should be able to simple `cd` into the root of this repo and run (assuming you have `cmake` and `ninja-build` installed on your system)
2830```bash
···3739## How to run the kernel?
3840While the ultimate goal of course is to run the kernel on a RaspberryPi, for development it is useful to also run it in `qemu`. For the `32-bit` version you can use
3941```bash
4040-qemu-system-arm -M raspi0 -serial null stdio -kernel ${PATH_TO_ELF_FILE}/kernel7.elf
4242+# ARMv6 / 32 bit
4343+qemu-system-arm -M raspi0 -serial null -serial stdio -kernel $PATH_TO_ELF/kernel.elf
4444+# ARMv8-a / 64 bit
4545+qemu-system-aarch64 -M raspi3b -serial null -serial stdio -kernel $PATH_TO_ELF/kernel7.elf
4146```
42474848+*Note:* To run the code with `qemu` you use the `.elf`, i.e. the full executable. If you want to test the kernel out on a real Raspberry Pi, then you need to move the `.img` file onto the SD card.
4949+5050+4351## How to generate documentation?
4452To generate the documentation you can run
4553```bash
4654doxygen .doxyfile
4755```
4848-Please make sure to install doxygen and graphviz.5656+Please make sure to install doxygen and graphviz.
+1-1
cmake/target.cmake
···11macro(setup model path)
22- set(BUILD_DIR ${path}/build/bin)
22+ set(BUILD_DIR ${CMAKE_BINARY_DIR}/bin)
3344 if(${model} STREQUAL "MODEL_0"
55 OR ${model} STREQUAL "MODEL_1")
+2-2
os/CMakeLists.txt
···88set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${ARCH_DIR}/linker.ld")
991010set(SOURCES
1111+ src/kernel/random.c
1112 src/kernel/kerio.c
1213 src/kernel/gpu.c
1314 src/kernel/mailbox.c
···3132target_include_directories(${KERNEL}.elf PUBLIC include)
3233target_link_libraries(${KERNEL}.elf PRIVATE common)
3334# target_link_libraries(${KERNEL}.elf PRIVATE utils)
3434-target_compile_definitions(${KERNEL}.elf PRIVATE UART_MODE=1) # Activate special mode where charater output gets redirected to UART_0
35353636# Generates the binary with objcopy.
3737add_custom_command(
···4242)
43434444# Bind above objcopy custom command with `kernel_img` target.
4545-add_custom_target(kernel_img ALL DEPENDS ${KERNEL}.img)4545+add_custom_target(kernel_img ALL DEPENDS ${KERNEL}.img)
+7
os/include/kernel/random.h
···11+#ifndef RANDOM_H
22+#define RANDOM_H
33+44+void rand_init();
55+unsigned int rand(unsigned int min, unsigned int max);
66+77+#endif