+# Copyright 2019 - Robin Krens
+#
+# TODO: Somehow integrate this assembly start.asm (start.o)
+#
+
+# Cross compilers links
CC=arm-none-eabi-gcc
LD=arm-none-eabi-ld
-AR=$(TOOLROOT)/arm-none-eabi-ar
AS=arm-none-eabi-as
MKIMG=arm-none-eabi-objcopy
+# Compiler flags
+# TODO:Cortex-m3 or Cortex-m0?
LDFLAGS+= -mthumb -mcpu=cortex-m3
-CFLAGS+= -mcpu=cortex-m3 -mthumb -g
+ASFLAGS+= -mcpu=cortex-m3 -mthumb -g
+CFLAGS+= -mcpu=cortex-m3 -mthumb -g -ffreestanding
+
+ODIR = obj
+_OBJ = main.o uart.o ivt.o systick.o sysinfo.o lib.o regf.o pool.o
+OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
+
+
+$(ODIR)/%.o: %.c $(DEPS)
+ @mkdir -p $(@D)
+ $(CC) -c $< $(CFLAGS) -I./include -o $@
+# Start up machine assembly
as:
- $(AS) $(CFLAGS) -o start.o start.asm
+ $(AS) $(ASFLAGS) -o start.o start.asm
-all:
- $(AS) $(CFLAGS) -o start.o start.asm
- $(CC) $(CFLAGS) -c -I./include -ffreestanding -o main.o main.c
- $(CC) $(CFLAGS) -c -I./include -ffreestanding -o uart.o uart.c
- $(CC) $(CFLAGS) -c -I./include -ffreestanding -o ivt.o ivt.c
- $(LD) -nostartfiles -T link.ld -o start.out start.o main.o uart.o ivt.o
- $(MKIMG) -Obinary -R .data start.out kernel.bin
+# Compile and link all
+kernel: $(OBJ)
+ $(AS) $(ASFLAGS) -o start.o start.asm
+ $(LD) -nostartfiles -Map $@.MAP -T link.ld -o $@.ELF start.o $^ --print-memory-usage
+ @echo "Creating binary..."
+ $(MKIMG) -Obinary -R .data $@.ELF $@.bin
+# Run in Qemu; note this is a patched version for stm32-f103c8
run:
- qemu-system-arm -serial stdio -M lm3s6965evb -kernel kernel.bin
+ /usr/local/bin/qemu-system-arm -serial stdio -M stm32-f103c8 -kernel kernel.bin
+
+# Examine all sections
+examine-all:
+ arm-none-eabi-objdump -D kernel.ELF | less
+
+# Examine just headers
+examine-header:
+ arm-none-eabi-objdump -x kernel.ELF | less
+
+# Flash kernel to board
+flash:
+ stm32flash -w kernel.bin -v /dev/ttyUSB0
-examine:
- arm-none-eabi-objdump -S start.out
+.PHONY: clean
-%.o: %.c
- $(CC) -c $(CFLAGS) $< -o $@
- $(CC) -MM $(CFLAGS) $< > $*.d
+clean:
+ rm -rf $(ODIR)/*.o start.o kernel.*
-%.o: %.s
- $(CC) -c $(CFLAGS) $< -o $@
+# Altijd handig deze template
+#%.o: %.c
+# $(CC) -c $(CFLAGS) $< -o $@
+# $(CC) -MM $(CFLAGS) $< > $*.d
+#
+#%.o: %.s
+# $(CC) -c $(CFLAGS) $< -o $@