1 # Copyright 2019 - Robin Krens
2 # Cross compilers links
5 AR=$(TOOLROOT)/arm-none-eabi-ar
7 MKIMG=arm-none-eabi-objcopy
10 # TODO:Cortex-m3 or Cortex-m0?
11 LDFLAGS+= -mthumb -mcpu=cortex-m3
12 CFLAGS+= -mcpu=cortex-m3 -mthumb -g
14 # Start up machine assembly
16 $(AS) $(CFLAGS) -o start.o start.asm
18 # Compile and link all
20 $(AS) $(CFLAGS) -o start.o start.asm
21 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o main.o main.c
22 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o uart.o uart.c
23 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o ivt.o ivt.c
24 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o systick.o systick.c
25 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o sysinfo.o sysinfo.c
26 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o lib.o lib.c
27 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o mm.o mm.c
28 $(CC) $(CFLAGS) -c -I./include -ffreestanding -o regf.o regf.c
29 $(LD) -nostartfiles -T link.ld -o start.out start.o main.o uart.o ivt.o systick.o sysinfo.o lib.o mm.o regf.o
30 $(MKIMG) -Obinary -R .data start.out kernel.bin
32 # Run in Qemu; note this is a patched version for stm32-f103c8
34 /usr/local/bin/qemu-system-arm -serial stdio -M stm32-f103c8 -kernel kernel.bin
36 # Examine all sections
38 arm-none-eabi-objdump -D start.out | less
40 # Examine just headers
42 arm-none-eabi-objdump -x start.out | less
44 # Flash kernel to board
46 stm32flash -w kernel.bin -v /dev/ttyUSB0
50 $(CC) -c $(CFLAGS) $< -o $@
51 $(CC) -MM $(CFLAGS) $< > $*.d
54 $(CC) -c $(CFLAGS) $< -o $@