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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
C_SOURCES = $(wildcard src/*.c src/**/*.c)
C_OBJECTS = ${C_SOURCES:.c=.co}
C_OBJECTD = ${subst src,obj,${C_OBJECTS}}
A_SOURCES = $(wildcard src/*.S src/**/*.S)
A_OBJECTS = ${A_SOURCES:.S=.ao}
A_OBJECTD = ${subst src,obj,${A_OBJECTS}}
ATTACH_USB ?= 0
AUTO ?= 0
BSP ?= 2
DEBUG ?= 0
SILENT ?= 0
DISK ?= /dev/sdc1
CROSS = arm-none-eabi
CC = ${CROSS}-gcc
AS = ${CROSS}-as
OBJCOPY = ${CROSS}-objcopy
OBJDUMP = ${CROSS}-objdump
QEMU = qemu-system-arm
GDB = gdb-multiarch
CFLAGS = -mcpu=cortex-a7 -fpic -ffreestanding -std=gnu99 -O3 -Wall -Wextra -nostdlib -Iinclude -g
CFLAGS += -DVERSION="\"0.9z\""
AFLAGS = -mcpu=cortex-a7 -Iinclude -g
QFLAGS = -M raspi2b -cpu cortex-a7 -m 1G
# Attach USB if requested
ifneq ("$(ATTACH_USB)","0")
QFLAGS += -device usb-kbd
QFLAGS += -trace events=events
endif
# Use Automation Pipe if requested
ifneq ("$(AUTO)","0")
QFLAGS += -chardev pipe,id=char0,mux=on,logfile=serial.log,path=guest -serial chardev:char0 -mon chardev=char0
else
QFLAGS += -chardev stdio,id=char0,mux=on,logfile=serial.log,signal=off -serial chardev:char0 -mon chardev=char0
endif
# Use Correct MMIO Address
ifeq ($(BSP),2)
BSP23 = 1
CFLAGS += -DBSP23
endif
# Pause and wait for GDB if requested
ifneq ($(DEBUG),0)
QFLAGS += -s -S
endif
# Don't use screen if requested
ifneq ("$(SILENT)","0")
QFLAGS += -nographic
endif
# Attach sd if exists
ifneq ("$(wildcard ./sd.hda)","")
QFLAGS += -drive file=sd.hda,if=sd,format=raw
endif
.PHONY: clean debug disk dump run test tree
default: clean build/kernel7.img
build/kernel7.img: build/kernel.elf
@mkdir -p $(@D)
${OBJCOPY} $< -O binary $@
build/kernel.list: build/kernel.elf
@mkdir -p $(@D)
${OBJDUMP} -D $< > $@
dump: build/kernel.list
build/kernel.elf: ${A_OBJECTD} ${C_OBJECTD}
@tput setaf 6 2> /dev/null || true; echo Linking Kernel; tput sgr0 2> /dev/null || true
@mkdir -p $(@D)
${CC} -T linker.ld -o $@ -ffreestanding -O3 -nostdlib $^
obj/%.co: src/%.c
@mkdir -p $(@D)
${CC} ${CFLAGS} -c $< -o $@
obj/%.ao: src/%.S
@mkdir -p $(@D)
${AS} ${AFLAGS} -c $< -o $@
run: build/kernel.elf
@tput setaf 6 2> /dev/null || true; echo Starting QEMU; tput sgr0 2> /dev/null || true
@${QEMU} -kernel $< ${QFLAGS}
debug: build/kernel.list
@tput setaf 6 2> /dev/null || true; echo Starting GDB; tput sgr0 2> /dev/null || true
@${GDB} $< -command=gdbinit
sd.hda:
@cp README.md sd.hda
@dd if=/dev/zero of=sd.hda count=1 bs=1 seek=16383
disk: sd.hda
clean:
@tput setaf 6 2> /dev/null || true; echo Clearing Build; tput sgr0 2> /dev/null || true
rm -rf obj/* build/*
tree:
@tree -a -I obj\|build\|.git\|.gitignore
test: clean build/kernel.elf
@tput setaf 6 2> /dev/null || true; echo Running Tests; tput sgr0 2> /dev/null || true
@./tests/run.sh
copy: clean build/kernel7.img
sudo mount -o umask=0 $(DISK) /mnt/sd0
sudo cp build/kernel7.img /mnt/sd0
sudo umount /mnt/sd0
|