Skip to content

hgruniaux/Pi-kachULM_OS

Repository files navigation

Pi-kachULM_OS

Building the kernel

To build the kernel you will need to install a aarch64 GCC compiler, cmake and mtools:

  • On Ubuntu, something like that:
    sudo apt install gcc-aarch64-linux-gnu make cmake mtools
    Try to install the latest available version of GCC.
  • On macOS,
    brew install gcc make cmake mtools
    should suffice if you are on a M1/M2 CPU. [To be tested]
  • On Windows, good luck. See MinGW or search internet.

Then, you just need you execute in the project directory:

# Change aarch64-linux-gnu- by whatever is named GCC for aarch64 on your system.
cmake -S . -Bbuild -DGCC_PREFIX=aarch64-linux-gnu- --toolchain=cmake/GCCToolchain.cmake
make -j -C build kernel-img

Or (for Clang):

# Change -17 by whatever version of Clang is installed on your system (or use nothing to call `clang` as is).
cmake -S . -Bbuild -DCLANG_SUFFIX=-17 --toolchain=cmake/ClangToolchain.cmake
make -j -C build kernel-img

You should specify -DTARGET_QEMU=ON when configuring CMake if you intend to build an image for QEMU.

Testing the kernel

You can either run the kernel on real Raspberry PI (at least version 3 required) hardware.

Or use QEMU. First, you need to install it:

  • On ubuntu,
    sudo apt install qemu-system-arm
  • On macOS,
    brew install qemu

Then to run the kernel, just type:

# You may need to change qemu-system-aarch64 by whatever is QEMU for aarch64 is named on your computer.
qemu-system-aarch64 \
    -M raspi3b \
    -serial pipe:/tmp/uart-input \
    -serial stdio \
    -kernel build/kernel/kernel8.img \
    -dtb doc/DeviceTree/pi3.dtb \
    -device loader,file=build/binuser/fs.img,addr=0x18000000,force-raw=on

and launch python tools/uart-input-server.py (for the UART keyboard and mouse driver).

If you don't want to use the UART keyboard and mouse driver (you will probably need to modify kernel.cpp):

qemu-system-aarch64 \
    -M raspi3b \
    -serial stdio \
    -kernel build/kernel/kernel8.img \
    -dtb doc/DeviceTree/pi3.dtb \
    -device loader,file=build/binuser/fs.img,addr=0x18000000,force-raw=on

The userspace file structure

  • /: The root
    • /bin: all the executables of the user space
      • /bin/init: ELF program for aarch, the first program started by the OS.
      • /bin/credits: ELF program for aarch, displaying credits on screen
      • /bin/slides: ELF program for aarch, used for the presentation
      • /bin/explorer: ELF program for aarch, a file explorer
    • /wallpaper.jpg: The window manager wallpaper.
    • /slides/: The slides used by the slides user program.