aboutsummaryrefslogtreecommitdiff
path: root/build/Makefile
blob: c657748b68b2a239b9aea79f63d99bac5722f52e (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
HOST_CC=gcc

HOST_CFLAGS=-Wall -std=gnu99 -I../src/lib/rs232 -O3

ARM_CC=arm-none-eabi-gcc

ARM_CFLAGS=-mcpu=cortex-a7 -ffreestanding -std=gnu11 -Wall -Wextra $(addprefix -I, $(dirs))
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

all : kernel.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)

echo :
	echo $(VPATH)
	echo $(CFLAGS)

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

%.img : %.elf
	arm-none-eabi-objcopy $^ -O binary $@

%.o: %.S
	arm-none-eabi-as -mcpu=cortex-a7 $< -o $@

%_embeddable.o : %.img
	arm-none-eabi-objcopy -I binary -O elf32-littlearm -B arm  $^ $@

%.elf : %.ld
	arm-none-eabi-gcc -T $< -o $@ $(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

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 --stdout | qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $<

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

pipe_image : pipe_image.o rs232.o
	$(HOST_CC) $^ -o $@

makefs : makefs.o
	$(HOST_CC) $^ -o $@

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

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

.PHONY: all qemu-elf qemu-bin clean