fixed-sized memory pool allocator
[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 ODIR = obj
19 _OBJ = main.o uart.o ivt.o systick.o sysinfo.o lib.o regf.o pool.o
20 OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
21
22
23 $(ODIR)/%.o: %.c $(DEPS)
24         @mkdir -p $(@D)
25         $(CC) -c $< $(CFLAGS) -I./include -o $@
26
27 # Start up machine assembly
28 as: 
29         $(AS) $(ASFLAGS) -o start.o start.asm
30
31 # Compile and link all
32 kernel: $(OBJ)
33         $(AS) $(ASFLAGS) -o start.o start.asm
34         $(LD) -nostartfiles -Map $@.MAP -T link.ld -o $@.ELF start.o $^ --print-memory-usage
35         @echo "Creating binary..."
36         $(MKIMG) -Obinary -R .data $@.ELF $@.bin
37
38 # Run in Qemu; note this is a patched version for stm32-f103c8
39 run:
40         /usr/local/bin/qemu-system-arm -serial stdio  -M stm32-f103c8 -kernel kernel.bin
41
42 # Examine all sections
43 examine-all:
44         arm-none-eabi-objdump -D kernel.ELF | less
45
46 # Examine just headers
47 examine-header:
48         arm-none-eabi-objdump -x kernel.ELF | less
49
50 # Flash kernel to board
51 flash:
52         stm32flash -w kernel.bin -v /dev/ttyUSB0
53
54 .PHONY: clean
55
56 clean:
57         rm -rf $(ODIR)/*.o start.o kernel.*
58
59 # Altijd handig deze template
60 #%.o: %.c
61 #       $(CC) -c $(CFLAGS) $< -o $@
62 #       $(CC) -MM $(CFLAGS) $< > $*.d
63 #
64 #%.o: %.s
65 #       $(CC) -c $(CFLAGS) $< -o $@
66
67
68
69