basic terminal
[cortex-from-scratch] / Makefile
1 # Copyright 2019 - Robin Krens
2 #
3 # TODO: Somehow integrate this assembly start.asm (start.o)
4 #
5
6 # Cross compilers links
7 CC=arm-none-eabi-gcc
8 LD=arm-none-eabi-ld
9 AS=arm-none-eabi-as
10 MKIMG=arm-none-eabi-objcopy
11
12 # Compiler flags
13 # TODO:Cortex-m3 or Cortex-m0?
14 LDFLAGS+= -mthumb -mcpu=cortex-m3 
15 ASFLAGS+= -mcpu=cortex-m3 -mthumb -g
16 CFLAGS+= -mcpu=cortex-m3 -mthumb -g -ffreestanding 
17
18 BIN = bin
19
20 ODIR = obj
21 _OBJ = ivt.o uart.o systick.o sysinfo.o lib.o regf.o pool.o term.o main.o
22 OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
23
24 $(ODIR)/%.o: %.c 
25         @mkdir -p $(@D)
26         $(CC) -c $< $(CFLAGS) -I./include -o $@
27
28 # Start up machine assembly
29 as: 
30         $(AS) $(ASFLAGS) -o start.o start.asm
31
32 # Compile and link all
33 kernel: $(OBJ)
34         $(AS) $(ASFLAGS) -o start.o start.asm
35         $(LD) -nostartfiles -Map $@.MAP -T link.ld -o $(BIN)/$@.ELF start.o $^ --print-memory-usage
36         @echo "Creating binary..."
37         @mkdir -p $(BIN)
38         $(MKIMG) -Obinary -R .data $(BIN)/$@.ELF  $(BIN)/$@.bin
39
40 # Run in Qemu; note this is a patched version for stm32-f103c8
41 run:
42         /usr/local/bin/qemu-system-arm -serial stdio  -M stm32-f103c8 -kernel $(BIN)/kernel.bin
43
44 # Examine all sections
45 examine-all:
46         arm-none-eabi-objdump -D $(BIN)/kernel.ELF | less
47
48 # Examine just headers
49 examine-header:
50         arm-none-eabi-objdump -x $(BIN)/kernel.ELF | less
51
52 # Flash kernel to board
53 flash:
54         stm32flash -w $(BIN)/kernel.bin -v /dev/ttyUSB0
55
56 .PHONY: clean
57
58 clean:
59         rm -rf $(ODIR)/*.o start.o $(BIN)/kernel.*
60
61 # Altijd handig deze template
62 #%.o: %.c
63 #       $(CC) -c $(CFLAGS) $< -o $@
64 #       $(CC) -MM $(CFLAGS) $< > $*.d
65 #
66 #%.o: %.s
67 #       $(CC) -c $(CFLAGS) $< -o $@
68
69
70
71