788955b5fde1992c9de171a285e5f42eba3ab48e
[cortex-from-scratch] / Makefile
1 # Copyright 2019 - Robin Krens
2 # Cross compilers links
3 CC=arm-none-eabi-gcc
4 LD=arm-none-eabi-ld
5 AR=$(TOOLROOT)/arm-none-eabi-ar
6 AS=arm-none-eabi-as
7 MKIMG=arm-none-eabi-objcopy
8
9 # Compiler flags
10 # TODO:Cortex-m3 or Cortex-m0?
11 LDFLAGS+= -mthumb -mcpu=cortex-m3 
12 CFLAGS+= -mcpu=cortex-m3 -mthumb -g 
13
14 # Start up machine assembly
15 as: 
16         $(AS) $(CFLAGS) -o start.o start.asm
17
18 # Compile and link all
19 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
31
32 # Run in Qemu; note this is a patched version for stm32-f103c8
33 run:
34         /usr/local/bin/qemu-system-arm -serial stdio  -M stm32-f103c8 -kernel kernel.bin
35
36 # Examine all sections
37 examine-all:
38         arm-none-eabi-objdump -D start.out | less
39
40 # Examine just headers
41 examine-header:
42         arm-none-eabi-objdump -x start.out | less
43
44 # Flash kernel to board
45 flash:
46         stm32flash -w kernel.bin -v /dev/ttyUSB0
47
48
49 %.o: %.c
50         $(CC) -c $(CFLAGS) $< -o $@
51         $(CC) -MM $(CFLAGS) $< > $*.d
52
53 %.o: %.s
54         $(CC) -c $(CFLAGS) $< -o $@
55
56
57
58