From fcef8b6535c402902d6493f5902ccaa46eeaad9a Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Fri, 12 Feb 2021 20:10:04 +0000 Subject: [PATCH] Updated intro and Makefiles to use LLVM clang in the right location --- README.md | 12 ++++++++++++ part2-building/Makefile | 4 ++-- part3-helloworld/Makefile | 4 ++-- part4-miniuart/Makefile | 4 ++-- part5-framebuffer/Makefile | 4 ++-- part6-breakout/Makefile | 4 ++-- part7-bluetooth/Makefile | 4 ++-- part8-breakout-ble/Makefile | 4 ++-- 8 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5aac8ec..9e594dd 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,22 @@ Don't proceed until you get Raspbian running! The RPi4 runs on an Arm Cortex-A72 processor. Your dev machine is likely running on an Intel processor. You'll therefore need some software that helps you build code to run on a different architecture. This is called a **cross-compiler**. +Using Arm's compiler for Linux +------------------------------ + Download and unpack [Arm's gcc compiler](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads). For reasons that I won't go into here, you'll need to use the "AArch64 ELF bare-metal target". Since I'm using WSL on Windows 10 to emulate Ubuntu, I downloaded the x86_64 Linux hosted cross-compiler. I also advocate installing GNU make - you'll need it soon enough. Because I'm using WSL, for me that was simply a matter of typing `sudo apt install make` and entering my password. +Using clang on Mac OS X (Apple Silicon or Intel) +------------------------------------------------ + +Download and install XCode from the App Store. This will give you a raft of developer tools for free, including `make`. + +I recommend using [Homebrew](https://docs.brew.sh/Installation) to install LLVM. For me, Homebrew was already installed, so this was a simple case of typing `brew install llvm`. + +LLVM will give you all you need to start building for Raspberry Pi bare metal on Mac. It even works on my M1 MacBook Pro with Apple Silicon, which runs an ARM processor rather than an Intel processsor. + _Now you're ready to start writing your OS!_ [Go to part1-bootstrapping >](./part1-bootstrapping/) diff --git a/part2-building/Makefile b/part2-building/Makefile index 86c7420..12441a6 100644 --- a/part2-building/Makefile +++ b/part2-building/Makefile @@ -6,10 +6,10 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part3-helloworld/Makefile b/part3-helloworld/Makefile index 86c7420..12441a6 100644 --- a/part3-helloworld/Makefile +++ b/part3-helloworld/Makefile @@ -6,10 +6,10 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part4-miniuart/Makefile b/part4-miniuart/Makefile index 86c7420..12441a6 100644 --- a/part4-miniuart/Makefile +++ b/part4-miniuart/Makefile @@ -6,10 +6,10 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part5-framebuffer/Makefile b/part5-framebuffer/Makefile index 86c7420..12441a6 100644 --- a/part5-framebuffer/Makefile +++ b/part5-framebuffer/Makefile @@ -6,10 +6,10 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part6-breakout/Makefile b/part6-breakout/Makefile index 86c7420..12441a6 100644 --- a/part6-breakout/Makefile +++ b/part6-breakout/Makefile @@ -6,10 +6,10 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part7-bluetooth/Makefile b/part7-bluetooth/Makefile index 143c51b..d0d1f1d 100644 --- a/part7-bluetooth/Makefile +++ b/part7-bluetooth/Makefile @@ -6,13 +6,13 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o BCM4345C0.o : BCM4345C0.hcd $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) BCM4345C0.o $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf diff --git a/part8-breakout-ble/Makefile b/part8-breakout-ble/Makefile index 143c51b..d0d1f1d 100644 --- a/part8-breakout-ble/Makefile +++ b/part8-breakout-ble/Makefile @@ -6,13 +6,13 @@ GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o BCM4345C0.o : BCM4345C0.hcd $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ %.o: %.c - clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) BCM4345C0.o $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf