aboutsummaryrefslogtreecommitdiff
CFLAGS ?= -Wall -std=gnu99 -O2

ARM_BASE ?= arm-none-eabi

ARM_CC ?= $(ARM_BASE)-gcc

ARM_CFLAGS ?= -mcpu=cortex-a7 -ffreestanding -std=gnu11 -Wall \
	-Wextra $(addprefix -I, $(dirs))

ARM_AS ?= $(ARM_BASE)-as

ARM_OBJCOPY ?= $(ARM_BASE)-objcopy

ARM_ELFFLAGS ?= -nostdlib -lgcc


KERNEL_STAGE2_OBJECTS := setup.o interrupt_vector.o interrupts.o \
	uart.o demo_functionality.o paging.o ramfs_embeddable.o \
	ramfs.o strings.o io.o atags.o scheduler.o

PL_0_TEST_OBJECTS := PL0_utils.o svc.o PL0_test.o strings.o io.o

LOADER_STAGE2_OBJECTS := uart.o strings.o io.o loader_stage2.o

RAMFS_FILES := PL0_test.img


empty:=
space:= $(empty) $(empty)

dirs:=$(shell find ../src/ -type d)
dirs_colon:=$(subst $(space),:,$(dirs))
vpath %.S $(dirs_colon)
vpath %.c $(dirs_colon)
vpath %.ld $(dirs_colon)


all : kernel.img


%.o : %.c
	$(if $(findstring /arm/,$<),\
	$(ARM_CC) $(ARM_CFLAGS),$(HOST_CC) $(HOST_CFLAGS)) -c $< -o $@

%.img : %.elf
	$(ARM_OBJCOPY) $^ -O binary $@

%.o: %.S
	$(ARM_AS) -mcpu=cortex-a7 $< -o $@

%_embeddable.o : %.img
	$(ARM_OBJCOPY) -I binary -O elf32-littlearm -B arm  $^ $@

%.elf : %.ld
	$(ARM_CC) -T $< -o $@ $(ARM_ELFFLAGS) $(filter %.o,$^)


PL0_test.elf : $(PL_0_TEST_OBJECTS)

kernel.elf : kernel_stage1.o

kernel_stage2.elf : $(KERNEL_STAGE2_OBJECTS)

loader_stage2.elf : $(LOADER_STAGE2_OBJECTS)

loader.elf : loader_stage1.o


kernel_stage1.o : kernel_stage2.img

loader_stage1.o : loader_stage2.img


ramfs.img : makefs $(RAMFS_FILES)
	./makefs $(RAMFS_FILES) > $@


qemu-elf : kernel.elf
	qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^

qemu-bin : kernel.img
	qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^

qemu-loader : loader.img kernel.img pipe_image
	./pipe_image | \
	    qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $<

run-on-rpi : kernel.img pipe_image
	./pipe_image | \
	    sudo socat FILE:/dev/ttyUSB0,b115200,raw -
	sudo screen  /dev/ttyUSB0 115200,cs8,-parenb,-cstopb,-hupcl


clean :
	-rm -f *.img *.elf *.o pipe_image makefs

.PHONY: all qemu-elf qemu-bin qemu-loader run-on-rpi clean