Skip to content

01. Environment Setup for Raspberry Pi OS Development

Target Hardware

This tutorial series targets the Raspberry Pi 4 Model B (BCM2711, Cortex-A72, ARMv8-A 64-bit).

Before we start writing code, let's set up the development environment.

Installing the Cross-Compiler

Since we're developing on a PC/Mac for the Raspberry Pi's ARM64 architecture, we need a cross-compiler.

sudo apt update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu cmake git
brew install aarch64-elf-gcc cmake git
sudo pacman -S aarch64-linux-gnu-gcc cmake git

Verify the installation:

aarch64-linux-gnu-gcc --version

Installing Build Tools

We'll use CMake as our build system:

cmake --version  # Should be 3.10 or higher

Setting Up the Project

Clone the os-rasp repository (or create your own):

1
2
3
cd ~/projects
git clone <your-repo-url> os-rasp
cd os-rasp

Project Structure

1
2
3
4
5
6
7
8
9
os-rasp/
├── CMakeLists.txt          # Main build configuration
├── cmake/
│   └── aarch64-none-elf.cmake  # Toolchain file
├── kernel/
│   ├── boot.S              # Assembly entry point
│   ├── kernel.c            # C kernel code
│   └── linker.ld           # Linker script
└── build/                  # Build output (generated)

Building the Kernel

1
2
3
mkdir build && cd build
cmake ..
make

If successful, you'll see:

[100%] Built target kernel8.elf
Generating raw binary image kernel8.img

The output file kernel8.img is what we'll deploy to the Raspberry Pi.

Understanding the Toolchain

CMake Toolchain File

Located at cmake/aarch64-none-elf.cmake, this file tells CMake how to cross-compile:

  • Compiler: aarch64-linux-gnu-gcc
  • Target: ARMv8-A (64-bit) Cortex-A72
  • Flags: -ffreestanding (no standard library), -nostdlib (no startup files)

Key Compiler Flags

  • -mcpu=cortex-a72+nosimd: Target the Raspberry Pi 4's CPU
  • -ffreestanding: We're not using a hosted environment
  • -nostdlib: Don't link against the standard C library

Next Steps

Now that your environment is ready, we'll dive into the boot process and write our first assembly code!