X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=Makefile;h=949e28733c7ffff460e766d5449e81aa01fec813;hb=6c208e8615258d585203ee6ecb6778a9d3b81d0a;hp=c4803b97d089402823d9892a53d284718a14f157;hpb=e9d02925e4e4cd03ef878ad9b4af6c94f1cac9cc;p=cortex-from-scratch diff --git a/Makefile b/Makefile index c4803b9..949e287 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,88 @@ +# 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 -LDFLAGS+= -mthumb -mcpu=cortex-m0 -CFLAGS+= -mcpu=cortex-m3 -mthumb -g +# Compiler flags +LDFLAGS+= -mthumb -mcpu=cortex-m3 +ASFLAGS+= -mcpu=cortex-m3 -mthumb -g +CFLAGS+= -mcpu=cortex-m3 -mthumb -g -ffreestanding + +# Include directory +INCLUDE+= -Iinclude + +BIN = bin + +ODIR = obj +_OBJ = ivt.o systick.o sysinfo.o term.o main.o clock.o rtc.o +OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ)) + +DDIR = obj/drivers +_DRIVERS = uart.o tm1637.o led.o tsensor.o at24c.o +DRIVERS = $(patsubst %, $(DDIR)/%,$(_DRIVERS)) + +LDIR = obj/lib +_LIBS = string.o stdio.o regfunc.o pool.o tinyprintf.o +LIBS = $(patsubst %, $(LDIR)/%,$(_LIBS)) + +$(DDIR)/%.o: drivers/%.c + @mkdir -p $(@D) + $(CC) -c $< $(CFLAGS) $(INCLUDE) -o $@ +$(ODIR)/%.o: %.c + @mkdir -p $(@D) + $(CC) -c $< $(CFLAGS) -I./include -o $@ + +$(LDIR)/%.o: lib/%.c + @mkdir -p $(@D) + $(CC) -c $< $(CFLAGS) -I./include -o $@ + +# Start up machine assembly as: - $(AS) $(CFLAGS) -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 - $(CC) $(CFLAGS) -c -I./include -ffreestanding -o systick.o systick.c - $(CC) $(CFLAGS) -c -I./include -ffreestanding -o sysinfo.o sysinfo.c - $(CC) $(CFLAGS) -c -I./include -ffreestanding -o lib.o lib.c - $(CC) $(CFLAGS) -c -I./include -ffreestanding -o mm.o mm.c - $(CC) $(CFLAGS) -c -I./include -ffreestanding -o regf.o regf.c - $(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 - $(MKIMG) -Obinary -R .data start.out kernel.bin + $(AS) $(ASFLAGS) -o start.o start.asm + +# Compile and link all +kernel: $(OBJ) $(DRIVERS) $(LIBS) + $(AS) $(ASFLAGS) -o start.o start.asm + $(LD) -nostartfiles -Map $(BIN)/$@.MAP -T link.ld -o $(BIN)/$@.ELF start.o $^ --print-memory-usage + @echo "Creating binary..." + @mkdir -p $(BIN) + $(MKIMG) -Obinary -R .data $(BIN)/$@.ELF $(BIN)/$@.bin +# Run in Qemu; note this is a patched version for stm32-f103c8 run: - /usr/local/bin/qemu-system-arm -serial stdio -M stm32-f103c8 -kernel kernel.bin + /usr/local/bin/qemu-system-arm -serial stdio -M stm32-f103c8 -kernel $(BIN)/kernel.bin + +# Examine all sections +examine-all: + arm-none-eabi-objdump -D $(BIN)/kernel.ELF | less + +# Examine just headers +examine-header: + arm-none-eabi-objdump -x $(BIN)/kernel.ELF | less + +# Flash kernel to board +flash: + stm32flash -w $(BIN)/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)/* start.o $(BIN)/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 $@