Small toy raspberry 3 kernel in c++
This project is a small project i started to see if i could build a small kernel for the raspberry pi 3. I initially chose C but then i rewrote it in C++, using it's advanced compiler capabilities to make everything stack based.
My plans for this kernel are:
Firstly you need to have build-devel installed to have the base tools to build a application. You will need a cross-compiler for aarch64, atleast the gcc and binutils packages.
To create the image you will need to run the following commands:
mkdir build -p
cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchian.cmake -DTOOLCHAIN_PATH=/path/to/toolchain
(TOOLCHAIN_PATH is not needed when the toolchain is in your path) ((TOOLCHAIN_PATH must point to the root of the toolchain, not the bin directory))
This will create the image and copy the kernel8.img and the kernel8.elf to the root of the project.
To run the image either run it in qemu via:
qemu-system-aarch64 -M raspi3b -serial null -serial stdio -kernel kernel8.img
Or to install it on a sd card, follow these instructions:
Firstly you will need a SD Card with enough space to hold the image and the bootloader.
If you don't want the hassle of creating the partition and putting the files in yourself, simply download something like raspbian and simply delete all the .img files and put in the kernel8.img file.
If you want to do it yourself, follow these instructions:
Here is a linux script to do it:
device=/dev/sdX
parted $device mklabel msdos
parted -a optimal $device mkpart primary fat32 0% 100MB
mkfs.fat -F 32 ${device}1
mount ${device}1 /mnt/raspi-sd
wget https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin -O /mnt/raspi-sd/bootcode.bin
wget https://github.com/raspberrypi/firmware/raw/master/boot/start.elf -O /mnt/raspi-sd/start.elf
wget https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat -O /mnt/raspi-sd/fixup.dat
cp kernel8.img /mnt/raspi-sd/kernel8.img
umount /mnt/raspi-sd