···11-FROM rushmash/gcc-arm-embedded-docker:latest AS base
22-33-ARG BUILD_TYPE=Release
44-ARG BUILD_DIR=build
55-66-# RUN apk update && apk add \
77-# gdb-multiarch \
88-# wget \
99-# make cmake ninja-build bzip2 mc file
1010-1111-# RUN mkdir /usr/opt/
1212-# # RUN wget --directory-prefix=/usr/opt/ https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xz
1313-# # RUN mkdir -p /usr/opt/aarch64-none-elf
1414-# # RUN tar -xf /usr/opt/gcc-arm-10.3-2021.07-aarch64-aarch64-none-elf.tar.xz -C /usr/opt/aarch64-none-elf --strip-components=1
1515-# # RUN ln -s /usr/opt/aarch64-none-elf/bin/aarch64-none-elf-gcc /usr/bin/aarch64-none-elf-gcc
1616-# # RUN ln -s /usr/opt/aarch64-none-elf/bin/aarch64-none-elf-ar /usr/bin/aarch64-none-elf-ar
1717-# # RUN ln -s /usr/opt/aarch64-none-elf/bin/aarch64-none-elf-as /usr/bin/aarch64-none-elf-as
1818-# # RUN ln -s /usr/opt/aarch64-none-elf/bin/aarch64-none-elf-ld /usr/bin/aarch64-none-elf-ld
1919-# # RUN ln -s /usr/opt/aarch64-none-elf/bin/aarch64-none-elf-objcopy /usr/bin/aarch64-none-elf-objcopy
2020-2121-2222-# # ENV CC="/usr/bin/aarch64-none-elf-gcc"
2323-# # ENV CXX="/usr/bin/aarch64-none-elf-gcc"
2424-2525-# RUN wget --directory-prefix=/usr/opt/ https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-aarch64-linux.tar.bz2
2626-# RUN mkdir -p /usr/opt/gcc-arm-none-eabi
2727-# RUN tar -xvjf /usr/opt/gcc-arm-none-eabi-10.3-2021.10-aarch64-linux.tar.bz2 -C /usr/opt/gcc-arm-none-eabi --strip-components=1
2828-# RUN ln -s /usr/opt/gcc-arm-none-eabi/bin/arm-none-eabi-gcc /usr/bin/arm-none-eabi-gcc
2929-# RUN ln -s /usr/opt/gcc-arm-none-eabi/bin/arm-none-eabi-ar /usr/bin/arm-none-eabi-ar
3030-# RUN ln -s /usr/opt/gcc-arm-none-eabi/bin/arm-none-eabi-as /usr/bin/arm-none-eabi-as
3131-# RUN ln -s /usr/opt/gcc-arm-none-eabi/bin/arm-none-eabi-ld /usr/bin/arm-none-eabi-ld
3232-# RUN ln -s /usr/opt/gcc-arm-none-eabi/bin/arm-none-eabi-objcopy /usr/bin/arm-none-eabi-objcopy
3333-3434-WORKDIR /home/piOS
3535-3636-# COPY . .
3737-3838-# FROM base AS build
3939-4040-# RUN rm -rf ./${BUILD_DIR}
4141-# RUN cmake -G Ninja -B ./${BUILD_DIR} -S .
4242-# RUN cmake --build ./${BUILD_DIR}
4343-4444-# FROM scratch AS export-stage
4545-# COPY --from=build ./home/piOS/build/bin .
+37-5
README.md
···11# piOS
22+
23This project is trying to build a simple OS for the RaspberryPi Zero W.
34I 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.
44-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.
55+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+77+[[_TOC_]]
5869## Notes
710Since I don't belive there is one perfect source for the relevant topics, I spend a lot of time reading code from others.
···1013 I changed some things were I found it appropritate, but at the end of the day I think Thanos did a great job and since I'm just trying to learn more about the subject, this project was a godsend!
1114* [Bare metal Raspberry Pi 3 tutorials (*Zoltan Baldaszti*)](https://github.com/bztsrc/raspi3-tutorial/): Really nice tutorial that introduces the basic ways of how HW and SW should interact with each other.
12151313-To build the project run
1616+## How to build the project?
1717+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`).
1818+1919+Once 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)
1420```bash
1515-DOCKER_BUILDKIT=1 docker build --progress=plain -f Dockerfile --rm -t pi_os:latest . --output ./export/
2121+cmake -G Ninja -B ./build -S .
2222+cmake --build ./build
1623```
2424+If you like to use docker, you can also use this minimal `Dockerfile` (for the `32-bit` version):
2525+```docker
2626+FROM rushmash/gcc-arm-embedded-docker:latest AS base
17271818-To run it in `qemu` you can use
2828+ARG BUILD_DIR=build
2929+3030+WORKDIR /home/piOS
3131+3232+COPY . .
3333+3434+FROM base AS build
3535+3636+RUN rm -rf ./${BUILD_DIR}
3737+RUN cmake -G Ninja -B ./${BUILD_DIR} -S .
3838+RUN cmake --build ./${BUILD_DIR}
3939+4040+FROM scratch AS export-stage
4141+COPY --from=build ./home/piOS/build/bin .
4242+1943```
2020-qemu-system-arm -M raspi0 -serial null stdio -kernel .export/kernel7.elf
4444+and run it via
4545+```bash
4646+DOCKER_BUILDKIT=1 docker build --progress=plain -f Dockerfile --rm -t pi_os:latest . --output ${PATH_TO_WHERE_YOU_WANT_THE_ELF_AND_IMG}
2147```
4848+4949+## How to run the kernel?
5050+While 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
5151+```bash
5252+qemu-system-arm -M raspi0 -serial null stdio -kernel ${PATH_TO_ELF_FILE}/kernel7.elf
5353+```